GIT版本控制常规性操作演示汇总

文章目录

      • `GIT`基本操作
      • `GIT`配置个人信息配置:
      • `GIT`查看个人信息配置:
      • `GIT`的三大区域
      • `GIT`回滚:`git reset`
      • `GIT`恢复日志:`git reflog`
      • `GIT`三大区域转换
      • `GIT`新建分支
      • `GIT`合并分支
      • `GIT`删除分支
      • 码云上创建项目
      • `GIT`变基:`git rebase`合并提交记录
      • `GIT`变基:`git rebase`简化工作流
      • `GIT`变基:`git rebase`合并代码

GIT基本操作

GIT是一个分布式版本控制软件,官网地址https://git-scm.com/

版本控制操作步骤:1,进入要管理的文件夹;2,初始化;3,管理;4,生成版本;下面是本次操作的流程演示过程

#第一步:进入要管理的文件夹
dream21th@dream21th MINGW64 /d/home
$ cd git-study/#第二步: 执行git初始化
dream21th@dream21th MINGW64 /d/home/git-study
$ git init
Initialized empty Git repository in D:/home/git-study/.git/#第三步: 查询需要管理的文件状态,abc.txt,index.html两个文件都未被管理
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch masterNo commits yetUntracked files:(use "git add <file>..." to include in what will be committed)abc.txtindex.htmlnothing added to commit but untracked files present (use "git add" to track)#第四步: 通过add添加要管理的文件
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git add index.html
warning: in the working copy of 'index.html', LF will be replaced by CRLF the next time Git touches it#第五步: 查询需要管理的文件状态,发现只有abc.txt没有被管理,而index.html被git管理了
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch masterNo commits yetChanges to be committed:(use "git rm --cached <file>..." to unstage)new file:   index.htmlUntracked files:(use "git add <file>..." to include in what will be committed)abc.txt
#第六步: 通过git add .让所有没有被管理的文件被管理起来
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch masterNo commits yetChanges to be committed:(use "git rm --cached <file>..." to unstage)new file:   abc.txtnew file:   index.html
#第七步:通过git commit添加版本控制
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m "v1"
[master (root-commit) 986868c] v12 files changed, 2 insertions(+)create mode 100644 abc.txtcreate mode 100644 index.htmldream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
nothing to commit, working tree clean# 第八步:修改index.html文件
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ vim index.html# 第九步: 修改index.html
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ vim index.html# 第十步: 重新添加文件管理控制
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   index.htmlno changes added to commit (use "git add" and/or "git commit -a")dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git add .
warning: in the working copy of 'index.html', LF will be replaced by CRLF the next time Git touches itdream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)modified:   index.htmldream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m "v2"
[master 1c7b174] v21 file changed, 2 insertions(+)# 第十一步: 查询版本控制日志dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit 1c7b174b6574698d880bc18efe38a7457cb2bd77 (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1

文件在管控台的三种颜色:红色(新增或者修改的文件),绿色(git已经管理的版本)。

GIT配置个人信息配置:

dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git config --global user.name "dream21th"dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git config --global user.email "dream21th@126.com"

GIT查看个人信息配置:

dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git config --global user.namedream21th@dream21th MINGW64 /d/home/git-study (master)
$ git config --global user.email

GIT的三大区域

GIT的三大区域是工作区,暂存区,版本库,他们之间的关系如下:

在这里插入图片描述

GIT回滚:git reset

# 第一步:查看提交的版本号,确认要回退的版本号
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800v3commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1# 第二步: 假设这次要回退到v2版本,在git reset --hard后面跟上v2的版本号
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git reset --hard 1c7b174b6574698d880bc18efe38a7457cb2bd77
HEAD is now at 1c7b174 v2# 第三步: 回退后查看当前版本
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit 1c7b174b6574698d880bc18efe38a7457cb2bd77 (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1

GIT恢复日志:git reflog

​ 通过上面的例子版本已经回退到v2版本,假如这个时候,又想退回到原来的v3版本,可以通过下面的指令操作

# 第一步: 通过git reflog查询到v3的版本号
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git reflog
1c7b174 (HEAD -> master) HEAD@{1}: reset: moving to 1c7b174b6574698d880bc18efe38a7457cb2bd77
df3b201 HEAD@{2}: commit: v3
1c7b174 (HEAD -> master) HEAD@{3}: commit: v2
986868c HEAD@{4}: commit (initial): v1# 第二步: 通过git reset --hard加上版本号回退
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git reset --hard df3b201
HEAD is now at df3b201 v3# 第三步: 查看版本日志信息
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800v3commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1

GIT三大区域转换

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wdjPaLKS-1688630161959)(D:\developsoftware\mayun\note\study-note\image\image-20230705150825706.png)]

