Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase gets stuck after resolving merge conflict

Tags:

git

I'm running a rebase that hits a conflict:

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

No biggie—I had made a small change that I knew would cause a conflict:

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>
                      <% } }); %>

I want to keep the version from HEAD, which is empty, so I go in and just remove the whole:

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

I save the file, browser/index.html, then git add browser/index.html:

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

But then:

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

Never seen this before... git status shows no remaining unresolved paths. What to do? I read on other related questions that this may be a good use of --skip, but this doesn't seem to be a null commit. Or am I wrong?

like image 419
Dmitry Minkovsky Avatar asked Feb 17 '14 15:02

Dmitry Minkovsky


People also ask

Does rebase avoid merge conflicts?

Rebasing is not going to magically remove all merge conflicts. In fact, you may encounter conflicts while rebasing. Sometimes, you will have to repeatedly resolve the same conflict while rebasing. However, merge conflicts happen because multiple changes happen to the same chunk of code simultaneously.

Why is git rebase taking so long?

What 'git rebase' does is take all your commits out until it finds a common parent and then apply upstream changes(The branch that you are merging) first and then apply the changes you have in your current branch. This process takes a long time. You have to fix the conflicts each time after fixing the conflicts.


2 Answers

Looks like the patch is empty, so you can safely skip it as git suggests:

$ git rebase --skip
like image 107
Agis Avatar answered Oct 18 '22 20:10

Agis


One possible cause of a git rebase being stuck in a "rebase loop" is git gc.
This is fixed in git 2.7.1 (February 6th, 2016)

See commit 8c24f5b (13 Jan 2016) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit eefc461, 26 Jan 2016)

rebase: ignore failures from "gc --auto"

After rebasing, we call "gc --auto" to clean up if we created a lot of loose objects. However, we do so inside an &&-chain. If "gc --auto" fails (e.g., because a previous background gc blocked us by leaving "gc.log" in place), then:

  1. We will fail to clean up the state directory, leaving the user stuck in the rebase forever (even "git am --abort" doesn't work, because it calls "gc --auto"!).
  2. In some cases, we may return a bogus exit code from rebase, indicating failure when everything except the auto-gc succeeded.

We can fix this by ignoring the exit code of "gc --auto".

So to fix you just need to remove gc.log:

rm .git/gc.log
like image 23
VonC Avatar answered Oct 18 '22 20:10

VonC