Search code examples
gitgit-revert

git revert raises a conflict and it is not fixed (constantly shows (master|reverting))


This question has been asked before but hasn't received a complete answer, so I ask it again.

When I tried to revert one of the commits in my git commit history, a conflict occurred, so I tried to fix that by manually editing the conflicted file. I saved the file (using vim) and came back to git bash. Then I tried to finalise the reverting process by adding and commiting the edited file. But still I see (master|reverting) in my prompt (user@123123 MINGW64 ~/Documents/library/Git/s1 (master|REVERTING)). I can get rid of (master|reverting) by using git revert --abort or git revert --skip (using these two commands ignore the whole reverting procedure) but when I use git revert --continue nothing happens. In this step, when I run git status, git shows me the following messages:

On branch master
You are currently reverting commit bbcf9a4.
  (all conflicts fixed: run "git revert --continue")
  (use "git revert --skip" to skip this patch)
  (use "git revert --abort" to cancel the revert operation)

nothing to commit, working tree clean

I am curious why this (master|reverting) appears in the first place and how I can finalise my reverting process.


Solution

  • I suspect that, after fixing your conflicts, you ended up with an empty stage and a clean work tree.

    In other words, you fixed your conflicts by editing back your files exactly how they were before the revert.

    Does git status gives you the following screen?

    On branch master
    You are currently reverting commit e768305.
      (all conflicts fixed: run "git revert --continue")
      (use "git revert --skip" to skip this patch)
      (use "git revert --abort" to cancel the revert operation)
    
    nothing to commit, working tree clean
    

    If that is the case, your stage is empty and your work tree is clean; using git commit on an empty stage does nothing, as well as using git revert --continue (since it does a commit behind the scenes).

    You may just skip your revert (with git revert --skip, since the stage is empty), or create an empty commit with git commit --allow-empty but it would be pretty pointless.


    To pragmatically stop Git from saying "REVERTING" (and stop being in a "reverting" state), delete the .git/REVERT_HEAD file.