# 第一步: 编写一个abc.txt在里面写v1
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ vim abc.txt# 第二步: 查询状态
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   abc.txtno changes added to commit (use "git add" and/or "git commit -a")#第三步: 加入暂存区
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git add -A
warning: in the working copy of 'abc.txt', LF will be replaced by CRLF the next time Git touches it# 第四步:加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m "111"
[master ead1292] 1111 file changed, 1 insertion(+)# 第五步:编写文件,加入新内容v2
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ vim abc.txt# 第六步: 查看状态
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   abc.txtno changes added to commit (use "git add" and/or "git commit -a")# 第七步: 加入暂存区
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git add .
warning: in the working copy of 'abc.txt', LF will be replaced by CRLF the next time Git touches it# 第八步:加入版本库
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m 'v2'
[master 5bf7911] v21 file changed, 1 insertion(+)# 第九步:查看文件内容
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ cat abc.txt
v1
v2# 第十步:查看版本日志
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit 5bf7911b941700fa5e1f2f60f87e6a4dbfa5f892 (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:39 2023 +0800v2commit ead12928cf17629e451f4697505c681ad8d2cd76
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800111# 第十一步:回到第一次提交的暂存区
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git reset --soft ead12928cf17629e451f4697505c681ad8d2cd76# 第十二步:查看版本状态
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes to be committed:(use "git restore --staged <file>..." to unstage)modified:   abc.txtdream21th@dream21th MINGW64 /d/home/git-study (master)
$ cat abc.txt
v1
v2# 第十三步:回退到工作区修改内容(未暂存)
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git reset HEAD abc.txt
Unstaged changes after reset:
M       abc.txtdream21th@dream21th MINGW64 /d/home/git-study (master)
$ git status
On branch master
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   abc.txtno changes added to commit (use "git add" and/or "git commit -a")# 第十四步:回退到工作区修改前内容
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git checkout -- abc.txt# 第十五步:查看wen'jian
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ cat abc.txt
v1

GIT新建分支

# 第一步: 查看当前有的分支
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git branch -a
* master# 第二步: 基于master新建dev分支
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git branch dev# 第三步: 切换到dev分支
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git checkout dev
Switched to branch 'dev'dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git status
On branch dev
nothing to commit, working tree clean# 第四步: 修改abc.txt文件
dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ vim abc.txtdream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git status
On branch dev
Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified:   abc.txtno changes added to commit (use "git add" and/or "git commit -a")# 第五步: 加入暂存区
dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git add .# 第六步: 加入版本库
dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git commit -m "v3"
[dev 4e55aa6] v31 file changed, 1 insertion(+)dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git status
On branch dev
nothing to commit, working tree cleandream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git log
commit 4e55aa657fd871b787cb384bc7086813dc87ac55 (HEAD -> dev)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 17:10:03 2023 +0800v3commit ead12928cf17629e451f4697505c681ad8d2cd76 (master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800111commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800v3commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1

​ 除了上面采用git branch的方式创建分支,还可以采用git checkout -b 分支名创建一个分支并切换到新建的分支。

dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git checkout -b bug_fix
Switched to a new branch 'bug_fix'dream21th@dream21th MINGW64 /d/home/git-study (bug_fix)

GIT合并分支

# 第一步: 切换到要合并的分支
dream21th@dream21th MINGW64 /d/home/git-study (bug_fix)
$ git checkout master
Switched to branch 'master'# 第二步: 将dev分支合并到master
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git merge dev
Updating ead1292..4e55aa6
Fast-forwardabc.txt | 1 +1 file changed, 1 insertion(+)# 第三步:查看合并后的内容
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ cat abc.txt
v1
v3dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git log
commit 4e55aa657fd871b787cb384bc7086813dc87ac55 (HEAD -> master, dev, bug_fix)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 17:10:03 2023 +0800v3commit ead12928cf17629e451f4697505c681ad8d2cd76
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800111commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800v3commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800v2commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800v1

GIT删除分支

# 删除分支bug_fix
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git branch -d bug_fix
Deleted branch bug_fix (was 4e55aa6).dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git branch -adev
* master

码云上创建项目

​ 码云的官网地址:https://gitee.com/,登录成功后进行下面操作:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d3aQnCXr-1688630161959)(D:\developsoftware\mayun\note\study-note\image\image-20230706095029880.png)]

​ 点击创建之后,会出现下面界面,可以采用下面的方法将本地代码上传到远程。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KKPsYCfP-1688630161959)(D:\developsoftware\mayun\note\study-note\image\image-20230706095205520.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TprLMrwG-1688630161960)(D:\developsoftware\mayun\note\study-note\image\image-20230706102259473.png)]

