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

news2024/11/28 4:50:39

文章目录

      • `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
|

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

轮询-实时调用接口

https://www.cnblogs.com/zhangliang88/p/16254460.htmlhttps://www.cnblogs.com/zhangliang88/p/16254460.html

软件测试 | Selenium对多浏览器处理

在执行自动化测试过程中&#xff0c;我们往往会针对不同的浏览器做兼容性测试&#xff0c;可以通过对测试用例代码的改造&#xff0c;实现对不同浏览器的自动化兼容性测试。 注&#xff1a;实现对不同浏览器的自动化兼容性测试&#xff0c;需要先将各个浏览器的驱动在PC端配置…

基于PyQt5的桌面图像调试仿真平台开发(15)图像融合

系列文章目录 基于PyQt5的桌面图像调试仿真平台开发(1)环境搭建 基于PyQt5的桌面图像调试仿真平台开发(2)UI设计和控件绑定 基于PyQt5的桌面图像调试仿真平台开发(3)黑电平处理 基于PyQt5的桌面图像调试仿真平台开发(4)白平衡处理 基于PyQt5的桌面图像调试仿真平台开发(5)…

AMEYA360:尼得科nidec恩布拉科变频压缩机介绍

能源安全、能源价格方面的挑战与气候危机交织 提高能源效率比以往任何时候都更为紧迫。 能源效率是应对当今全球能源危机的核心 也是能源价值创造的重要体现。 尼得科恩布拉科大金 带来制冷方面的节能研究 LMSEY系列冷库一体机使用变频调速可 节能约14%! 全球制冷技术供应商、尼…

浅谈配电能效平台在城市地下综合管廊的应用

摘要:电气设计是综合管廊设计的重要组成部分&#xff0c;文章对综合管廊的断面设计、供配电系统和缆线设计进行了分析阐述&#xff0c;并结合设计案例&#xff0c;简要总结了综合管廊电气设计要点。 关键词:综合管廊&#xff1b;断面设计&#xff1b;供配电系统&#xff1b;缆…

微信小程序如何进行开发?

文章目录 0.引言1.注册微信公众平台账号2.准备微信开发者工具3.创建微信小程序并预览 0.引言 笔者编程一般编得较多的是桌面软件&#xff0c;有时也会编手机软件&#xff0c;这些软件都必须安装才能使用&#xff0c;这限制了软件的推广。而现有社交软件如微信使用得较广泛&…

使用GitHub Actions 来进行项目远程服务器部署

由于项目源码是托管在github的&#xff0c;而部署是放在远程服务器上&#xff0c;并且使用nginx部署。 现在的部署流程时&#xff0c;需要更新时&#xff0c;在本地切换到master分支&#xff0c;执行构建操作&#xff0c;拿到构建出的dist目录&#xff0c;将其上传到远程服务的…

从GitLab拉取并运行项目

从GitLab拉取并运行项目 序Git项目运行运行报错 总结教训 序 搭建好前端基础环境后&#xff0c;开始尝试从单位项目组拉取项目尝试本地运行。 Git Git相关配置&#xff1a;一篇学会Git版本管理 先申请Git账号&#xff0c;随后由上级分配权限拉入该项目组。 通过git clone ……

年终奖大幅缩水,是去还是留?

一、年终奖的历史和意义 互联网行业是中国经济发展的一个重要支柱&#xff0c;这也使得互联网公司的年终奖一直是许多从业者最为关注的话题之一。随着行业的不断发展&#xff0c;互联网公司的年终奖也在不断提高&#xff0c;逐渐成为了企业吸引和留住人才的重要手段。在互联网…

基于archlinux的mabox-linux桌面系统,内存资源消耗只有278M!

今天安装了基于archlinux的mabox-linux桌面系统&#xff0c;内存资源消耗只有278M&#xff01;实在是惊到我了。先上图&#xff0c;改天有空再深入体验一下。 安装后发现没有1920X1080这个分辨率&#xff0c;设置的命令如下&#xff1a; 一&#xff0c;xrandr #查看本机支持的…

短期面试突击攻略大全!2023最全Java面试题目合集

这两年的面试难度确实要比往年高处很多。很多小伙伴投递了上千份简历&#xff0c;只有几家公司约面试。排除个人简历的因素&#xff0c;这在往年都是不太常见的。 大厂缩招&#xff0c;于是很多往年能进大厂的人只能去卷中小厂&#xff0c;搞得层层内卷。 比如往年能有一万个人…

旅游卡分销小程序开发

旅游业的不断发展&#xff0c;旅游卡分销小程序成为了越来越多旅游公司的选择。旅游卡分销小程序是一种在线分销平台&#xff0c;它允许游客购买旅游卡并分销给其他人&#xff0c;从而获得佣金。本文将探讨旅游卡分销小程序的开发。 一、确定旅游卡分销小程序的需求 在…

低代码平台能友好的融入到toB项目中吗?

低代码平台通常可以友好地融入现有toB的交付项目中。虽然低代码平台和传统的高代码开发具有不同的开发方式和工具集&#xff0c;但它们可以在同一个项目中协同工作&#xff0c;互相补充&#xff0c;那么实现能配置的尽可能配置化&#xff0c;配置不出来的就手写。 对于普通IT项…

.Hex文件直接解析的实现_PIC芯片

1.问题 bootloader写成后&#xff0c;需要处理传送过来的.Hex&#xff0c;或者等价的文件的烧录。MicroChip官方并未给出一个.Hex转为.Bin的处理策略。在它的Bootloader代码中&#xff0c;我们可以大致看到它的实现机制&#xff0c;它定义了一组命令。上位机在处理升级时&#…

基于FreeRTOS的嵌入式设备管理关键技术研究及实现(学习六重要)

差分升级算法研究及改进 文件差分算法通过对不同文件的片段进行对比查找差异&#xff0c;将差异描述输出为差分文件。 差分算法是差分升级的关键技术&#xff0c;因此&#xff0c;差分算法的性能决定着整个升级系统的性能。 差分算法研究 差分更新又称为增量编码&#xff0…

yarn介绍与说明

1.介绍 说明&#xff1a;Yarn 是一个由 Facebook、Google、Exponent 和 Tilde 公司联合推出的新一代 JavaScript 包管理工具&#xff0c;用于取代 npm。与 npm 相比&#xff0c;Yarn 可以更快地下载依赖&#xff0c;更好地管理依赖版本&#xff0c;更稳定地构建依赖关系。 2.…

AWVS扫描工具使用教程

AWVS是一款Web漏洞扫描工具&#xff0c;通过网络爬虫测试网站安全&#xff0c;检测流行的Web应用攻击&#xff0c;如跨站脚本、sql 注入等。据统计&#xff0c;75% 的互联网攻击目标是基于Web的应用程序。 AWVS的主要功能模块 Blind SQL Injector&#xff1a;盲注工具 HTTP E…

单元测试报错 No tests found for given includes: [StudyApplicationTests.contextLoads]

当你运行单元测试报错No tests found for given includes: [StudyApplicationTests.contextLoads] 如下&#xff1a; 可能是因为你的gradle测试默认使用的是以gradle启动,改成以IDEA启动即可

力扣 64. 最小路径和

文章目录 题目描述解题思路 题目描述 https://leetcode.cn/problems/minimum-path-sum/ 解题思路 问题类型&#xff1a;动态规划 private int MinPathSum(int[][] grid) {for (int i 0; i < grid.Length; i) {for (int j 0; j < grid[i].Length; j) {if (i 0 &am…

Vue3 Diff 算法简易版

背景 学习一下Vue3中的diff算法~ 逻辑概述 这个算法的过程不算太复杂&#xff1a; 同时从新旧列表的头部遍历&#xff0c;找出相同的节点&#xff0c;则patch&#xff0c;否则就停止遍历&#xff1b;同时从新旧列表的尾部遍历&#xff0c;找出相同的节点&#xff0c;则patc…