398

I managed to create a little mess in my local git repository. I was trying to fix a broken commit by using the following instructions. Before running the "git commit --amend" (and after the git rebase --interactive) I decided that my changes were incorrect and so I executed "git reset HEAD --hard". Not a good idea, I tell you.

Now the interactive rebase seems to be "stuck". Git shows the current branch as (|REBASE-m). Every command (cd .., ls, git rebase...) inside my repository gives the following error:

cat: .git/rebase-merge/head-name: No such file or directory

Here's how git rebase --abort looks like:

$ git rebase --abort
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/head-name: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/orig-head: No such file or directory
HEAD is now at 4c737fb Revert "Modified file names"
rm: cannot remove `c:/_work/project/src/git/.git/rebase-merge/done': Permission denied
rm: cannot remove directory `c:/_work/project/src/git/.git/rebase-merge': Directory
not empty
cat: .git/rebase-merge/head-name: No such file or directory

Here's the result of git rebase --continue:

$ git rebase --continue
cat: c:/_work/project/src/git/.git/rebase-merge/prev_head: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/end: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/msgnum: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/onto: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
prev_head must be defined
cat: .git/rebase-merge/head-name: No such file or directory

Any ideas? I would like to reset the situation back to the state it was before I started my well-thought rebase operation.

Here's how git log --oneline shows the situation:

4c737fb Revert "Modified file names"
247ac02 Modified file names
33141e6 Message modifications
10a4a04 Modified db script

And this is fine.

I'm using msysgit v1.7.0.2.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
Mikael Koskinen
  • 12,306
  • 5
  • 48
  • 63

20 Answers20

747

I got stuck in this. I created the head-name file, and then I ran into another error saying it couldn't find the onto file, so I created that file. Then I got another error saying could not read '.git/rebase-apply/onto': No such file or directory.

So I looked at the git documentation for rebasing and found another command:

git rebase --quit

This set me back on my branch with no changes, and I could start my rebase over again, good as new.

alexwho314
  • 29
  • 2
  • 9
Laura Slocum
  • 7,696
  • 2
  • 11
  • 9
  • 49
    `--quit` worked. `--abort` didn't because the rebase was cancelled half way through – Kalob Taulien Sep 27 '19 at 21:51
  • 6
    I had similar rebase-related error, just with different error message. Tried: `$ git rebase --abort` Output: `error: could not read '.git/rebase-apply/head-name': No such file or directory` Finally, this solution fixes my problem: `git rebase --quit` – aff Nov 14 '19 at 06:24
  • 3
    Upvoted. `git rebase --quit` absolutely saved me. Same symptoms as described, but mine came after trying to do a `git pull --rebase`, which for some reason failed. Note I had autostash enabled (git version 2.27.0.windows.1) and had VS2019 running (pointed at that repo) at the same time - suspect some combination of these messed it up. – ErrCode Jun 10 '20 at 04:11
  • I was worried I'd have to re-do all the rebasing work after `git rebase --quit`, so I backed up the whole tree first, but after quiting and starting the rebase again, there were no conflicts to resolve! I might have been helped by my "rerere" configuration set up before the rebase started. https://git-scm.com/book/en/v2/Git-Tools-Rerere – Mark Stosberg Apr 20 '22 at 16:35
  • As said in comments of the accepted answer, `git rebase --quit` will wipe the `.git/rebase-merge` folder, **including autostash**. If you had an autostash (with `git rebase --autostash`), make sure to save its commit hash (found in `.git/rebase-merge/autostash`) before running this command so you can easily reapply it afterwards with `git stash apply `. – kagmole Jul 07 '22 at 07:32
216

It looks like Git tried to remove the .git/rebase-merge directory but wasn't able to remove it completely. Have you tried copying that folder away? Also copy away the .git/rebase-apply folder if that is present.

