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 master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        abc.txt
        index.html

nothing 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 master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   index.html

Untracked 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 master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   abc.txt
        new file:   index.html
#第七步:通过git commit添加版本控制
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m "v1"
[master (root-commit) 986868c] v1
 2 files changed, 2 insertions(+)
 create mode 100644 abc.txt
 create mode 100644 index.html

dream21th@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.html

no 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 it

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:   index.html

dream21th@dream21th MINGW64 /d/home/git-study (master)
$ git commit -m "v2"
[master 1c7b174] v2
 1 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 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1

文件在管控台的三种颜色:红色(新增或者修改的文件),绿色(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.name

dream21th@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 +0800

    v3

commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1

# 第二步: 假设这次要回退到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 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1

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 +0800

    v3

commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1

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.txt

no 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] 111
 1 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.txt

no 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] v2
 1 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 +0800

    v2

commit ead12928cf17629e451f4697505c681ad8d2cd76
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800

    111

# 第十一步:回到第一次提交的暂存区
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.txt

dream21th@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.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.txt

no 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.txt

dream21th@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.txt

no 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] v3
 1 file changed, 1 insertion(+)

dream21th@dream21th MINGW64 /d/home/git-study (dev)
$ git status
On branch dev
nothing to commit, working tree clean

dream21th@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 +0800

    v3

commit ead12928cf17629e451f4697505c681ad8d2cd76 (master)
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800

    111

commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800

    v3

commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1

​ 除了上面采用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-forward
 abc.txt | 1 +
 1 file changed, 1 insertion(+)

# 第三步:查看合并后的内容
dream21th@dream21th MINGW64 /d/home/git-study (master)
$ cat abc.txt
v1
v3

dream21th@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 +0800

    v3

commit ead12928cf17629e451f4697505c681ad8d2cd76
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 15:12:08 2023 +0800

    111

commit df3b201b621dfc7b3b256a8d5a51cd229bb4f1fe
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 13:57:13 2023 +0800

    v3

commit 1c7b174b6574698d880bc18efe38a7457cb2bd77
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 12:01:51 2023 +0800

    v2

commit 986868cdd81c46867a700d63b79f494c3a97065e
Author: dream21th <dream21th@126.com>
Date:   Wed Jul 5 11:59:30 2023 +0800

    v1


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 -a
  dev
* 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-one

dream21th@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.txt

dream21th@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.1
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt
 
# 第四步:创建文件并加入版本库,标记为v1.2
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch b.txt

dream21th@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.2
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 b.txt

# 第五步:创建文件并加入版本库,标记为v1.3
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch c.txt

dream21th@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.3
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 c.txt

# 第六步:创建文件并加入版本库,标记为v1.4
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ touch d.txt

dream21th@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.4
 1 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 +0800

    v1.4

commit 159bd65f730db0ab317fe784a554a1660f6e391f
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:01:09 2023 +0800

    v1.3

commit efcf53797b6a41ed20f59fa7e1bf2d1ff28e0d84
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:54 2023 +0800

    v1.2

commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800

    v1.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.4
 Date: Thu Jul 6 11:00:54 2023 +0800
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 b.txt
 create mode 100644 c.txt
 create 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.4

commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800

    v1.1

dream21th@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.txt

dream21th@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.txt
 1 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.txt

dream21th@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.txt
 1 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 +0800

    g.txt

commit 85ea9ba0e5d4389f007c6be99a339cd6c124c8d5
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:54 2023 +0800

    合并v1.2 到 v1.4

commit 09c30f6113714c59fbf4665de5bd9317aa1d8215
Author: dream21th <dream21th@126.com>
Date:   Thu Jul 6 11:00:30 2023 +0800

    v1.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 09c30f6113714c59fbf4665de5bd9317aa1d8215
  Author: dream21th <dream21th@126.com>
  Date:   Thu Jul 6 11:00:30 2023 +0800

      v1.1

# 第五步: 在master分支合并dev分支
dream21th@dream21th MINGW64 /d/home/git-study-one (master)
$ git merge dev
Merge made by the 'ort' strategy.
 f.txt | 0
 1 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 09c30f6113714c59fbf4665de5bd9317aa1d8215
  Author: dream21th <dream21th@126.com>
  Date:   Thu Jul 6 11:00:30 2023 +0800

      v1.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 merge

dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ git merge master
Updating bea1b84..e53ba9a
Fast-forward
 g.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 g.txt

dream21th@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 09c30f6113714c59fbf4665de5bd9317aa1d8215
  Author: dream21th <dream21th@126.com>
  Date:   Thu Jul 6 11:00:30 2023 +0800

      v1.1
