10

I'm having a serious problem trying to do git rebase --interactive on my repo. I get the cryptic error fatal: ref HEAD is not a symbolic ref, and my rebase ceases to function. I must git rebase --abort to get back to a good state.

Here are the output(s) I receive: https://gist.github.com/d38f1e2d2ec9bc480b6f

What I've been told in the past is that this is due to the fact that I'm in "detached HEAD" mode, but how would I have gotten into the rebase in the first place if I was in that mode? I'm most certainly starting in master, then running git rebase --interactive and modifying the git-rebase-todo text file to what I want. And then this error happens.

I've asked everyone here at work, and some people @ #git on freenode. No one seems to truly understand my problem or know what the solution is. Googling for that error produced nothing, relevant searches on StackOverflow have proven nothing. I can't seem to figure this out, and it's really lame going from squashing every commit I push to master to now pushing every little change I make as its own separate commit.

tubbo
  • 598
  • 10
  • 21
  • A succezsfull rebase -i is described here: http://davidstechtips.com/2011/03/collapsing-commits-in-git/. In your case, try `git checkout master `, like `8bbfbba` maybe? Or you didn't do a `git rebase --continue`after a conflict? – VonC May 08 '12 at 00:29
  • 1
    It could be that you are still inside a previous rebase which detaches the head during its re-processing. This can happen easily during a big rebase in the heat of fixing the current interactive step and you could have got distracted. I've just been working through a rebase where I had a lot of work (many small steps) to do, but ended up doing a separate `rebase -i` for each and every step just so I didn't get lost. Firing up the git-gui and gitk visualiser will help as well. [make sure you are starting on one of your own local branches] – Philip Oakley May 08 '12 at 08:20
  • You can establish whether you are actually in detached HEAD mode by looking at the contents of `.git/HEAD` If it contains text like "ref: refs/heads/..." you are _not_ in detached HEAD mode. If, on the other hand, it contains a SHA-ID (e.g. a jumbly string of letters and numbers) you are indeed in detached HEAD mode. – Daniel Kessler May 08 '12 at 16:37

2 Answers2

4

During a 'git rebase' the ref that you are rebasing off of is checked out. If that ref is a commit then you will get a detached head; if it is a branch reference then that branch is checked out. If during the course of a commit a FATAL occurs, then you are left with a working directory in a munged state. For example, if you were on branch Foo and you tried to rebase off of Bar, then after a FATAL you will be at Bar or somewhere after Bar with a few rebase commits applied. You recover by checking out Foo as simply.

git rebase --abort 

or, if the rebase is really wedged (see reference below), as:

git checkout -f Foo

After that, you can safely try the rebase again to try to debug why the FATAL occurs. Here is a case where rebase fails when running out of memory and 'git rebase --abort' doesn't work.

Community
  • 1
  • 1
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • 1
    Using `git checkout -f` doesn't solve my problem. I've been doing `git rebase --abort` to get out of the rebase every time. Here's what I get when I try `git checkout -f`: https://gist.github.com/4d3aa867602f1e438e9b – tubbo May 08 '12 at 20:11
  • This is due to my use of `git-tracker`. Sorry!! – tubbo May 08 '12 at 20:19
  • Using 'git rebase --abort' is the preferred approach; but it doesn't always work (see reference) – GoZoner May 08 '12 at 20:36
0

git rebase --abort didn't work for me. Though the rebase output provided the solution already:

fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

Namely after having run rm -fr ".git/rebase-merge, things went back to normal.

Mateja Petrovic
  • 3,799
  • 4
  • 25
  • 40