Git rebase在解决合并冲突后卡住了

10
我正在运行一个rebase操作,出现了冲突:
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Better `SelectMotifsView.js`
Using index info to reconstruct a base tree...
M       browser/AddLinkView.js
M       browser/SelectMotifsView.js
M       browser/index.html
Falling back to patching base and 3-way merge...
Auto-merging browser/index.html
CONFLICT (content): Merge conflict in browser/index.html
Failed to merge in the changes.
Patch failed at 0001 Better `SelectMotifsView.js`
The copy of the patch that failed is found in:
   /Users/dmitry/dev/links/.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".

没问题-我做了一个小改动,我知道会引起冲突:
diff --cc browser/index.html
index ba9c4f3,4c2a1c2..0000000
--- a/browser/index.html
+++ b/browser/index.html
@@@ -40,6 -40,7 +40,10 @@@
              <label>
                  <%= label %>
                  <select class="form-control" name="motif">
++<<<<<<< HEAD
++=======
+                     <% console.log(exclude); %>
++>>>>>>> Better `SelectMotifsView.js`
                      <% motifs.each(function(motif) { if (!exclude || exclude.indexOf(motif) < 0) { %>
                          <option value="<%= motif.get('id') %>"><%= motif.get('name') %></option>
                      <% } }); %>

我想保留空的HEAD版本,因此我只需删除整个内容:

++<<<<<<< HEAD
++=======
+                     <% console.log(exclude); %>
++>>>>>>> Better `SelectMotifsView.js` 

我保存文件,browser/index.html,然后执行 git add browser/index.html 命令:

$ git add browser/index.html
$ git rebase --continue

但是:

Applying: Better `SelectMotifsView.js`
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 prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

我从未见过这种情况... git status显示没有剩余的未解决路径。该怎么办?我在其他相关问题上读到,这可能是使用--skip的好方法,但这似乎不是一个空提交。或者我错了吗?


有点令人困惑的是三个 M 状态文件。如果只有一个冲突,并选择保持文件不变,则应该有另外两个更改的文件。但也许那些文件最终被自动解决为“无更改”了吗?(从上面看不太清楚。) - torek
它问你:“没有更改-你忘记使用'git add'了吗?” 那是什么答案? - jshawl
@jessh:是的,你可以在我的问题中看到:我在冲突的文件上使用了git add。没有其他未解决的路径。 - Dmitry Minkovsky
@torek:是的,这些在变基路径上被修改了,但它们没有遇到冲突,所以它们被自动合并了。我把所有的输出都粘贴了出来……这样你就知道我知道的一切了。 - Dmitry Minkovsky
我从未见过 git rebase 对实际修改了内容的提交报告此类消息,所以建议尝试使用 --skip - Fred Foo
似乎自动合并结果为“与此补丁无异”。这意味着由于手动合并的结果也是“与此补丁无异”,所以该补丁最终为空,可以省略。(如果您仍想保留它,请使用 --allow-empty 手动提交,或尝试使用 --keep-empty,尽管源代码建议后者在此时不起作用。) - torek
2个回答

15

看起来这个补丁是空的,所以你可以像 git 建议的那样安全地跳过它:

$ git rebase --skip

这立刻解决了它。 - OGHaza

5
一个导致 git rebase 在“rebase loop”中卡住的可能原因是 git gc
这个问题在 git 2.7.1 (2016年2月6日) 中得到了修复。
请参见由 Jeff King (peff) 于 2016年1月13日提交的提交记录 8c24f5b(由 Junio C Hamano -- gitster -- 于 2016年1月26日合并至 提交记录 eefc461)

rebase: 忽略 "gc --auto" 的失败

在变基后,如果我们创建了许多松散的对象,则会调用 "gc --auto" 进行清理。但是,我们在 &&-chain 内部执行此操作。如果 "gc --auto" 失败(例如,因为之前的后台 gc 通过保留 "gc.log" 阻止了我们),则:

  1. 我们将无法清理状态目录,使用户永远卡在变基中(即使 "git am --abort" 也不起作用,因为它会调用 "gc --auto"!)。
  2. 在某些情况下,我们可能会从变基返回虚假的退出代码,表示除自动 gc 以外的所有操作都成功。

我们可以通过忽略 "gc --auto" 的退出代码来解决这个问题。

所以解决方法就是删除 gc.log
rm .git/gc.log

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