===============================================================
#下面演示通过git rebase的方式合并分叉
# 第一步: 创建h.txt文件并加入版本控制
dream21th@dream21th MINGW64 /d/home/git-study-one (dev)
$ touch h.txt

dream21th@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.txt
 1 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.txt


dream21th@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.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 i.txt

dream21th@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-forward
 h.txt | 0
 1 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 09c30f6113714c59fbf4665de5bd9317aa1d8215
  Author: dream21th <dream21th@126.com>
  Date:   Thu Jul 6 11:00:30 2023 +0800

      v1.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.txt

dream21th@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.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 y.txt

dream21th@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.git
   398a705..e9d6ee5  master -> master

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

dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ touch x.txt

dream21th@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.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 x.txt

dream21th@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_study
   398a705..e9d6ee5  master     -> origin/master
Merge made by the 'ort' strategy.
 y.txt | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 y.txt

dream21th@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.txt

dream21th@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.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 xx.txt

dream21th@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.git
   d9aba5c..676791f  master -> master

dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ touch xy.txt

dream21th@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 found

dream21th@dream21th MINGW64 /d/home/git-study-two/git_study (master)
$ git commit -m "xy.txt"
[master a6bbb8a] xy.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 xy.txt

dream21th@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_study
   d9aba5c..676791f  master     -> origin/master

dream21th@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
|

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

设计模式- 一、设计原则-1

一、设计原则 当涉及到软件设计和开发原则时&#xff0c;有一些常见的原则和准则可以帮助我们编写高质量、可维护和可扩展的代码。以下是其中一些重要的原则和准则&#xff1a; SOLID原则&#xff1a; 单一职责原则&#xff08;Single Responsibility Principle&#xff0c;SRP…

举例说明ChatGPT模型是怎么进行无监督学习的

ChatGPT&#xff0c;也称为生成式预训练Transformer&#xff08;GPT&#xff09;&#xff0c;是一种基于Transformer架构的自然语言处理模型。虽然在实际应用中&#xff0c;它主要用于有监督学习任务&#xff0c;但在训练初期&#xff0c;它会经历无监督学习阶段。以下是一个简…

【简单认识LVS及LVS-NAT负载均衡群集的搭建】

文章目录 一、LVS群集简介1、群集的含义2、性能扩展方式3、群集的分类4、负载均衡群集架构1、负载均衡的结构 5、三种负载调度工作模式1、NAT模式2、TUN模式3、DR模式 二、LVS虚拟服务器1、Linux Virtual Server简介2、启用LVS虚拟服务3、LVS调度算法&#xff08;1&#xff09;…

Atcoder Beginner Contest 309——D-F讲解

前言 由于最近期末考试&#xff0c;所以之前几场都没打&#xff0c;给大家带了不便&#xff0c;非常抱歉。 这个暑假&#xff0c;我将会持续更新&#xff0c;并给大家带了更好理解的题解&#xff01;希望大家多多支持。 由于&#xff0c; A ∼ C A\sim C A∼C 题比较简单&am…

Git 上传Github 超时问题

提交代码到GitHub总是超时&#xff0c;偶尔会直接上传成功。 提供一下解决方案 1.首先找到网络 2. 找到代理 3. 把自动检查设置全部关闭&#xff0c;然后打开手动设置代理&#xff0c;然后输入ip地址和你代理的端口号&#xff0c;保存即可。 4. 最后使用git push origin mast…

java中如何将一个集合list转成以逗号隔开的字符串

事例代码 代码&#xff1a; package com.air.app;import java.util.ArrayList; import java.util.List;public class ListToStringTest {public static void main(String[] args) {//定义list集合List<String> list new ArrayList<>();list.add("1");…

基于低代码平台打造的焙乐道销售支持系统

编者按&#xff1a;低代码平台说了那么多&#xff0c;在实际应用中又是怎样体现的它的种种优势呢&#xff1f;今天小编结合实际案例来说说。 本文是以最大的烘焙原料产商——焙乐道的销售支持系统为例子&#xff0c;进行说明。 客户说明&#xff1a;焙乐道是一家国际性集团公司…

Python一行命令搭建HTTP服务器并外网访问+-+内网穿透

文章目录 1.前言2.本地http服务器搭建2.1.Python的安装和设置2.2.Python服务器设置和测试 3.cpolar的安装和注册3.1 Cpolar云端设置3.2 Cpolar本地设置 4.公网访问测试5.结语 转载自远程内网穿透的文章&#xff1a;【Python】快速简单搭建HTTP服务器并公网访问「cpolar内网穿透…

CentOS Linux上安装JDK11、MySQL8.0、Minio等软件(rpm脚本模式)

