18.4.4 将user1/getopt分支合并到主线
既然开发者user1负责的功能开发完成了,那就合并到开发主线master上吧,这样测试团队(如果有的话)就可以基于开发主线master进行软件集成和测试了。具体操作过程如下。
(1)为将分支合并到主线,首先user1将工作区切换到主线,即master分支。
$git checkout master
Switched to branch 'master'
(2)然后执行git merge命令以合并user1/getopt分支。
$git merge user1/getopt
Updating ebcf6d6..0881ca3
Fast-forward
src/main.c|41++++++++++++++++++++++++++++++++++++——-
1 files changed,36 insertions(+),5 deletions(-)
(3)本次合并非常顺利,实际上合并后master分支和user1/getopt指向同一个提交。这是因为合并前的master分支的提交就是usr1/getopt分支的父提交,所以此次合并相当于将分支master重置到user1/getopt分支。
$git rev-parse user1/getopt master
0881ca3f62ddadcddec08bd9f2f529a44d17cfbf
0881ca3f62ddadcddec08bd9f2f529a44d17cfbf
(4)查看状态信息可以看到本地分支和远程分支的跟踪关系。
$git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit(working directory clean)
(5)上面的状态输出中显示本地master分支比远程共享版本库的master分支领先,可以运行git cherry命令查看哪些提交领先(未被推送到上游跟踪分支中)。
$git cherry
+0881ca3f62ddadcddec08bd9f2f529a44d17cfbf
(6)执行推送操作,完成本地分支向远程分支的同步。
$git push
Counting objects:7,done.
Delta compression using up to 2 threads.
Compressing objects:100%(4/4),done.
Writing objects:100%(4/4),689 bytes,done.
Total 4(delta 3),reused 0(delta 0)
Unpacking objects:100%(4/4),done.
To file:///path/to/repos/hello-world.git
ebcf6d6..0881ca3 master->master
(7)删除user1/getopt分支。
既然特性分支user1/getopt已经合并到主线上了,那么该分支已经完成了历史使命,可以放心地将其删除。
$git branch-d user1/getopt
Deleted branch user1/getopt(was 0881ca3).
开发者user2对多语种支持功能有些犯愁,需要多花些时间,那么就先不等他了。