2012-11-19 79 views
15

我想重新綁定一個分支,git因爲試圖執行一些失敗的合併操作而氾濫。我該如何讓git來阻止它?由於空白錯誤git rebase失敗

# git rebase -f --onto master~2 master~ master 
First, rewinding head to replay your work on top of it... 
Applying: r1002 - CS 1.0.23 
Using index info to reconstruct a base tree... 
M about.html 
<stdin>:68: trailing whitespace.      
<stdin>:115: trailing whitespace. 
<stdin>:201: trailing whitespace. 
<stdin>:2369: trailing whitespace. 
<stdin>:2385: trailing whitespace. 
warning: squelched 2305 whitespace errors 
warning: 2310 lines add whitespace errors. 
Falling back to patching base and 3-way merge... 
Auto-merging about.html 
CONFLICT (content): Merge conflict in about.html 
Failed to merge in the changes. 
Patch failed at 0001 r1002 - 1002 
The copy of the patch that failed is found in: 
    /local/melder/tmp/test/.git/rebase-apply/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". 

正如你可以看到有2000+空白的錯誤,不是容易用手合併。

編輯:以側步這個現在不合並我所做的:

# git add -A 
# git rebase --continue 

編輯:請不要介意這是一個愚蠢的想法。

回答

5

這將不會出現問題。你現在在文件中有衝突標記!

空白問題是警告,你不應該有很多合法的衝突。如果文件是一個噩夢來解決,你可能需要手工重建它。這取決於你在做什麼。

很多時候,這兩個基地是如此不同,每次承諾你rebasing讓你處理這個怪異的衝突。我傾向於避免重新配置工作流並訂閱合併/重置。這是我做的:http://dymitruk.com/blog/2012/02/05/branch-per-feature/

如果你的問題是隻有像行尾空白的問題,你可以嘗試做每邊一個過濾器的分支或交互式底墊清理你的資料庫第一個拿到空白每次提交是是一致的。

此外,我使用無法比較3或Perforce合併做衝突解決方案。 BC3具有語法意識,並且應該最好地處理空白。很多時候,它甚至不會開放,因爲它會爲你解決衝突,你可以繼續。

+1

嗯......你說得對,那不好。我嘗試使用rebase -X他們的策略,並且工作。事情是我試圖自動化這個rebasing過程。回購中應該沒有真正的衝突,我相信空白錯誤是由unix/windows移動造成的。如果可能的話,我想回避一下。 – melder

1

我認爲大多數差異查看器(特別是那些有GUI)讓你選擇如何處理空白變化。

我建議你使用類似meld的東西作爲你的git mergetool來自動糾正這些衝突。當啓動meld時,將其設置爲空白處理策略(來自Preferences面板的Text filters選項卡),並自動調整這些更改。

+0

感謝您的迴應,但我想自動化此過程。由於開發人員在不同的系統上工作,並將代碼移動到各種操作系統上,因此我正在處理非常大的存在空白問題的回購。當我們擁有數百個數據庫並且在其中存在數千個空白不一致時,進入併合並每一個回購是不切實際的。 – melder

1

今天我解決了這樣一個問題是這樣的:

REMOVE_AFTER="3cd7a0db76ff9dca48979e24c39b408c" 
REPO="[email protected]:company/repo.git" 
cd ~/tmp 
git clone $REPO gitfix 
cd gitfix 
git checkout --orphan temp $REMOVE_AFTER 
git commit -m "Truncated history" 
git rebase --strategy=recursive --strategy-option=theirs --onto temp $REMOVE_AFTER master 

當底墊在你這是由已刪除的文件引起了CONFLICT (modify/delete)衝突,就可以解決這樣說:

git rm path/to/both/deleted/file 
git rebase --continue 

在rebase期間,您會遇到其他衝突,您需要手動修復它,然後:

git add path/to/conflict/file 
git rebase --continue 

當您完成,底墊說:All done.然後,您可以:

git branch -D temp 

現在檢查結果:

git log --format=oneline 
+0

REMOVE_AFTER指向哪個分支/更改? –

+1

@EdRandall不記得了。我想我的修復是爲了解決衝突,因爲刪除的文件。所以我想REMOVE_AFTER是git commit之後發生衝突的提交。 –

11

我今天所面臨的同樣的問題:重訂由於失敗造成的空白錯誤衝突。 與爲whitespace選項(git rebase --whitespace=fixgit rebase --whitespace=nowarn)不同的設置試驗失敗後,爲我工作的解決方案是忽略遞歸合併策略尾隨空白錯誤(git rebase --abort任何正在運行的第一重訂,如果需要的話):

git rebase -Xignore-space-at-eol <newbase> 

取決於空白錯誤種類,選項-Xignore-space-change-Xignore-all-space可能更有用。我不知道選項--ignore-whitespace是否也能起作用。

+0

'--ignore-whitespace'對我來說不起作用 - 它沒有它就返回完全一樣。 但'-Xignore' ...參數也不起作用 - 他們給我留下了相同的合併衝突,但沒有消息說有空白問題。 –

+0

@andrewlorien你確定這些衝突是由空白錯誤引起的,還是他們真正的代碼衝突?我的評論只適用於第一種情況。 – joanpau

+0

好問題,謝謝。我現在已經手動修復了這些錯誤,但我懷疑有空白和真實錯誤的混合。我認爲--ignore-whitespace沒有幫助,但我認爲-Xignore-space-at-eol確實忽略了空白問題,讓我解決了同一行中的其他問題。 –

相關問題