This question is already answered correctly, but I just want to address the first point of op's question -- I can't figure out how to finish this reverting. if you too were stuck in revert state like me and got here searching for an answer.
it can be straightforward as git revert --continue
. but only if you're reverting some changes inside a file. if you get stuck in revert state, that's most likely because you're trying to revert a commit that created a file and that file is modified in any of the subsequent commit.
take an example:
1c40cd3 added fileB
4e06828 added fileA
faf29dd (origin/main, origin/HEAD, main) Merged in feature5 (pull request #13)
6e735e3 (origin/feature5, feature5) updated file.txt
fb51fca added file.txt
744ba74 Initial commit
now, if you're trying to revert fb51fca (added file.txt)
, it will show you something like:
$ git revert fb51fca
CONFLICT (modify/delete): file.txt deleted in parent of fb51fca (added file.txt) and modified in HEAD. Version HEAD of file.txt left in tree.
error: could not revert fb51fca... added file.txt
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git revert --continue".
hint: You can instead skip this commit with "git revert --skip".
hint: To abort and get back to the state before "git revert",
hint: run "git revert --abort".
$ git status
On branch feature6
You are currently reverting commit fb51fca.
(fix conflicts and run "git revert --continue")
(use "git revert --skip" to skip this patch)
(use "git revert --abort" to cancel the revert operation)
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: file.txt
you can clearly see file.txt deleted in fb51fca (added file.txt) and modified in HEAD. Version HEAD of file.txt left in tree.
. now, you can do git add -A
and git commit ...
BUT
what revert does is goes back in history (in the specified commit), removes the changes that were done in that commit. and makes a new commit. but the issue is, you created a file, now revert is deleting it. in the end, there is no file left to stage and as you know, git doesn't allow empty directories or empty commits.
but there's a workaround for empty commits. as ryan suggested, you can do git commit -m "empty commit to escape revert" --allow-empty
. git revert probably doesn't use this --allow-empty
flag and that's probably the reason it can't do a commit gets stuck in revert state.
either way, if you get stuck in the revert state, you're probably doing something wrong. trying to revert something that doesn't make sense.
git revert --abort
worked for me. – Gordan