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看起来是线性的。

以下是精华部分:

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

A-B-C

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

A-B-C-D-E

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

MERGE:

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.

REBASE:

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!





详细的解释挨个读:

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

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

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/

你可能感兴趣的:(git rebase vs git merge)