62

OK, so I'm getting an error sometimes when I try to revert a commit (with Git). All that I do is

git revert <commit hash>

and it gives me this message:

error: could not revert <commit hash> <commit message>
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'

Does this mean that I should use git mergetool and resolve any conflicts? Once I do this can I add/rm and then commit, and the revert is complete?

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
icnhzabot
  • 9,801
  • 5
  • 21
  • 9
  • 1
    The conflicts should appear in your code files, right? So thats where you should sort that out. When done make sure to commit whats right. – Eric Herlitz May 21 '11 at 21:21

2 Answers2

35

Yes you will have to resolve the conflicts, mark them as so with git add or git rm and git commit

The commit is not done yet, after the git revert - if you see .git/MERGE_MSG, you will see something like:

Revert "adding revert"

This reverts commit c1366607f15a8384434948cb0bcbf8ece48bb460.

Conflicts:

revert

So once you resolved the merge and do a git commit you will be presented with the message from the MERGE_MSG file and you can commit and that completes the revert.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • OK, thank you! Just wonderin' to make sure I was doing the correct thing :) – icnhzabot May 21 '11 at 21:35
  • And what do I do if I realise that revert was not needed at all? How to "clear" the working directory? – przemo_li Apr 26 '16 at 12:48
  • 1
    @przemo_li: Enter `git status` and it will give you a suggestion: `(use "git revert --abort" to cancel the revert operation)` – avandeursen Apr 22 '17 at 10:23
  • Use can use `git revert --continue` to complete the operation after you fix all conflicts. – Vladimir Reshetnikov Nov 06 '17 at 21:39
  • Unfortunelly I cant do `git revert`. I am getting errors all the time like: "The following untracked working tree files would be overwritten by merge:". I can't even use `force`. I really have to manually delete theese files? – dafie Oct 02 '18 at 11:30
7

You can use git reset --hard, if you want to delete all the conflicts and remove the revert you have done for which the abort error arise.

ARKhan
  • 1,724
  • 22
  • 30