Git – 分支合并(merge)

工作中,通常多人会同时在不同分支上进行工作,然后需要把不同分支的工作合并到一个分支。

例如,前面章节中,我们在dev分支上提交了test1.txt的修改,master分支上是没有这个提交的,现在想把这个提交合并到master分支。

要合并分支,可以使用命令:

git merge <branch name>

该命令把指定分支<branch name>,合并到当前分支。

注意 可以使用git log查看当前分支的提交记录,比较一下dev分支与master分支的提交记录:

$ git checkout dev
Switched to branch 'dev'

Kevin@qikegu MINGW64 /g/project/git-demo (dev)
$ git log
commit de35112d50b2f59b640d2b395d1315f0195cf7ec (HEAD -> dev)
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 20:48:34 2019 +0800

    add 'abcde' to test1.txt

commit 0d22e8a603dec5d9c90d142dd301ac08c8df4a10 (origin/master, origin/HEAD, master)
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 18:27:46 2019 +0800

    add text to test1.txt

commit 492204d0e04e99d0c02c9f685a0046688d68e012
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 18:25:41 2019 +0800

    update

commit 9441f90a3c004b759c8257d8cb8fba5f139ae05c
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 12:57:09 2019 +0800

    add text1.txt

commit e1b9b710a4f4ca900d4fe37b9590f63479fd480d
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Sun Aug 18 11:55:33 2019 +0800

    Initial commit


$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

Kevin@qikegu MINGW64 /g/project/git-demo (master)
$ git log
commit 0d22e8a603dec5d9c90d142dd301ac08c8df4a10 (HEAD -> master, origin/master, origin/> HEAD)
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 18:27:46 2019 +0800

    add text to test1.txt

commit 492204d0e04e99d0c02c9f685a0046688d68e012
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 18:25:41 2019 +0800

    update

commit 9441f90a3c004b759c8257d8cb8fba5f139ae05c
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Mon Aug 19 12:57:09 2019 +0800

    add text1.txt

commit e1b9b710a4f4ca900d4fe37b9590f63479fd480d
Author: kevinhwu <kevinhwu@qikegu.com>
Date:   Sun Aug 18 11:55:33 2019 +0800

    Initial commit

可以看到,commit de35112d50b2f59b640d2b395d1315f0195cf7ec这次提交只在dev分支中,master分支中不存在。

章节



浙ICP备17015664号 浙公网安备 33011002012336号 联系我们 网站地图  
@2019 qikegu.com 版权所有,禁止转载