GIT变基:git rebase合并提交记录

# 第一步: 新建一个目录
dream21th@dream21th MINGW64 /d/home
$ mkdir git-study-onedream21th@dream21th MINGW64 /d/home
$ cd git-study-one/# 第二步:添加版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one
$ git init
Initialized empty Git repository in D:/home/git-study-one/.git/# 第三步:创建文件并加入版本库,标记为v1.1
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch a.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "v1.1"
[master (root-commit) 09c30f6] v1.11 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 a.txt# 第四步:创建文件并加入版本库,标记为v1.2
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch b.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "v1.2"
[master efcf537] v1.21 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 b.txt# 第五步:创建文件并加入版本库,标记为v1.3
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch c.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "v1.3"
[master 159bd65] v1.31 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 c.txt# 第六步:创建文件并加入版本库,标记为v1.4
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch d.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "v1.4"
[master 822f1d7] v1.41 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 d.txt# 第七步:查看版本日志,发现有四条提交记录
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log
commit 822f1d743052055521f45e0712996c35a3b0232d (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:01:29 2023 +0800v1.4commit 159bd65f730db0ab317fe784a554a1660f6e391f
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:01:09 2023 +0800v1.3commit efcf53797b6a41ed20f59fa7e1bf2d1ff28e0d84
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:54 2023 +0800v1.2commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800v1.1# 第八步: 合并后三次提交记录(通过git rebase -i HEAD~3 数字代表合并的后面条数,也可以通过版本号合并)
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git rebase -i HEAD~3
[detached HEAD 85ea9ba] 合并v1.2 到 v1.4Date: Thu Jul 6 11:00:54 2023 +08003 files changed, 0 insertions(+), 0 deletions(-)create mode 100644 b.txtcreate mode 100644 c.txtcreate mode 100644 d.txt
Successfully rebased and updated refs/heads/master.# 第九步: 查看合并后的提交记录,发现只剩两条
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log
commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5 (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:54 2023 +0800合并v1.2 到 v1.4commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800v1.1dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ ls
a.txt  b.txt  c.txt  d.txt

注意:尽量不要把已经推到远程的版本合并。

GIT变基:git rebase简化工作流

dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git branch
* master# 第一步: 新建一个分支dev,并切换到dev分支
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git checkout -b dev
Switched to a new branch 'dev'# 第二步: 创建一个文件并加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ touch f.txtdream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git commit -m "f.txt"
[dev bea1b84] f.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 f.txt# 第三步: 切换到master分支
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git checkout master
Switched to branch 'master'# 第四步: 创建一个文件并加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch g.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m 'g.txt'
[master d600c5c] g.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 g.txt# 查看版本控制记录
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log
commit d600c5cfb4d34f8b1dc44a9555d02369df6122b2 (HEAD -> master)
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 13:31:04 2023 +0800g.txtcommit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:54 2023 +0800合并v1.2 到 v1.4commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800v1.1# 图形化的方式查看版本日志
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log --graph
* commit d600c5cfb4d34f8b1dc44a9555d02369df6122b2 (HEAD -> master)
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 13:31:04 2023 +0800
|
|     g.txt
|
* commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 11:00:54 2023 +0800
|
|     合并v1.2 到 v1.4
|
* commit 09c30f6113714c59fbf4665de5bd9317aa1d8215Author: dream21th <dream21th@126.com>Date:   Thu Jul 6 11:00:30 2023 +0800v1.1# 第五步: 在master分支合并dev分支
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git merge dev
Merge made by the 'ort' strategy.f.txt | 01 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 f.txt# 图形化的方式查看版本日志,看到后面有两条分叉线
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log --graph
*   commit e53ba9a679b8c292f7ee0d54dd9d56d02eb630e9 (HEAD -> master)
|\  Merge: d600c5c bea1b84
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:31:29 2023 +0800
| |
| |     Merge branch 'dev'
| |
| * commit bea1b84e2ea85bb4d2fdb32ae9764104510a9e38 (dev)
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:30:36 2023 +0800
| |
| |     f.txt
| |
* | commit d600c5cfb4d34f8b1dc44a9555d02369df6122b2
|/  Author: dream21th <dream21th@126.com>
|   Date:   Thu Jul 6 13:31:04 2023 +0800
|
|       g.txt
|
* commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 11:00:54 2023 +0800
|
|     合并v1.2 到 v1.4
|
* commit 09c30f6113714c59fbf4665de5bd9317aa1d8215Author: dream21th <dream21th@126.com>Date:   Thu Jul 6 11:00:30 2023 +0800v1.1
# 回到dev分支合并master的代码,后面展示通过git rebase的方式减少交叉线
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git checkout dev
Switched to branch 'dev'dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git merge mster
merge: mster - not something we can mergedream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git merge master
Updating bea1b84..e53ba9a
Fast-forwardg.txt | 01 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 g.txtdream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git log --graph
*   commit e53ba9a679b8c292f7ee0d54dd9d56d02eb630e9 (HEAD -> dev, master)
|\  Merge: d600c5c bea1b84
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:31:29 2023 +0800
| |
| |     Merge branch 'dev'
| |
| * commit bea1b84e2ea85bb4d2fdb32ae9764104510a9e38
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:30:36 2023 +0800
| |
| |     f.txt
| |
* | commit d600c5cfb4d34f8b1dc44a9555d02369df6122b2
|/  Author: dream21th <dream21th@126.com>
|   Date:   Thu Jul 6 13:31:04 2023 +0800
|
|       g.txt
|
* commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 11:00:54 2023 +0800
|
|     合并v1.2 到 v1.4
|
* commit 09c30f6113714c59fbf4665de5bd9317aa1d8215Author: dream21th <dream21th@126.com>Date:   Thu Jul 6 11:00:30 2023 +0800v1.1
===============================================================
#下面演示通过git rebase的方式合并分叉
# 第一步: 创建h.txt文件并加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ touch h.txtdream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git commit -m "h.txt"
[dev 6167254] h.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 h.txt# 第二步:切换到master分支创建i.txt文件并加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git checkout master
Switched to branch 'master'dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch i.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "i.txt"
[master 92d1b47] i.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 i.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git checkout dev
Switched to branch 'dev'# 第三步:切换到dev分支,rebase分支master
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git rebase master
Successfully rebased and updated refs/heads/dev.dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git status
On branch dev
nothing to commit, working tree clean# 第四步: 切换回master分支,merge分支dev
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git checkout master
Switched to branch 'master'dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git merge dev
Updating 92d1b47..398a705
Fast-forwardh.txt | 01 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 h.txt# 第五步:通过git rebase查看发现后面只有一条线
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log --graph
* commit 398a705fdfe4d7e23934505268a736f3247ced87 (HEAD -> master, dev)
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 13:32:46 2023 +0800
|
|     h.txt
|
* commit 92d1b474c1f6df90c8495a9430895beefb2f1bcd
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 13:33:17 2023 +0800
|
|     i.txt
|
*   commit e53ba9a679b8c292f7ee0d54dd9d56d02eb630e9
|\  Merge: d600c5c bea1b84
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:31:29 2023 +0800
| |
| |     Merge branch 'dev'
| |
| * commit bea1b84e2ea85bb4d2fdb32ae9764104510a9e38
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:30:36 2023 +0800
| |
| |     f.txt
| |
* | commit d600c5cfb4d34f8b1dc44a9555d02369df6122b2
|/  Author: dream21th <dream21th@126.com>
|   Date:   Thu Jul 6 13:31:04 2023 +0800
|
|       g.txt
|
* commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 11:00:54 2023 +0800
|
|     合并v1.2 到 v1.4
|
* commit 09c30f6113714c59fbf4665de5bd9317aa1d8215Author: dream21th <dream21th@126.com>Date:   Thu Jul 6 11:00:30 2023 +0800v1.1
# 简化日志图形化输出
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git log --graph --pretty=format:"%h %s"
* 398a705 h.txt
* 92d1b47 i.txt
*   e53ba9a Merge branch 'dev'
|\
| * bea1b84 f.txt
* | d600c5c g.txt
|/
* 85ea9ba 合并v1.2 到 v1.4
* 09c30f6 v1.1

GIT变基:git rebase合并代码

# 模拟在本地环境一提交代码到远程
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch y.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "y.txt"
[master e9d6ee5] y.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 y.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 222 bytes | 222.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/dream21th/git_study.git398a705..e9d6ee5  master -> master

​ 在本地环境二先做修改代码,然后提交版本库,在更新远程代码,更新完成后看到本地代码有分叉。

dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ touch x.txtdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git commit -m 'x.txt'
[master e1b0e87] x.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 x.txtdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git pull
Already up to date.dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git pull
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 202 bytes | 25.00 KiB/s, done.
From https://gitee.com/dream21th/git_study398a705..e9d6ee5  master     -> origin/master
Merge made by the 'ort' strategy.y.txt | 01 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 y.txtdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git log --graph
*   commit d9aba5c612a8a7dd5e23c61f7785f29588bcdb3d (HEAD -> master)
|\  Merge: e1b0e87 e9d6ee5
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:58:34 2023 +0800
| |
| |     Merge branch 'master' of https://gitee.com/dream21th/git_study
| |
| * commit e9d6ee5159adc051450d36c20a6e61f0be3cb950 (origin/master, origin/HEAD)
| | Author: dream21th <dream21th@126.com>
| | Date:   Thu Jul 6 13:58:10 2023 +0800
| |
| |     y.txt
| |
* | commit e1b0e871154e50f874d249213446288c292bc86e
|/  Author: dream21th <dream21th@126.com>
|   Date:   Thu Jul 6 13:57:38 2023 +0800
|
|       x.txt

​ 通过git fetchgit rebase的操作方式减少分叉:

dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch xx.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git commit -m "xx.txt"
[master 676791f] xx.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 xx.txtdream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 224 bytes | 224.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/dream21th/git_study.gitd9aba5c..676791f  master -> master
dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ touch xy.txtdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git add .dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ gt commit -m "xy.txt"
bash: gt: command not founddream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git commit -m "xy.txt"
[master a6bbb8a] xy.txt1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 xy.txtdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git fetch
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (2/2), 204 bytes | 68.00 KiB/s, done.
From https://gitee.com/dream21th/git_studyd9aba5c..676791f  master     -> origin/masterdream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git rebase origin/master
Successfully rebased and updated refs/heads/master.dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git log --graph
* commit 3fbfdf8919825508c96fbba54bf8536856f50fc9 (HEAD -> master)
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 14:04:33 2023 +0800
|
|     xy.txt
|
* commit 676791fd5eb1639b3d333907110d65b3018cc60b (origin/master, origin/HEAD)
| Author: dream21th <dream21th@126.com>
| Date:   Thu Jul 6 14:04:01 2023 +0800
|
|     xx.txt
|

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/14896.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

随机产生50个100以内的不重复的整数,设计位图排序算法进行排序。

1.问题 随机产生50个100以内的不重复的整数&#xff0c;设计位图排序算法进行排序。 2.设计思路 阶段1&#xff1a; 初始化一个空集合    for i[0,n)    bit[i]0 阶段2&#xff1a; 读入数据i&#xff0c;并设置bit[i]1    for each i in the input file    bit[i]1…

3.6.共享内存的学习

目录 前言1. 共享内存2. shared memory案例3. 补充知识总结 前言 杜老师推出的 tensorRT从零起步高性能部署 课程&#xff0c;之前有看过一遍&#xff0c;但是没有做笔记&#xff0c;很多东西也忘了。这次重新撸一遍&#xff0c;顺便记记笔记。 本次课程学习精简 CUDA 教程-共享…

基于C++、GDAL、OpenCV的矢量数据骨架线提取算法

基于C、GDAL、OpenCV的矢量数据骨架线提取算法 CGAL已经实现了该功能&#xff0c;但由于CGAL依赖于Boost库&#xff0c;编译后过大&#xff0c;因此本文所采用的这套方式实现骨架线提取功能。 效果&#xff1a; 思路&#xff1a; 1、将导入shp按照要素逐一拆分成新的shp 2、…

类Twitter风格的RSS阅读器

本文完成于 2 月中旬&#xff0c;其中的反代还是 frp npm 方案&#xff1b; 什么是 RSS ? RSS 是用 PHP、Laravel、Inertia.js、Tailwind 和 Vue.js 编写的简单的类Twitter 风格的 RSS阅读器&#xff0c;支持 RSS和ATOM 格式。 命令行安装 在群晖上以 Docker 方式安装。 官…

Nacos2.3.0源码启动报错找不到符号com.alibaba.nacos.consistency.entity

一. 源码下载编译&#xff1a;找不到符号com.alibaba.nacos.consistency.entity 如果报错找不到符号com.alibaba.nacos.consistency.entity Nacos\consistency\src\main\java\com\alibaba\nacos\consistency\entity 这个包下没有相关的java文件&#xff0c;其实是我们没有编译…

hadoop --- MapReduce

MapReduce定义&#xff1a; MapReduce可以分解为Map (映射) Reduce (规约) &#xff0c; 具体过程&#xff1a; Map : 输入数据集被切分成多个小块&#xff0c;并分配给不同的计算节点进行处理Shuffle and Sort&#xff1a;洗牌和排序&#xff0c;在 Map 阶段结束后&#xf…

15.1 BP神经网络实现图像压缩——了解神经网络在图像处理方面的应用(matlab程序)

1.简述 BP神经网络现在来说是一种比较成熟的网络模型了,因为神经网络对于数字图像处理的先天优势,特别是在图像压缩方面更具有先天的优势,因此,我这一段时间在研究神经网络的时候同时研究了一下关于BP网络实现图像压缩的原理和过程,并且是在MATLAB上进行了仿真的实验,结果发现设…

TinyStories: How Small Can Language Models Be and Still Speak Coherent English?

本文是LLM系列的文章之一&#xff0c;针对《TinyStories: How Small Can Language Models Be and Still Speak Coherent English?》的翻译。 TinyStories&#xff1a;语言模型能有多小&#xff0c;还能说连贯的英语&#xff1f; 摘要1 引言2 TinyStories数据集的描述2.1 Tiny…

3D模型轻量化开发工具HOOPS与WebGL的对比分析

HOOPS是一种商业级的3D开发平台&#xff0c;由Tech Soft 3D公司开发。它提供了一套全面的工具和API&#xff0c;用于构建和展示高度复杂的3D场景和模型&#xff0c;可以在多个平台和环境中使用&#xff0c;包括Web、移动设备和桌面&#xff0c;这使得开发者能够在不同的设备上展…

UE5接入在线直播视频源,如hls(m3u8)格式

文章目录 1.实现目标2.实现过程2.1 VlcMedia插件重编译2.2 UE5接入在线直播2.3 创建材质3.参考资料1.实现目标 通过重编译VlcMedia插件,以支持在线直播视频在UE5中的播放,GIF动图如下: 2.实现过程 本文主要包括插件的重编译、在线直播视频的接入,以及材质的创建三个部分。…

ELK部署安装

目录 一、环境准备 1.准备三台服务器&#xff08;带图形化的linuxCentOS7&#xff0c;最小化缺少很多环境&#xff09; 2.修改主机名 3.关闭防火墙 4.elk-node1、elk-node2 用系统自带的java 5.上传软件包到node1和node2 二、部署elasticsearch 1、node1、node2操作 2.no…

Coggle 30 Days of ML(23年7月)任务四:线性模型训练与预测

Coggle 30 Days of ML&#xff08;23年7月&#xff09;任务四&#xff1a;线性模型训练与预测 任务四&#xff1a;使用TFIDF特征和线性模型完成训练和预测 说明&#xff1a;在这个任务中&#xff0c;你需要使用TFIDF特征和线性模型&#xff08;如逻辑回归&#xff09;完成训练…