Martin Owen
  • 5,221
  • 3
  • 35
  • 31
  • 7
    Thanks for pointing that out. I was able to fix my problem just by restarting the computer. I'm not sure what went wrong because somehow every access to the .git\rebase-merge folder caused an "Access denied" -error. – Mikael Koskinen Sep 13 '10 at 05:07
  • 28
    Reboot did not work for me but `git rebase --abort` (from http://stackoverflow.com/a/4757777/146044) _did_ work. – backus Mar 28 '16 at 02:24
  • 6
    a word of warning... i had 4 hours worth of changes on my working directory when i noticed the corrupted rebase error. tried the `git rebase --abort` it wiped my unstaged changes... the error did disappear though – George Ananda Eman Sep 26 '16 at 12:22
  • Removing REBASE_HEAD, rebase-apply/ and rebased-patches in .git worked for me – MyrionSC2 Apr 02 '20 at 09:04
  • 8
    `git rebase --quit` worked for me but I lost all autostashed changes like @GeorgeAnandaEman => it is possible to recover them though by using the answer in https://stackoverflow.com/questions/37845799/how-do-you-get-a-lost-autostash-commit-from-git-rebase-autostash explaining how to see all autostash commits – tiho Jul 15 '20 at 20:25
  • For IntelliJ users: Git > Rebase... > Abort Rebase. – Trayan Momkov Feb 17 '21 at 09:14
  • yeah, I deleted .git/rebase-merge and the rebase was fully gone. Easy fix. I was using Merge , by sublime-text. I hate that app, im done with it – Norman Bird Dec 28 '22 at 20:33
94

I had a similar problem due to a zombie vim.exe process. Killing it in Task Manager, followed by a git rebase --abort fixed it.

user584317
  • 957
  • 7
  • 3
  • this was my problem too. I used sysinternals `handle` command and saw that a process (sh.exe) had the file locked. Using `pskill ` fixed it for me. – Paul Oliver Aug 17 '15 at 23:07
  • i tried git rebase --abort but got an error error: could not read '.git/rebase-apply/head-name': No such file or directory; git rebase --quit worked – Andrei Diaconescu Nov 01 '21 at 10:22
40

Thanks @Laura Slocum for your answer

I messed things up while rebasing and got a detached HEAD with an

 error: could not read orig-head

that prevented me from finishing the rebasing.

The detached HEAD seem to contain precisely my correct rebase desired state, so I ran

rebase --quit

and after that I checked out a new temp branch to bind it to the detached head.

By comparing it with the branch I wanted to rebase, I can see the new temp branch is exactly in the state I wanted to reach. Thanks

Ruth
  • 546
  • 1
  • 6
  • 12
7

Had same problem in Eclipse. Could not Rebase=>abort from Eclipse.

Executing git rebase --abort from Git Bash Worked for me.

Praveen Hiremath
  • 4,209
  • 2
  • 17
  • 11
7

On Windows, if you are unwilling or unable to restart the machine see below.

Install Process Explorer: https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

In Process Explorer, Find > File Handle or DLL ...

Type in the file name mentioned in the error (for my error it was 'git-rebase-todo' but in the question above, 'done').

Process Explorer will highlight the process holding a lock on the file (for me it was 'grep').

Kill the process and you will be able to abort the git action in the standard way.

Darren Yeats
  • 101
  • 1
  • 3
6

Create a file with this name:

touch .git/rebase-merge/head-name

and than use git rebase

Ethaan
  • 11,291
  • 5
  • 35
  • 45
Tehila Dabush
  • 61
  • 1
  • 3
6

In my case eighter git rebase --abort and git rebase --continue was throwing:

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

I managed to fix this issue by manually removing: .git\rebase-apply directory.

Dariusz
  • 15,573
  • 9
  • 52
  • 68
3

I'm using git version 2.19.2.windows.1.

the only thing that worked for me was to remove the .git/rebase-apply/ directory and do a git reset --hard.

Spongman
  • 9,665
  • 8
  • 39
  • 58
3

I have tried all the above steps mentioned but nothing worked for me. Finally, restarting the computer worked for this issue :D

Mohammed Asif
  • 41
  • 1
  • 5
2

With SublimeText 3 on Windows, the problem is fixed by just closing the Sublime windows used for interactive commit edition.

LeBorgne
  • 103
  • 9
2

If you get below state and rebase does not work anymore,

$ git status
rebase in progress; onto (null)
You are currently rebasing.
  (all conflicts fixed: run "git rebase --continue")

Then first run,

$ git rebase -quit

And then restore previous state from reflog,

$ git reflog
97f7c6f (HEAD, origin/master, origin/HEAD) HEAD@{0}: pull --rebase: checkout 97f7c6f292d995b2925c2ea036bb4823a856e1aa
4035795 (master) HEAD@{1}: commit (amend): Adding 2nd commit
d16be84 HEAD@{2}: commit (amend): Adding 2nd commit
8577ca8 HEAD@{3}: commit: Adding 2nd commit
3d2088d HEAD@{4}: reset: moving to head~
52eec4a HEAD@{5}: commit: Adding initial commit

Using,

$ git checkout HEAD@{1} #or
$ git checkout master #or
$ git checkout 4035795 #or
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
1

In my case it was because I had opened SmartGit's Log in the respective Git project and Total Commander in the respective project directory. When I closed both I was able to rebase without any problem.

The more I think about it, the more I suspect Total Commander, i.e. Windows having a lock on opened directory the git rebase was trying to something with.

Friendly advice: When you try to fix something, always do one change at a time. ;)

meridius
  • 1,495
  • 1
  • 18
  • 26
0

Once you have satisfactorily completed rebasing X number of commits , the last command must be git rebase --continue . That completes the process and exits out of the rebase mode .

Karel Bílek
  • 36,467
  • 31
  • 94
  • 149
diptia
  • 2,135
  • 21
  • 21
0

I had the same problem. I used process explorer as suggested in other post (i am not able to find that post) and figured out which process has a lock on the file and kill it. then execute the --continue or --abort as per needs

user3739537
  • 63
  • 2
  • 7
0

In my case after testing all this options and still having issues i tried sudo git rebase --abort and it did the whole thing

Dani.Rangelov
  • 366
  • 2
  • 5
0

tried everything else but a reboot, what worked for me is rm -fr .git/REBASE_HEAD

0

I had a commit running in my VSCode that made it stuck. killed the VS Code process and did recover (R) to the rebase. Fixed it for me.

Orit
  • 314
  • 2
  • 6
0

I was missing the "author-script" because it was already used in the last commit I did (on accident). I undid that last commit, and committed everything in one. (I'm using git-branchless fwiw)

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72
-3

I am using git in eclipse and I was having the same problem.

Eventually I found that the "Rebase ..." menu entry was temporarily transformed into a sub-menu.

Team-> Rebase -> Abort

It worked for me.

Shiva Agrawal
  • 161
  • 2
  • 9