Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase failing

I'm trying to rebase the work of a colleague.

First, I get a ton of conflicts where <<<<< head seams to contain the new code.

Then after a while I get the following error:

fatal: update_ref failed for ref 'refs/heads/dev_504':  cannot lock ref     'refs/heads/dev_504': ref refs/heads/dev_504 is at  XXXXXXX   but expected     XXXXXXXX Could not move back to refs/heads/dev_504 

Then if I try to continue anyway I get the following error:

fatal: cannot resume: .git/rebase-apply/final-commit does not exist. 

How can I fix this so the rebase won't give an error?

like image 574
Bunker Avatar asked Jan 09 '16 15:01

Bunker


People also ask

Can git rebase fail?

In particular, failure to apply a patch during a git rebase is a common problem that can be very destabilizing for the inexperienced user.

What is the main issue with git rebase?

The golden rule of git rebase is to never use it on public branches. The rebase moves all of the commits in main onto the tip of feature . The problem is that this only happened in your repository. All of the other developers are still working with the original main .


2 Answers

  • You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called.

  • You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option.

  • You can fix the conflict.

  • Failing that, you should re-create your branch or you can be able to remove the .git/rebase-merge directory, which contains the rebase state.

like image 60
Slim KTARI Avatar answered Sep 22 '22 14:09

Slim KTARI


Apparently the branch onto which you want to rebase, was also rebased between the time you branched off, maybe cleaning history up or rebasing on yet another branch. If so, you need to:

  • abort, current mess:git rebase --abort
  • to be current: git fetch
  • now the interesting part:

    git rebase --onto BUDDY_BRANCH YOUR_BRANCH~ YOUR_BRANCH

e.g. you branched of your local master (checkout of origin/master), a new branch test_branch (which you now want to update with current origin/master)

git rebase --onto master test_branch~ test_branch 

What this does is in simple terms, it takes your branches initial parent commit, finds it's counterpart in current master and rebases based on that.

like image 26
Alim Özdemir Avatar answered Sep 20 '22 14:09

Alim Özdemir