git rebase vs git merge

語法爲git rebase [base], base就是commit id或者ref名稱
好比git fetch; git rebase origin/master

就是將本身自clone或上次pull以來全部的本身所作的的commit(還沒有push的)放在[base]以後,讓commit history看起來是線性的。

如下是精華部分: html

Suppose originally there were 3 commits,A,B,C: linux

A-B-C

Then developer Dan created commitD, and developer Ed created commitE: git

A-B-C-D-E

Obviously, this conflict should be resolved somehow. For this, there are 2 ways: github

MERGE: segmentfault

A-B-C-D-E-M

Both commitsDandEare still here, but we create merge commitMthat inherits changes from bothDandE. However, this creates diamond shape, which many people find very confusing. ide

REBASE: fetch

A-B-C-D-E-R

We create commitR, which actual file content is identical to that of merge commitMabove. But, we get rid of commitE, like it never existed (denoted by dots - vanishing line). Because of this obliteration,Eshould 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! ui





詳細的解釋挨個讀:

http://stackoverflow.com/questions/16666089/whats-the-difference-between-git-merge-and-git-rebase this

http://stackoverflow.com/questions/16336014/git-merge-vs-rebase htm

http://segmentfault.com/q/1010000000430041

http://linux.cn/article-4046-1.html

http://gitbook.liuhui998.com/4_2.html

https://benmarshall.me/git-rebase/ https://help.github.com/articles/using-git-rebase/

相關文章
相關標籤/搜索