44

I am part way through a git rebase and I am stuck. I can't remember exactly what happened but I was using a UI and deleted a checked-out branch and things just seemed to go blank. I restarted and managed to do a bit of other work creating and committing to other branches etc but then I noticed a status saying I was still in the middle of a rebase

If I try

git rebase --skip
git rebase --continue
git rebase --abort

each fail with

error: could not read '.git/rebase-merge/head-name': No such file or directory

Is there a way I can get back to a stable state? I'm really not bothered about what the rebase related to so am not trying to get back to point where I am still in the middle of the rebase.

Edit:

$ git status
On branch fix/SJW-01225
Your branch is up to date with 'core-v3/fix/SJW-01225'.

You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")

Untracked files:
(use "git add <file>..." to include in what will be committed)

     [long list of untracked files]

nothing added to commit but untracked files present (use "git add" to track)

Edit-1:

$ touch .git/rebase-merge/head-name

$ git rebase --abort
error: could not read '.git/rebase-merge/onto': No such file or directory

$ touch .git/rebase-merge/onto

$ git rebase --abort
error: could not get 'onto': ''

Thx

6
  • Could you paste what git return when you type git status ?
    – dunajski
    Mar 7, 2019 at 14:13
  • Try to create the file: touch .git/rebase-merge/head-name.
    – Maroun
    Mar 7, 2019 at 14:22
  • TVM. Edited again following your suggestion Mar 7, 2019 at 14:25
  • 1
    Is this a learning experiment? Perhaps it's git clone time? Mar 7, 2019 at 14:28
  • 8
    xkcd.com/1597
    – user330315
    Mar 7, 2019 at 14:38

5 Answers 5

60

To escape from corrupted git rebase you can do the following

  1. Reset to a known state. You can find out from which commit you started your rebase with git reflog.

For example, reflog will give you the following. The rebase starting point is the last rebase (start) or rebase -i (start) if you did an interactive rebase. Here it is HEAD@{1}:

$ git reflog
f10ccfed (HEAD) HEAD@{0}: rebase : fast-forward
383aa038 (origin/master, origin/HEAD) HEAD@{1}: rebase (start): checkout HEAD~10
0600cf7e (origin/Files, master, Files) HEAD@{4}: checkout: moving from master to Files
0600cf7e (origin/Files, master, Files) HEAD@{5}: commit: fixes
f10ccfed (HEAD) HEAD@{6}: commit: refactoring

So what you need is:

git checkout master # assuming you were on master
git reset --hard HEAD@{1}
  1. Remove the rebase-merge folder
rm -rf .git/rebase-merge
2
  • 3
    In Windows, I needed to quote the commit. git reset --hard "HEAD@{1}"
    – PackBjamin
    Dec 17, 2021 at 21:10
  • In mycase, it cannot find rebase-merge folder. After resetting Head, I ran rebase --abort and it is fine.
    – KYLO
    Jul 27 at 21:29
21

I somehow got my repo into the same state. In my case, there was no .git/rebase-merge directory, but I did find a rebase-apply directory. Other than the in-progress rebase, git status was clean, so the only thing I needed to do to get out of the weird bad rebase state was to run:

rm -rf .git/rebase-apply/
16

git rebase --quit worked for me.

1
  • Take note of the difference between --abort and --quit: stackoverflow.com/q/55431768/2745495. Using --quit does not move the HEAD back, and the original question was: "Is there a way I can get back to a stable state?" Jun 9, 2022 at 9:19
1

I was in a similar problem:

$ git status
On branch master
You are currently rebasing.
  (all conflicts fixed: run "git rebase --continue")
nothing to commit, working tree clean
$ git rebase --abort
error: could not read '.git/rebase-merge/head-name': No such file or directory
$ git rebase --skip
error: could not read '.git/rebase-merge/head-name': No such file or directory
$ git rebase --continue
error: could not read '.git/rebase-merge/head-name': No such file or directory

So then I tried initiating a new rebase, and I got this clue (first time I've seen Git refer to itself in the first person, by the way):

$ git rebase -i HEAD~1
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.
$ rm -fr ".git/rebase-merge"
$ git status
On branch master
nothing to commit, working tree clean
$ git push origin master
Everything up-to-date

So in my case, the problem was solved by forcefully and recursively removing Git's rebase-merge directory via rm -fr ".git/rebase-merge".

1

Encountered a similar issue where --abort did not work

$ git rebase master
error: could not write index
fatal: Could not detach HEAD
First, rewinding head to replay your work on top of it...

and could not find anything wrong with the repo using

$ git status
On branch XXX
nothing to commit, working tree clean
$ ls .git/r*
#Nothing of interest

In the I fixed it by cleaning, i.e. issuing the following (very destructive if you have uncomitted changes) command

git clean -xfd

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.