2014-04-13 37 views
2

我想使用git rebase來提交一系列提交併將它們應用於不同的根提交。例如,git rebase是否有等價的「git apply --reject」?

git rebase --onto root start finish 

獲得基於rootstartfinish的提交。

當git的不能申請提交乾淨,它會更新文件顯示這樣的衝突(例如,從git的手冊):

 Here are lines that are either unchanged from the common 
     ancestor, or cleanly resolved because only one side changed. 
     <<<<<<< yours:sample.txt 
     Conflict resolution is hard; 
     let's go shopping. 
     ======= 
     Git makes conflict resolution easy. 
     >>>>>>> theirs:sample.txt 
     And here is another line that is cleanly resolved or unmodified. 

程序員文件編輯它應在新的分支是什麼,然後運行git --rebase continue以繼續添加來自源的提交。

但是,當文件在rootstart之間有很多變化時,可能會有許多這樣的行,並且它們可能很難解釋。在這種情況下,人們可能更喜歡將「失敗的hunks」輸出到文件中,以便人們可以通讀原始提交中的更改(手動對所要更改的文件進行更改,然後運行git rebase --continue以繼續添加提交)。

git apply--reject選項執行此操作:

--reject 
     For atomicity, git apply by default fails the whole patch and does 
     not touch the working tree when some of the hunks do not apply. 
     This option makes it apply the parts of the patch that are 
     applicable, and leave the rejected hunks in corresponding *.rej 
     files. 

這也是patch程序的行爲 - 這樣我就可以得到我想要先outputing與git show提交,然後用patch應用它。然而,當涉及許多提交時,這並不方便。

有沒有辦法做到這一點與git rebase(或另一個git命令)?

+0

您是否考慮過使用視覺差異/合併工具來幫助您解釋衝突標記?我使用Beyond Compare,我發現它爲我節省了很多時間來修復合併衝突。 –

+0

我不知道他們是什麼。他們是否允許您指定大塊適用於文件的位置? (我已經重新組織了文件,並且git或補丁不知道在哪裏應用hunk,這就是爲什麼我想要手動完成所有工作。) –

+0

你在使用什麼操作系統,Windows,OS X或Linux? –

回答

0

你可以在commit-by-commit的基礎上做這樣的事情。

當合並衝突發生時,混帳給人這樣的消息:如果file.c錯位是由於出文件中的合併衝突

CONFLICT (content): Merge conflict in file.c 
Failed to merge in the changes. 
Patch failed at 0004 Changes to file 
The copy of the patch that failed is found in: 
    /home/g/src/project/.git/rebase-apply/patch 

,你可以得到的文件恢復到它以前的方式在與

git reset file.c 
git checkout file.c 

犯然後,您可以運行

patch -p1 </home/g/src/project/.git/rebase-apply/patch 

這樣做的輸出可以看看像

patching file file.c 
Hunk #2 FAILED at 1133. 
Hunk #3 FAILED at 1167. 
Hunk #4 FAILED at 1201. 
Hunk #5 FAILED at 1241. 
Hunk #6 FAILED at 1251. 
Hunk #7 succeeded at 1324 (offset 6 lines). 
Hunk #8 FAILED at 1325. 
Hunk #9 succeeded at 2142 (offset 11 lines). 
Hunk #10 succeeded at 2163 (offset 11 lines). 
Hunk #11 succeeded at 2181 (offset 11 lines). 
Hunk #12 succeeded at 2279 (offset 11 lines). 
Hunk #13 succeeded at 2299 (offset 11 lines). 
Hunk #14 succeeded at 2412 (offset 11 lines). 
Hunk #15 succeeded at 2508 (offset 11 lines). 
Hunk #16 succeeded at 2531 (offset 11 lines). 
Hunk #17 succeeded at 2540 (offset 11 lines). 
Hunk #18 succeeded at 2581 (offset 11 lines). 
Hunk #19 succeeded at 2599 (offset 11 lines). 
Hunk #20 succeeded at 2611 (offset 11 lines). 
Hunk #21 succeeded at 2629 (offset 11 lines). 
Hunk #22 succeeded at 2637 (offset 11 lines). 
Hunk #23 succeeded at 2668 (offset 11 lines). 
Hunk #24 succeeded at 2677 (offset 11 lines). 
Hunk #25 succeeded at 2805 (offset 11 lines). 
Hunk #26 succeeded at 2871 (offset 11 lines). 
Hunk #27 succeeded at 2911 (offset 11 lines). 
Hunk #28 succeeded at 3028 (offset 11 lines). 
Hunk #29 succeeded at 3085 (offset 11 lines). 
Hunk #30 succeeded at 3117 (offset 11 lines). 
Hunk #31 succeeded at 3557 (offset 11 lines). 
Hunk #32 succeeded at 3572 (offset 11 lines). 
Hunk #33 succeeded at 4773 (offset 11 lines). 
Hunk #34 succeeded at 4807 (offset 11 lines). 
Hunk #35 succeeded at 4859 (offset 11 lines). 
6 out of 35 hunks FAILED -- saving rejects to file file.c.rej 

然後手動使file.c.rej的變化,然後運行

git add -u 
git rebase --continue 

繼續。