Git rebase failing

31,583

Solution 1

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

Solution 2

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.

Share:
31,583
Bunker
Author by

Bunker

Updated on September 08, 2020

Comments

  • Bunker
    Bunker over 3 years

    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?

  • quiram
    quiram about 5 years
    I'm not sure the third point (fix the conflict) applies. OP has already fixed the conflict, the error message appears after running git rebase --continue
  • Simmetric
    Simmetric about 5 years
    This is the real answer! To rebase your local master branch onto origin/master, enter git rebase --onto origin/master master~ master
  • user7610
    user7610 almost 4 years
    ` % git rebase --skip :( git: builtin/am.c:1981: am_skip: Assertion !is_null_oid(&state->orig_commit)' failed. error: am died of signal 6