无法解决变基冲突

19
foo:/opt/bar$ git status
# On branch develop
nothing to commit (working directory clean)

foo:/opt/bar$ git pull --rebase origin develop
From ssh://xxx/yyy
* branch develop -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: Subscription logging added.
Using index info to reconstruct a base tree...
<stdin>:120: trailing whitespace.
* @return integer
<stdin>:143: trailing whitespace.
* @return integer
<stdin>:166: trailing whitespace.
* @return integer
<stdin>:189: trailing whitespace.
* @return integer
<stdin>:212: trailing whitespace.
* @return integer
warning: squelched 3 whitespace errors
warning: 8 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging app/config/config.yml
CONFLICT (content): Merge conflict in app/config/config.yml
Failed to merge in the changes.
Patch failed at 0001 Subscription logging added.

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".

foo:/opt/bar$ git status
# Not currently on any branch.
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: app/config/config.yml
#
no changes added to commit (use "git add" and/or "git commit -a")

foo:/opt/bar$ git add -A

foo:/opt/bar$ git status
# Not currently on any branch.
nothing to commit (working directory clean)

foo:/opt/bar$ git rebase --continue
Applying: Subscription logging added.
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".

foo:/opt/bar$ git add -A

foo:/opt/bar$ git status
# Not currently on any branch.
nothing to commit (working directory clean)

foo:/opt/bar$ git rebase --continue
Applying: Subscription logging added.
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".

foo:/opt/bar$

1
你尝试使用 --skip 跳过这个更改了吗?这可能只是修复一些已经在即将到来的提交中解决的尾随空格问题(简化为无操作)。 - guido
1
在执行合并操作后,app/config/config.yml 可能没有被更改。因此,您应该简单地使用 --skip 跳过此提交。 - user3159253
@LajosVeres,无需合并文件 <<< git mergetool - Roman Newaza
注意:确保使用Git 2.0.2+(2014年7月)以确保git rebase --skip正常工作。请参见我的答案 - VonC
dup: https://dev59.com/mWYq5IYBdhLWcg3whRDV - Brent Bradburn
4个回答

46

你走在正确的道路上。你只需要跳过出现问题的提交:

git rebase --skip

你已经解决了冲突,但是相比于之前的提交,没有任何变化。在这种情况下,你不能简单地使用git rebase --continue,因为这会告诉Git创建一个空提交,这是不允许的。

如果你对其他的提交有冲突,你仍然应该使用 git rebase --continue

--skip 选项也很有用,当你不想在新产生的历史中包含某个提交时可以使用它。


2
这是正确的答案,但我要注意的是,前几次遇到这种情况时,使用git rebase --skip总是让人感到害怕:我真的确定跳过这个提交没问题吗?另外,一个副注:从技术上讲,空提交是可能的,只需要使用--allow-empty,而git rebase没有提供。 - torek
@Torek,如果rebase不支持--allow-empty选项,那么你该如何使用它? - Roman Newaza
3
如果Git的开发者能够改善这种特定情况下的提示信息,以帮助其他人理解该如何操作,那将是很好的。 - Roman Newaza
1
@RomanNewaza:这仅在常规的git commit中可用。如果您真的想要,可以手动创建一个空提交,然后跳过rebase无法添加的空提交。但是,那么您需要有一些理由来创建/保留空提交,在rebase期间,我不确定那会是什么。 - torek
@torek,我不会做的 :) - Roman Newaza

7

git rebase --skip是正确的解决方案,但有一种情况会导致其无法继续当前的rebase。

Git 2.0.2(2014年7月)已经修复了这个bug:请参见提交95104c7brian m. carlson (bk2204)

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

如果git rebase --merge遇到冲突,如果下一个提交也发生冲突,--skip将无法工作
msgnum文件将永远不会更新为新的补丁号,因此实际上不会跳过任何补丁,导致无法逃脱的循环。
在call_merge中首先更新msgnum文件的值。
这也避免了跳过提交时出现“已应用”的消息。
对于调用call_merge的其他上下文,看不到任何可见的更改,因为在这些情况下,msgnum文件的值保持不变。

2
这篇文章帮助我解决了一个类似的问题,但是原作者并没有提出问题。我知道从命令中可以清楚地看出发生了什么,但对于某些专业知识不太充分的人可能不太明显(我差点就没看),所以:

当你需要变基(rebase)你的远程分支(假设为myBranch),因为你几天前已经推送过,并且其他开发人员在此之后合并了新变更,所以在你合并到主干或目标分支之前,你必须先变基。Gitlab会提示:

"不可能快进式合并。您必须先在本地变基。"

通常只需要:

git checkout master

git pull

git checkout myBranch

git rebase master

<修复问题,然后 git add .>

git rebase --continue

但在这种特殊情况下,git会告诉你没有进行任何更改,并询问你是否忘记了“git add”。因为你没有进行任何新的提交,你在myBranch中所做的更改已经被提交到其他地方,你希望复制你的旧提交,这就是使用git rebase --skip的地方。

希望这能帮助像我一样的人,如果他们遇到这个问题,并且已经绝望到看到了底部!


0

Git 提示您解决的冲突在未来的提交中已更改,当前情况下没有更改。 现在 Git 不允许您继续变基,因为它无法创建空提交。

如果您现在执行 git rebase --skip,那么在下一个更改该文件的提交中将再次显示相同的冲突。

为了避免这种情况,您可以手动提交使用: git commit --allow-empty 然后执行 git rebase --skip

这将防止不断解决相同的冲突。


如果我们执行git合并怎么办?既然我们已经解决了冲突。 - Ebram

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