I was going to do a rebase to delete my last commit but I didn't want to finish so I exited. (I realize this probably was not the best way to go about it, but it's done) I guess I did it wrong because I am getting the error: fatal: Could not open file .git/rebase-merge/done for reading: No such file or directory
every time I run git status
. How do I get rid of this error so I can continue making commits? Can I just delete the file? If I can delete it, how would I do that?
6 Answers
Before you try the following, make sure you stash
or commit
any uncommitted changes first, or you will lose them irrevocably.
Then try to do a git rebase --abort
.
-
11WARNING: if you have any uncommitted changes, this may remove them irrevocably :( I booted up this morning, did some work, tried to commit and got this error; googled and found this answer; tried it; and my last hour of work has vanished for good.– slinkpDec 9, 2016 at 15:57
-
1
-
Just trying to prevent others making the same mistake that I did! :-)– BliscoFeb 11, 2017 at 16:05
-
5
-
git rebase --abort
gives the same error, I fixed it by adding the files that it was complaining about, see @Stefano's answer below.– CWSitesJan 28, 2020 at 20:28
Stash or commit didn't work for me, I just created the files that git was complaining about until it worked!
$ git rebase --abort
error: could not read '.git/rebase-apply/head-name': No such file or directory
echo "master" > .git/rebase-apply/head-name
$ git rebase --abort
error: could not read '.git/rebase-apply/onto': No such file or directory
$ echo "develop" > .git/rebase-apply/onto
$ git rebase --abort
error: could not read '.git/rebase-apply/head': No such file or directory
$ echo "develop" > .git/rebase-apply/head
After which git rebase --abort
worked. The branch names you are putting in those files needs to exists, and in my case I didn't care about my local changes, but obviously be careful with this if you do.
-
You save my nervousness :) Do you know what branch I should write when I rebased
"master"
onto"origin/master"
? I have replaced "developer" with "origin/master" andgit rebase --abort
worked.– marbel82Oct 2, 2019 at 7:59 -
@marbel82 I guess it doesn't matter because that's only for git to store the state of the marge. When you eventually abort it you can start again!– StefanoOct 3, 2019 at 20:27
-
For me, just
git reset --hard HEAD
worked fine to restore the state (warning - make sure to save all your changes before doing that).– Dan M.Dec 2, 2019 at 12:49
DavidN's solution to abort the rebase is great as long as you don't have any unstaged changes since the last rebase going south!
If you wrote code after the rebase attempt, ignoring the could not open file .git/rebase-merge/done
message,
then your best bet is to do
git stash
to save your local changes and only then abort the rebase.
I am sure this is one of those stackoverflow questions, where people who are eager to solve their problem without considering the implications, will just run the abort command and regret it soon after.
I've just done:
git add .
git commit -m "change inter rebase"
and then could continue:
git rebase --continue
No
git stash
git rebase --abort
needed.
-
-
Not sure why git complained about author script, but it really was just an issue of committing for me. Not sure why this solution isn't higher.– CatskulOct 17 at 15:52
For some one doing this from within Visual Studio Code, close the running terminal/shell and then run git rebase --quit
Doing this will solve the issue.
The error message should be clearer now:
error: you have staged changes in your working tree
(Hence add+commit, or stash)
Git 2.43 (Q4 2023) fixes the behaviour of "rebase -i
" when the command got interrupted by conflicting changes.
See commit 203573b, commit 405509c, commit e032abd, commit f2b5f41, commit 9f67899, commit 206a78d, commit 36ac861 (06 Sep 2023) by Phillip Wood (phillipwood
).
(Merged by Junio C Hamano -- gitster
-- in commit b995e78, 14 Sep 2023)
rebase --continue
: refuse to commit after failed commandSigned-off-by: Phillip Wood
If a commit cannot be picked because it would overwrite an untracked file then "
git rebase --continue
"(man) should refuse to commit any staged changes as the commit was not picked.
This is implemented by refusing to commit if the message file is missing.
The message file is chosen for this check because it is only written when "git rebase
"(man) stops for the user to resolve merge conflicts.Existing commands that refuse to commit staged changes when continuing such as a failed "exec" rely on checking for the absence of the author script in
run_git_commit()
.
This prevents the staged changes from being committed but printserror: could not open '.git/rebase-merge/author-script' for reading
before the message about not being able to commit.
This is confusing to users and so checking for the message file instead improves the user experience.
The existing test for refusing to commit after a failed exec is updated to check that we do not print the error message about a missing author script anymore.
git rm .git/rebase-merge/done
and that did not work