2013-10-18 105 views
9

我有遠程存儲庫。 我這樣做:git rebase與衝突不起作用

git clone https://[email protected]/mylogin/myrepo.git 

克隆成功。 我有git樹:
C(master)
|         B:A
|    /
B  /
|
A
|
A0
|
A01(origin/head)(origin/master)
|
(一些提交)

我需要:
                                B:
C(主) / 

我需要變基分支B到C(主) 我該怎麼做:

git checkout b1 
Switched to branch 'b1' 
git rebase master 
First, rewinding head to replay your work on top of it... 
Applying: B:A 
Using index info to reconstruct a base tree... 
M index1.txt 
Falling back to patching base and 3-way merge... 
Auto-merging index1.txt 
CONFLICT (content): Merge conflict in index1.txt 
Failed to merge in the changes. 
Patch failed at 0001 B:A 
The copy of the patch that failed is found in: 
    /pth/to dir/.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". 

git branch 
* (no branch) 
    b1 
    master 

我該做什麼? 我可以在分支b1中切換,解決衝突並提交,但它沒有幫助(我測試了它)。

回答

26

如果Git檢測到無法自動解決的衝突,它將停止重新綁定。在你的情況下,你在文件index1.txt中有衝突(你可以在輸出中看到它,在運行git status時也可以看到它)。在繼續之前,您必須解決衝突。編輯文件,您將看到<<<<<<======>>>>>>標記。衝突在這些行中,其中<=之間的內容是主機中的更改,之後(直到>)是分支b1中的更改。修復它,刪除git標記(<,=,>),然後運行git add index1.txt,並轉到下一個文件(如果有的話,在本例中只有index1.txt衝突)。完成添加所有文件後,運行git rebase --continue。如果git遇到另一個衝突,只需對每個有問題的文件重複該過程。一旦你完成了,git會告訴你rebase已經成功完成,你會回到b1。如果您想要停止該過程並返回原始b1(rebase命令之前),只需運行git rebase --abort

請記住,當您修復衝突時,請不要編輯文件,因爲它應該在最終提交中,而只是介紹爲特定提交所需的更改。隨着git繼續重新綁定並應用您的提交,其他更改將被添加。 「

+0

」不要編輯該文件,因爲它應該在您的最終提交中,而只是介紹爲特定提交所需的更改「+1。我想知道當我改變它們的時候,這些代碼行怎麼還在那裏? – Swapnil

+2

請注意,您應該編輯帶有衝突的文件(在您的案例中爲'index1.txt'),而不是'patch'文件。如果您不確定哪些變更正在重新設計,那麼'patch'就在那裏。 –