合并两个commit有两种方式:一种是 git merge ,而这一种在git pull命令中是默认的 另一种是 git rebase
git pull命令中
git pull <远程主机名> <远程分支名>:<本地分支名>
例如:git pull origin next:master
把远程origin分支next fetch回来并git merge
git pull --rebase <远程主机名> <远程分支名>:<本地分支名>
而如果使用rebase方式则
git pull --rebase origin next:master
这里建议还是先git fetch在做决定是git merge还是git rebase吧,如果只是git pull则默认为merge。
现在看看merge和rebase的区别:
引用一个文章:http://*.com/questions/16666089/whats-the-difference-between-Git-merge-and-git-rebase
Suppose originally there were 3 commits, A
,B
,C
:
Then developer Dan created commit D
, and developer Ed created commit E
:
Obviously, this conflict should be resolved somehow. For this, there are 2 ways:
MERGE:
Both commits D
and E
are still here, but we create merge commit M
that inherits changes from both D
and E
. However, this creates diamond shape, which many people find very confusing.
REBASE:
We create commit R
, which actual file content is identical to that of merge commit M
above. But, we get rid of commit E
, like it never existed (denoted by dots - vanishing line). Because of this obliteration, E
should be local to developer Ed and should have never been pushed to any other repository. Advantage of rebase is that diamond shape is avoided, and history stays nice straight line - most developers love that!
diamond 菱形
get rid of 删除
identical 相同的