本地环境&#xff1a;Windows 10家庭版 16G内存 512G硬盘 软件&#xff1a;VMWare WorkStation 16.0 FinalShell 4.0.1 一、下载必要软件包 下载软件均选择x86架构64位&#xff01;&#xff01;&#xff01;&#xff08;可根据自己的电脑配置选择&#xff09; CentOS Linu…

数字图像处理(三)

目录 实验六、图像分割方法 实验七、图像识别与分类 实验六、图像分割方法 一、实验目的 了解图像分割技术相关基础知识&#xff1b;掌握几种经典边缘检测算子的基本原理、实现步骤理解阈值分割、区域分割等的基本原理、实现步骤。理解分水岭分割方法的基本原理、实现方法。…

ModaHub魔搭社区:Zilliz Cloud快速开始教程(一)

目录 前提条件 创建 Collection 查看 Collection 插入数据 本教程涵盖以下 Zilliz Cloud 集群操作指南: 创建 Collection查看 Collection插入数据向量搜索、向量查询、通过 ID 获取 Entity删除 Entity删除 Collection 前提条件 在本文档中,我们将使用 Milvus 的 SDK。…

mysql单表查询,排序,分组查询,运算符,select,order by,group by

CREATE TABLE emp (empno int(4) NOT NULL, --员工编号ename varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,--员工名字job varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,--员工工作mgr int(4) NULL DEFAULT NU…

【计算机视觉】YOLOv8的测试以及训练过程(含源代码)

文章目录 一、导读二、部署环境三、预测结果3.1 使用检测模型3.2 使用分割模型3.3 使用分类模型3.4 使用pose检测模型 四、COCO val 数据集4.1 在 COCO128 val 上验证 YOLOv8n4.2 在COCO128上训练YOLOv8n 五、自己训练5.1 训练检测模型5.2 训练分割模型5.3 训练分类模型5.4 训练…

华为OD机试真题 Java 实现【快递投放问题】【2023 B卷 100分】,附详细解题思路

目录 一、题目描述二、输入描述三、输出描述四、Java算法源码五、效果展示1、输入2、输出 一、题目描述 有N个快递站点用字符串标识&#xff0c;某些站点之间有道路连接。每个站点有一些包裹要运输&#xff0c;每个站点间的包裹不重复&#xff0c;路上有检查站会导致部分货物无…

博客质量分计算——发布 version 5

目录 1. 背景2. 质量分 version 52.1 version 4 存在问题分析2.2 version 5 改进2.3 消融分析2.3.1 正向积极得分消融实验2.3.2 正向累积得分单变量实验2.3.3 非高分文章消融实验 2.4 V4 和 V5 版本质量分分布对比 3. 总结4. 参考 1. 背景 博客质量分顾名思义是用于衡量一篇博…

MyBatis查询数据库(1)

前言&#x1f36d; ❤️❤️❤️SSM专栏更新中&#xff0c;各位大佬觉得写得不错&#xff0c;支持一下&#xff0c;感谢了&#xff01;❤️❤️❤️ Spring Spring MVC MyBatis_冷兮雪的博客-CSDN博客 经过前⾯的学习咱们 Spring 系列的基本操作已经实现的差不多了&#xff0…

企业为什么要做自动化测试?如何成功实施自动化测试?

目录&#xff1a;导读 前言一、Python编程入门到精通二、接口自动化项目实战三、Web自动化项目实战四、App自动化项目实战五、一线大厂简历六、测试开发DevOps体系七、常用自动化测试工具八、JMeter性能测试九、总结&#xff08;尾部小惊喜&#xff09; 前言 企业为什么需要自…

掌握Python文件操作的绝招:打造数据之径,揭开文件操作的神秘面纱

文章目录 前言文件的基本操作打开文件操作关闭文件操作对文件进行操作1&#xff09;只读文件操作read()readlines()readline()seek() 2&#xff09;只写文件操作3&#xff09;文件追加操作读写、追加读写操作1. r 模式打开文件2. w 模式打开文件3. a 模式打开文件 以二进制的形…

UDP客户端和服务器

UDP客户端&#xff0c;也就是首先主动发送数据的一方&#xff0c;也就是发起服务请求的一方。 UDP服务器&#xff0c;也就是首先等待接收数据&#xff0c;并对接收的数据进行处理&#xff0c;返回计算结果的一方&#xff0c;也就是提供服务的一方。 在下面实验中使用到的函数 …

Linux进度条

Linux进度条 一.基本概念1.回车和换行2.缓冲区2.实现倒计时 二.进度条 一.基本概念 1.回车和换行 回车&#xff1a;指光标移到该行的起始位置&#xff08;\r&#xff09;。 换行&#xff1a;换到下一行&#xff08;\n&#xff09;。 在c语音里\n将回车和换行相结合了。 2.缓冲…