git pull and git rebase

relevant article:
使用git fetch和git rebase處理多人開發同一分支的問題——azureternite
我先update sem.c,但有人update itoa.cpp並且比我先提交。

gir pull:

* 949238e (HEAD -> master) Merge branch 'master' of https://github.com/theArcticOcean/CLib (weistephen<[email protected]>, Wed May 30 23:13:23 2018)
|\
| * c20582e (origin/master) :sparkles: update itoa.cpp (weistephen<[email protected]>, Wed May 30 22:36:21 2018)
* | b04d196 :sparkles: update sem.c (weistephen<[email protected]>, Wed May 30 22:47:02 2018)
|/
* 519b6f8 :memo: update README.md (weistephen<[email protected]>, Sat May 26 15:34:23 2018)

git rebase
關於git rebase,解釋是這樣的:git-rebase - Reapply commits on top of another base tip
因爲服務器上已經有了新的修改,我們想要做的事情就是將把那些修改拿過來,然後把我們的修改補上。
這正好符合rebase的場景。

Assume the following history exists and the current branch is "topic":

                     A---B---C topic
                    /
               D---E---F---G master


       From this point, the result of either of the following commands:

           git rebase master
           git rebase master topic

       would be:

                             A'--B'--C' topic
                            /
               D---E---F---G master

fetch 並且rebase

➜ CLib git:(master) git fetch
➜ CLib git:(master) git rebase
First, rewinding head to replay your work on top of it...
Applying: :sparkles: update sem.c
➜ CLib git:(master) git-tree

git-tree:

* 9044a50 (HEAD -> master) :sparkles: update sem.c (weistephen<[email protected]>, Thu May 31 08:10:52 2018)
* c20582e (origin/master) :sparkles: update itoa.cpp (weistephen<[email protected]>, Wed May 30 22:36:21 2018)
* 519b6f8 :memo: update README.md (weistephen<[email protected]>, Sat May 26 15:34:23 2018)

git-tree的原型是
alias git-tree=“git log --graph --decorate --pretty=format:’%C(red)%h%C(yell ow)%d%C(reset) %s %C(green)(%an<%ae>, %cd)%C(reset)’ --abbrev-commit --date= local $*”

總結:簡答的說,git pull中的merge步驟會產生一個新的commit,將兩個分支合併,所以有兩條線相匯。git rebase branchA [branchB]直接將A分支中的commit放到B分支中,形成一條新的提交線,沒有兩條線交匯的場景。這兩種解決代碼衝突的方案,rebase的history顯得更加“乾淨”一些。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章