git rebase實戰


在develop分支上rebase另外一個分支master,是將master作為本地,develop作為遠端來處理的。

最后的效果是,develop分支看起來像是在master分支的最新的節點之后才進行開發的

 

 

develop分支上的commit記錄

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (develop)
$ git log
commit f529181aa7aa12794b261b5be57e948792168dd6  C5
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:43:21 2015 +0800

1.添加I love you

commit ccdaa5fd698d68854ad43bfc1ddef614ea2441ac  C4
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:43:02 2015 +0800

1.刪除hello world

commit dc697947fccd64b310d5b910c6c8faca0a6a914d   C3
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

commit 1f14a3c4a2bb5d9a26b6198733097f6801f6dcb9  C2
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:41:15 2015 +0800

1.添加hello

commit caf9736695f78779e9bae77afbc49d97a5e4959c    C1
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:40:48 2015 +0800

1.新增一個文件

 

 

 

master分支上的commit記錄

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (master)
$ git log
commit 618a561d8084af6b75ee6a9864bd2747c377eff6  C7
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:53:54 2015 +0800

添加lu

commit dc7ce42604209cc1cfb0b871043d89fd324830e3  C6
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:53:11 2015 +0800

添加chuck

commit dc697947fccd64b310d5b910c6c8faca0a6a914d  C3
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

commit 1f14a3c4a2bb5d9a26b6198733097f6801f6dcb9  C2
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:41:15 2015 +0800

1.添加hello

commit caf9736695f78779e9bae77afbc49d97a5e4959c  C1
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:40:48 2015 +0800

1.新增一個文件

 

 

develop分支和master分支的共同的父節點

commit dc697947fccd64b310d5b910c6c8faca0a6a914d
Author: ChuckLu <郵箱>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

 

C1<--C2<--C3<--C6<--C7      master分支

                     <--C4<--C5      develop分支

 

rebase開始

1.首先切換到develop分支  

git checkout develop

2.在develop分支上進行rebase    

git rebase master

【rebase是在master分支的最后一個提交C7上開始的】

將C4和C7合並,得到一個合並結果result1

再將C5和result1合並,得到一個合並結果result2

 

C4和C7合並的時候產生沖突,Local是C7,C5作為Remote出現。

在develop分支上rebase另外一個分支master,是將master作為本地,develop作為遠端來處理的。

 

 處理完沖突之后,保存,並標記為解決沖突

1.第一種處理方式,處理結果為直接使用右側的文件

 

git rebase --continue

這時候,會收到提示,

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (develop|REBASE 1/2)
$ git rebase --continue
Applying: 1.刪除hello world
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

 

即便是已經處理了沖突,但是這個沖突比較特殊。上圖的合並結果,是以右側的現有文件(Local)作為處理結果的。

關於這個,這里有解釋http://stackoverflow.com/questions/4033009/git-rebase-conflicts-keep-blocking-progress

 Word of caution: Please note that git rebase --skip will completely drop the commit that git tried to rebase.

In our case, this should be okay since git is complaining this is an empty commit.

If you think you've lost changes once the rebase is complete, you can use git reflog to get the commit id of your repository before the rebase,

and use git reset --hard to get your depot back in that state (this is another destructive operation).

這個時候,需要通過git rebase --skip來跳過

 

 

2.第二種處理方式,合並結果,既不是Local也不是Remote的

這種情況下git rebase --continue

就可以正常工作

 

 

當前處於分支A,執行命令

git rebase B

那么在處理沖突的時候,Local是B,Remote是A

 

 

 

C1  v0.10.12     5fc35f2b069116b334a20f324bf135237627e404

C2  load language setting before GameV2 initialized    78f9d8de291f0e241bcb0ecd7ce532109fcef657

C3  fix config not loading early enough,causing no language besides enUS to work  0bb37cb02d9a120e6e311303bffd85d2c5d648bb

C4  v0.10.13 (language fix)   3b82bb138f149788611f48c8fdfbf1f18ea3b029

1.在chucklu_master的分支上執行git rebase temp

 以temp的最后一個提交對象v0.10.13,假定這次提交為C4,

chucklu_master上,實際只有一個新的提交,假定為C2

rebase的時候,會把C2的修改和C4進行一次合並,發現有沖突

手動合並,

git rebase --continue 

如果合並的結果是Local的話[會提示git add],這種情況下,直接就git rebase --skip

上面這句話,以為着,合並結果是temp的節點C4,這會導致,chucklu_master上的提交記錄直接被忽略掉

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_master|REBASE 1/1)
$ git rebase --continue
Applying: load language setting before GameV2 initialized
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

如果收到這樣的提示,則說明這次的合並,是無效的。當前分支上的這一次commit,對於基底分支temp來說,沒有任何意義。所以直接跳過。

 

 

 

2.在temp分支上執行 git rebase chucklu_master

 以chucklu_master的最后一個提交對象,假定這次提交為C2

temp分支,實際上有2個提交,假定為C3和C4

rebase的時候,首先是C3和C2進行合並,得到結果result

然后把C4和上一步的result合並,得到另外一個結果result1

 

生成了新的commit  fix config not loading early enough, causing no language besides enUS to work.   dd076d7b5da66c17eae4bbdc8a7af4c635ef0360

雖然提交信息是一樣的,但是SHA的值已經改變

v0.10.13 (language fix)     238a2d1042106c8e94722794d980e75439261be5

 

 

 

===2015年10月20日更新===

$ git rebase --continue
ZBMYun/SourceCode/ZITakerHS/ZITaker/UI/FormDeviceInfo.cs: needs update
You must edit all merge conflicts and then
mark them as resolved using git add

處理完沖突之后,提示這個。記得用tortoisegit的圖形化界面處理完沖突的,並且標記了resolved量。

不知道為什么還提示這個,

按照提示執行

$ git add UI/FormDeviceInfo.cs

最后再執行git rebase --continue就完成了

 

 

===2015年10月25日凌晨3:41更新===

$ git rebase --continue
Applying: Re-Fix gold progress display, add background image
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

這種情況下,沒有提示有具體的文件需要git add

直接執行git rebase --skip就可以了

執行完成以后,需要記得和之前第三方的最后一次提交,進行compare。如果一致的話,就說明rebase是有效的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM