美文网首页
2019-03-05 Git分支管理

2019-03-05 Git分支管理

作者: 阿丧小威 | 来源:发表于2019-03-06 22:48 被阅读0次

分支管理1

98ca9,34ac2,f30ab分别为前3次提交内容,都有快照,工作在master分支上,master上面有一个HEAD指针指向它,所以每次提交都提交到master上面来

分支管理2

开发一个新的功能时,不能在master上开发,要在一个新的分支上开发,不然会很乱,比如testing分支

分支管理3

创建新分支后,HEAD指针还是指向master上,这时需要切换一下分支

分支切换

切换分支后,HEAD指针指向testing上了

分支命令

示例:

[root@localhost test]# git branch about    ---要开发一个about模块,所以创建一个名为about的分支
[root@localhost test]# git status
On branch master    ---创建分支后还在master上
nothing to commit, working directory clean
[root@localhost test]# git checkout about    ---切换指针
Switched to branch 'about'
[root@localhost test]# git status
On branch about    ---工作在about上了
nothing to commit, working directory clean
[root@localhost test]# git log    ---创建新的分支后还是只有前面的3个提交记录
commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# ll
total 12
-rw-r--r--. 1 root root 21 Mar  2 20:24 index.html
-rw-r--r--. 1 root root  5 Mar  2 20:38 news.html
-rw-r--r--. 1 root root 22 Mar  2 20:43 test.html
[root@localhost test]# vi about.html    ---开发一个新模块
about us
:wq
[root@localhost test]# git log    ---有4次提交记录了
commit 06c81edf9d8db4ab95c1558f8a551ac81de5a659
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 21:40:40 2019 +0800

    about

commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# ll
total 16
-rw-r--r--. 1 root root  9 Mar  2 21:40 about.html
-rw-r--r--. 1 root root 21 Mar  2 20:24 index.html
-rw-r--r--. 1 root root  5 Mar  2 20:38 news.html
-rw-r--r--. 1 root root 22 Mar  2 20:43 test.html
[root@localhost test]# git checkout master    ---切换回master
Switched to branch 'master'
[root@localhost test]# git log    ---发现只能看到之前的3个提交,看不到about的提交,说明分支已经朝着不同的方向演进了
commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# git branch    ---可以查看当前所在分支为master
  about
* master
[root@localhost test]# git checkout about
Switched to branch 'about'
[root@localhost test]# git branch
* about
  master
Merge

示例2:

把分支上的代码挪到master上去
[root@localhost test]# vi about2.html
about2
:wq
[root@localhost test]# git add .
[root@localhost test]# git commit -m "about2"
[about 96c9ee3] about2
 1 file changed, 1 insertion(+)
 create mode 100644 about2.html
[root@localhost test]# git log    ---一共5次提交
commit 96c9ee3183d8589922448da51a66554037f4c76b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 22:16:16 2019 +0800

    about2

commit 06c81edf9d8db4ab95c1558f8a551ac81de5a659
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 21:40:40 2019 +0800

    about

commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# git checkout master    ---切换到master
Switched to branch 'master'
[root@localhost test]# git log
commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# git merge about    ---把about分支与master共同的节点之后分离的节点重现在master分支上
Updating 8880be9..96c9ee3
Fast-forward
 about.html  | 1 +
 about2.html | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 about.html
 create mode 100644 about2.html
[root@localhost test]# git log    ---master也有5次提交了
commit 96c9ee3183d8589922448da51a66554037f4c76b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 22:16:16 2019 +0800

    about2

commit 06c81edf9d8db4ab95c1558f8a551ac81de5a659
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 21:40:40 2019 +0800

    about

commit 8880be9fc12c00fe8f5a26a5f87e6b6af193ac7b
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:43:44 2019 +0800

    test

commit 8ce4e28510f0bdf1153c064e507b11e2b2052744
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:41:12 2019 +0800

    news

commit b613f505626d37c74b262ba5a345ef41740785fb
Author: zheng <zheng@qq.com>
Date:   Sat Mar 2 20:33:08 2019 +0800

    first commit
[root@localhost test]# git branch --merged    ---查看哪些分支已被并入当前分支
  about
* master
[root@localhost test]# git branch --no-merged    ---查看哪些分支没有被并入当前分支

相关文章

  • git常用命令

    分支管理 git 切换分支 git 查看远程分支 git 查看本地分支 git 创建本地分支 git 删除本地分支...

  • Git命令整理

    Git命令 ———————————————— git配置: git基本步骤: git分支管理: 创建分支命令: 切...

  • GIT分支管理

    GIT 分支管理 参考:在阿里,我们如何管理代码分支?GitHub Flow & Git Flow 基于Git...

  • git常用操作

    Basic Operation 分支管理切换分支git checkout git checkout -b #...

  • 2019-03-05 Git分支管理

    98ca9,34ac2,f30ab分别为前3次提交内容,都有快照,工作在master分支上,master上面有一个...

  • git提交代码规范管理

    GIT分支管理 git远程分支主要包括:master develop fixbugmaster:整个项目主分支,...

  • 2021-11-30

    一、分支管理 1、创建分支 git branch 2、查看分支 git branch...

  • git分支仓库管理

    git分支和标签管理 创建分支 git branch banchName git checkout -b bra...

  • git分支管理与使用规范

    git分支管理与使用规范 分支管理 flow git flow github flow gitlab flow f...

  • git 创建分支提交远程分支

    Git创建与管理远程分支 1.创建本地分支 git branch 分支名,例如:git branch 2.0.1....

网友评论

      本文标题:2019-03-05 Git分支管理

      本文链接:https://www.haomeiwen.com/subject/qmtzuqtx.html