What should I do when git revert aborts with an error message?
Asked Answered
R

2

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?

Rubato answered 21/5, 2011 at 21:13 Comment(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.Tortola
C
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.

Couteau answered 21/5, 2011 at 21:24 Comment(5)
OK, thank you! Just wonderin' to make sure I was doing the correct thing :)Rubato
And what do I do if I realise that revert was not needed at all? How to "clear" the working directory?Swanee
@przemo_li: Enter git status and it will give you a suggestion: (use "git revert --abort" to cancel the revert operation)Kolo
Use can use git revert --continue to complete the operation after you fix all conflicts.Eighteenmo
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?Dipterous
H
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.

Historicism answered 1/8, 2018 at 6:32 Comment(1)
pretty sure git reset --mixed is a safer option.Amharic

© 2022 - 2024 — McMap. All rights reserved.