Git rebase 合并冲突无法继续。

187

我正在尝试将“dev”分支变基以赶上“master”分支。

$ git checkout dev 
$ git rebase master 
First, rewinding head to replay your work on top of it...
Applying: Corrected compilation problems that came from conversion from SVN.
Using index info to reconstruct a base tree...
M       src/com/....
<stdin>:125: trailing whitespace.
/**
<stdin>:126: trailing whitespace.
 *
<stdin>:127: trailing whitespace.
 */
<stdin>:128: trailing whitespace.
package com....
<stdin>:129: trailing whitespace.

warning: squelched 117 whitespace errors
warning: 122 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging src/com/....
CONFLICT (content): Merge conflict in src/com/...
Failed to merge in the changes.
Patch failed at 0001 Corrected compilation problems that came from conversion from SVN.

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

$ vi src/com/.....   { fixed the merge issue on one file } 
$ git add -A . 
$ git rebase --continue 
src/com/....: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add
$ vi src/com....      { verified, no >>> or <<< left, no merge markers } 
$ git rebase --continue 
Applying: Corrected compilation problems that came from conversion from SVN.
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 would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".

有什么想法吗?


1
注意:有时候 git rebase --skip 仍然可能无法正常工作。直到 Git 2.0.2(2014年7月)才解决了这个问题。请参见我的回答 - VonC
有时候像这样的问题,最好重新开始合并,并且要特别小心地做每一步(这并不容易)。 - Brent Bradburn
6个回答

311

我曾经遇到过几种情况会导致 rebase 卡住。其中一种是,如果更改变为空(提交中的更改在重置期间已经进行了),那么你可能需要使用 git rebase --skip

很容易识别。如果你运行 git status,它应该不显示任何更改。如果是这种情况,请跳过此步骤。如果不是,请提供 git status 的复制品,我可以尝试提供进一步帮助。


当我的'git pull --rebase origin master'似乎陷入了需要解决冲突和跳过之间的循环时,这帮助了我。经过更多的耐心等待,我已经解决了问题,谢谢! - AnneTheAgile
5
git status 返回:"正在进行变基;在<commitnumber>上,您当前正在将分支'<branchname>'变基到'<commitnumber>'。 (所有冲突已解决:运行“git rebase --continue”)"。git rebase --continue 没有任何更改,而git rebase --skip 有,但在我的情况下,我一遍又一遍地遇到了这种情况。 这是正确的还是有什么问题? - Adil
谢谢。我担心 --skip 会比继续使用我所做的更糟糕。 - jchook
在我的情况下,Intellij Idea GUI和SourceTree都显示每个文件已添加到提交中,而git status则显示有一个文件被修改,但未添加到提交中。执行add somefile.txt允许继续重新设置基础。 - azizbekian
跳过也有丢失一些更改的风险。Git有时会欺骗用户... - Karsten
显示剩余2条评论

21

我遇到这个问题的其中一次是在执行git add之后进行git commit。因此,以下步骤将产生您提到的rebase错误:

git add <file with conflict>
git commit -m "<some message>"  
git rebase --continue

虽然下面的序列没有出现任何错误,并继续了基地重构:

git add <file with conflict>
git rebase --continue

可能使用 git add -A 选项中的“全部”选项会创建类似的情况。(请注意,我在 git 方面非常缺乏经验,因此这个答案可能不正确。)为了安全起见,在这种情况下,git rebase --skip 似乎也可以很好地解决问题。


6
注意:Git 2.0.2(2014年7月)修正了一个情况,即git rebase --skip会卡住并无法继续进行当前的rebase。
请参见commit 95104c7 from brian m. carlson (bk2204)

rebase--merge: 修复连续两个冲突时的--skip

如果git rebase --merge遇到冲突,则如果下一个提交也有冲突,则--skip将无法工作
msgnum文件永远不会更新为新的补丁号,因此实际上没有跳过补丁,导致无法逃脱的循环。

在call_merge中的第一件事就是更新msgnum文件的值。
这也避免了在跳过提交时出现“已应用”的消息。
对于调用call_merge的其他上下文来说,没有可见的变化,因为在这些情况下,msgnum文件的值保持不变。


6
在冲突较多的rebase过程中(长时间使用git status),我无法确定应该暂存哪些内容。我使用的是PhpStorm集成的Git,在其中它没有显示未暂存的文件。git add .无法解决此问题,但这个评论建议调用git diff-files --ignore-submodules。这将显示三个文件需要特别添加到git,这样就解决了问题。

3
$ vi src/com....      { verified, no >>> or <<< left, no merge markers } 
$ git rebase --continue 

看起来你忘记了将改动添加到 git 中...


第二次只需要"verify",没有任何更改。在其上面是正确的Git添加。 - awm
你使用了 git add 然后继续合并,但是它停止了因为另一个文件有冲突,所以你还需要修复那个文件。我有什么遗漏吗? - John Brodie
1
这是同一个文件正在报告需要合并。好的,就为了你,我会再执行一次“git add”,但结果是相同的。 - awm
谢谢!那是我的情况:我解决了冲突,但没有暂存更改。 - Kirill

0

我在某个分支中删除了一个文件,然后在一些提交之后,发现该文件也被另一个分支删除了。为了让rebase继续进行,我不得不使用git rm命令来删除该文件。

我尝试重现这个问题,但是并没有出现“无法继续”的情况。如果有人想要尝试,请看看我尝试的内容:

mkdir t
cd t
git init
echo a > a.txt && echo b > b.txt && git add . && git commit -m "+a +b"

git checkout -b no-a
echo b1 > b.txt && git add b.txt && git commit -m "~b1"
git rm a.txt && echo b2 > b.txt && echo c1 > c.txt && git add . && git commit -m "-a ~b +c"

git checkout main
git rm a.txt && echo b0 > b.txt && echo c0 > c.txt && git add . && git commit -m "~b +c"
git log --oneline --graph --decorate --all

git checkout no-a
git status
git rebase main
ls
cat b.txt
git status

git checkout no-a b.txt
git commit -m "-a ~b"
git rebase --skip

git checkout no-a c.txt && git checkout main a.txt
git commit -m "~b +c"
git rebase --skip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接