• git 记录


    git 工作区介绍

    在这里插入图片描述

    • workspace:工作区,就是平时存放项目代码的地方。
    • Index/Stage:暂存区,用于临时存放你的改动,事实上只是一个文件,保存即将提交到文件列表信息。
    • Repository:仓库区(或版本库),就是安全存放数据的位置,这里面有你提交到所有版本的数据。其中HEAD指向最新放入仓库的版本。
    • Remote:远程仓库,托管代码的服务器,可以简单的认为是你项目组中一台电脑用于远程数据交换。

    https://blog.csdn.net/xyzso1z/article/details/119009639

    基础命令

    git config

    git config --global = 设置配置项

    $ git config --global user.name=xxx
    
    $ git config --global user.email=xxx@163.com
    
    $ git config --list
    diff.astextplain.textconv=astextplain
    filter.lfs.clean=git-lfs clean -- %f
    ...
    
    $ git config --global --list
    user.name=xxx
    user.email=xxx@163.com
    core.autocrlf=true
    http.sslverify=false
    
    ### ~/.gitconfig ###
    
    $ cat ~/.gitconfig
    [user]
            name = xxx
            email = xxx@163.com
    [core]
            autocrlf = true
    [http]
            sslVerify = false
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    git config --global --unset <配置名> 删除配置项

    git config --global --unset user.name
    git config --global --unset user.email
    
    • 1
    • 2
    git init 初始化
    git status
    $ git status
    On branch master
    Changes to be committed:
      (use "git restore --staged ..." to unstage)
            deleted:    .gitignore
            new file:   gateway/src/main/java/com/nufront/bigdata/collect/MysqlFlinkSQLcdc2Kafka.java
            modified:   pom.xml
            new file:   v2x/pom.xml
            ...
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    git add 添加至暂存区
    ### 将当前文件夹下文件提交至暂存区
    git add .
    
    • 1
    • 2
    git rm 删除暂存区文件

    git rm --cached <文件路径> 只删除暂存区文件
    git rm --f <文件路径> 删除暂存区文件及物理文件

    $ git rm --cached xxxx.java
    rm 'xxx.java'
    
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    在这里插入图片描述

    清空暂存区

    在这里插入图片描述

    git commit
    git commit -m '数据分流'
    
    • 1

    在这里插入图片描述

    git remote 远程库
    git remote -v 所有远程库
    $ git remote -v
    origin  git@github.com:Olave/nufront-data-center.git (fetch)
    origin  git@github.com:Olave/nufront-data-center.git (push)
    
    • 1
    • 2
    • 3
    git remote show <远程别名>

    在这里插入图片描述

    添加远程库 git remote add <别名>
    git remote add origin git@github.com:tianqixin/xxx.git
    
    • 1
    删除远程库 git remote rm <别名>
    删除远程库 git remote rename <旧别名> <新别名>
    git push

    在这里插入图片描述

    在这里插入图片描述

    fatal: The current branch master has no upstream branch.
    分支

    在这里插入图片描述

    查看当前分支
    $ git branch
    * master
    
    
    • 1
    • 2
    • 3
    创建分支

    git branch

    git branch <分支名>
    
    • 1

    git从master建立分支

    • git branch -r 查看远程分支
    • git branch -a 查看所有分支
    $ git branch -r
      origin/master
    
    $ git branch -a
    * 20221112
      master
      remotes/origin/master
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    git branch --set-upstream-to 本地关联远程分支

    git branch --set-upstream-to=<远程别名>/<远程分支>  <本地分支>
    
    • 1

    https://www.cnblogs.com/chenjo/p/14072152.html

    使用git在本地新建一个分支后,需要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。关联目的是在执行 git pull, git push 操作时就不需要指定对应的远程分支,你只要没有显示指定,git pull的时候,就会提示你。

    在这里插入图片描述

    在这里插入图片描述

    • git branch -D <本地分支名> 删除本地分支
    • git branch -d -r <远程分支名> 删除远程分支,本地对应分支还存在
    • git push origin <本地分支>:<远程分支> 创建远程分支
    • git push origin :<远程分支名> 删除远程分支
    • git push origin --delete <远程分支名> 删除远程分支

    在这里插入图片描述

    切换分支

    git checkout

    git checkout <分支名>
    
    • 1

    git checkout -b <分支名> 创建新分支dev,并把当前master分支内容复制一份到新分支dev中

    合并分支

    git merge <目标分支> 将目标分支合并到当前分支下

    • 将 master 合并到当前分支
    git checkout xxx
    
    ### 在 xxx 分支下
    git merge master
    
    • 1
    • 2
    • 3
    • 4

    在这里插入图片描述

    • 合并冲突

    说明:只有已经 commit 的文件才会发生冲突,否则则是报:Your local changes to the following files would be overwritten by checkout:
    在这里插入图片描述

    git tag

    git clone 切换源码分支版本

    git checkout <tag_name>
    git checkout release-10.0-rc3
    
    • 1
    • 2
    • detached HEAD 状态
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded ((release-10.0))
    $ git branch
    * (HEAD detached at release-10.0-rc3)
      master
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded ((release-10.0))
    $ git checkout -b release-10.0-rc3
    Switched to a new branch 'release-10.0-rc3'
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (release-10.0-rc3)
    $ git branch
      master
    * release-10.0-rc3
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    https://blog.csdn.net/CSDN_KONGlX/article/details/125484338

    • git tag是一系列commit的中的一个点,只能查看,不能移动。branch是一系列串联的commit的线。

    • tag是静态的,branch是动态的,要向前走。

    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ git branch -r
      origin/HEAD -> origin/master
      origin/dependabot/maven/flink-shaded-swagger/org.yaml-snakeyaml-1.32
      origin/master
      origin/release-1.0
      origin/release-10.0
      ...
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ git branch -a
    * master
      remotes/origin/HEAD -> origin/master
      ...
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ git reflog -v
    3082afc (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: clone: from git@github.com:apache/flink-shaded.git
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ git tag
    1.0
    2.0
    3.0
    3.0-rc1
    3.0-rc2
    4.0
    4.0-rc1
    4.0-rc2
    5.0
    5.0-rc1
    release-10.0
    release-10.0-rc1
    release-10.0-rc2
    release-10.0-rc3
    release-11.0
    release-11.0-rc1
    release-12.0
    release-12.0-rc1
    release-13.0
    release-13.0-rc1
    release-14.0
    release-14.0-rc1
    release-15.0
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ git checkout release-10.0-rc3
    Note: switching to 'release-10.0-rc3'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by switching back to a branch.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -c with the switch command. Example:
    
      git switch -c <new-branch-name>
    
    Or undo this operation with:
    
      git switch -
    
    Turn off this advice by setting config variable advice.detachedHead to false
    
    HEAD is now at 2a20826 [hotfix][legal] Fix zookeeper patch version
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded ((release-10.0))
    $ ls -l
    total 49
    -rw-r--r-- 1 Administrator 197121  1388 十一月 16 22:00 deploysettings.xml
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-asm-7/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-force-shading/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-guava-18/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-hadoop-2-parent/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-jackson-parent/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-netty-4/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-netty-tcnative-dynamic/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-netty-tcnative-static/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 flink-shaded-zookeeper-parent/
    -rw-r--r-- 1 Administrator 197121 11558 十一月 16 22:00 LICENSE
    -rw-r--r-- 1 Administrator 197121   171 十一月 16 22:11 NOTICE
    -rw-r--r-- 1 Administrator 197121 12468 十一月 16 22:11 pom.xml
    -rw-r--r-- 1 Administrator 197121  1805 十一月 16 22:11 README.md
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:11 tools/
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded ((release-10.0))
    $ git checkout master
    Previous HEAD position was 2a20826 [hotfix][legal] Fix zookeeper patch version
    Switched to branch 'master'
    Your branch is up to date with 'origin/master'.
    
    Administrator@Lancelot MINGW64 ~/Desktop/大数据开发/源码/flink-shaded (master)
    $ ls -l
    total 45
    -rw-r--r-- 1 Administrator 197121  1388 十一月 16 22:00 deploysettings.xml
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-asm-9/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-force-shading/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-guava-30/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-jackson-parent/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-netty-4/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-netty-tcnative-dynamic/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-netty-tcnative-static/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-swagger/
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 flink-shaded-zookeeper-parent/
    -rw-r--r-- 1 Administrator 197121 11558 十一月 16 22:00 LICENSE
    -rw-r--r-- 1 Administrator 197121   171 十一月 16 22:20 NOTICE
    -rw-r--r-- 1 Administrator 197121 16360 十一月 16 22:20 pom.xml
    -rw-r--r-- 1 Administrator 197121  1758 十一月 16 22:20 README.md
    drwxr-xr-x 1 Administrator 197121     0 十一月 16 22:20 tools/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    查看提交记录

    git log

    $ git log
    
    commit 3c896ed7a299c59d3d3426f0cb04e4440a66e541 (HEAD -> master, origin/master)
    Author: chenkang <chenkang020@foxmail.com>
    Date:   Sat Nov 12 08:16:00 2022 +0800
    
        数据分流
    
    commit cbe0700b253b8fcfffa20a7925a6a859e7d09e20
    Author: kang.chen <kang.chen@nufront.com>
    Date:   Wed Mar 23 18:59:27 2022 +0800
    
        CDH 版本分流
    
    commit ce3c9704985312e476467292f3b79fda70229b8b
    Author: kang.chen <kang.chen@nufront.com>
    Date:   Wed Mar 23 18:59:02 2022 +0800
    
        CDH 版本分流
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    查看commit 提交哪些内容

    在这里插入图片描述

    git clean

    git clean 会清除未被 tracked 的文件——未被添加进暂存区、未被commit 的文件

    git reset

    git reset命令用于回退版本,可以指定退回某一次提交的版本

    https://m.runoob.com/git/git-reset.html

    —>>https://zhuanlan.zhihu.com/p/346993796

    拉取远程至本地

    git pull = git fetch + git merge

    问题记录

    https://zhuanlan.zhihu.com/p/478264832

    ERROR: [ebdb695] missing Change-Id in commit message footer

    在这里插入图片描述

    gitdir=$(git rev-parse --git-dir); scp -p -P 29418 xxx ${gitdir}/hooks/
    
    git commit --amend
    
    git push origin master:refs/for/master
    
    • 1
    • 2
    • 3
    • 4
    • 5

    在这里插入图片描述

  • 相关阅读:
    in(...) 可能会让你排查Bug到崩溃,哈哈哈
    R语言使用mlr包创建随机森林分类模型、网格搜索、交叉验证获取随机森林的最佳超参数组合(random forest classification)
    Cookie跨域以及Cookie共享问题
    VUE全家桶 (Vue-cli、Vue-route、Vuex)学习笔记
    Java阻塞队列中的异类,SynchronousQueue底层实现原理剖析
    ruoyi前后端分离3.8.6版本,把用户昵称设置到Vuex中,使任何组件都能直接获取用户的昵称
    HTTP请求、响应详解
    Linux系统firewalld防火墙的进阶操作(日志保存 IP网段 ssh服务)
    第4讲:vue内置命令(文本插值,属性绑定,v-text,v-html)
    推荐系统实践读书笔记-07推荐系统实例
  • 原文地址:https://blog.csdn.net/qq_15138049/article/details/127815838