18.5.4 开发者user2合并推送
开发者user2在本地版本库完成提交后,不要忘记向远程共享版本库进行推送。但在推送分支hello-1.x时开发者user2没有开发者user1那么幸运,因为此时远程共享版本库的hello-1.x分支已经被开发者user1推送过一次,因此开发者user2在推送过程中会遇到非快进式推送问题。
$git push
To file:///path/to/repos/hello-world.git
![rejected]hello-1.x->hello-1.x(non-fast-forward)
error:failed to push some refs to 'file:///path/to/repos/hello-world.git'
To prevent you from losing history,non-fast-forward updates were rejected
Merge the remote changes(e.g.'git pull')before pushing again.See the
'Note about fast-forwards' section of 'git push—help' for details.
就像在“第15章 Git协议和工作协同”一章中介绍的那样,开发者user2需要执行一个拉回操作,将远程共享服务器的改动获取到本地并和本地提交进行合并。
$git pull
remote:Counting objects:7,done.
remote:Compressing objects:100%(4/4),done.
remote:Total 4(delta 3),reused 0(delta 0)
Unpacking objects:100%(4/4),done.
From file:///path/to/repos/hello-world
ebcf6d6..b56bb51 hello-1.x->origin/hello-1.x
Auto-merging src/main.c
Merge made by recursive.
src/main.c|2+-
1 files changed,1 insertions(+),1 deletions(-)
通过显示分支图的方式查看日志,可以看到在执行git pull操作后发生了合并。
$git log—graph—oneline
*8cffe5f Merge branch 'hello-1.x' of file:///path/to/repos/hello-world into hello-1.x
|\
|*b56bb51 Fix typo:-help to—help.
*|e64f3a2 Bugfix:allow spaces in username.
|/
*ebcf6d6 blank commit for GnuPG-signed tag test.
*8a9f3d1 blank commit for annotated tag test.
*60a2f4f blank commit.
*3e6070e Show version.
*75346b3 Hello world initialized.
现在开发者user2可以将合并后的本地版本库中的提交推送给远程共享版本库了。
$git push
Counting objects:14,done.
Delta compression using up to 2 threads.
Compressing objects:100%(8/8),done.
Writing objects:100%(8/8),814 bytes,done.
Total 8(delta 6),reused 0(delta 0)
Unpacking objects:100%(8/8),done.
To file:///path/to/repos/hello-world.git
b56bb51..8cffe5f hello-1.x->hello-1.x