Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git revert <hash> not allowed due to a merge but no -m option was given

I am trying to revert to a certain 'hash' number in git, by using the 'revert' command.

I am using the following command:

git revert c14609d74eec3ccebafc73fa875ec58445471765 

But, I am getting the following returned:

error: Commit c14609d74eec3ccebafc73fa875ec58445471765 is a merge but no -m option was given.
fatal: revert failed

As a new git user, please can you explain what is happening & what I have to do to resolve this.

I want to revert back to this certain commit (c14609d74eec3ccebafc73fa875ec58445471765) that I see when running git log.

like image 675
user3544484 Avatar asked Jun 19 '14 07:06

user3544484


People also ask

How do I revert a merge in git?

In case you are using the Tower Git client, undoing a merge is really simple: just press CMD+Z afterwards and Tower will undo the merge for you!

How do I undo a merge not committed?

You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.

How do you undo a merge that has been pushed?

Now, if you have already pushed the merged changes you want to undo to your remote repository, you can right-click on the merge commit and select Revert commit from the context menu. You will then be asked if you want to immediately create a commit.


1 Answers

You are trying to revert a merge commit, and git doesn't know which parent to revert to. The -m allows us to choose which parent to choose. See the merge commit and note down which parent you want to go to. The parent information can be seen in git log, for example:

commit d02ee0f2179def10277f30c71c5d6f59ded3c595

Merge: dd3a24c 2462a52

and run:

git revert <hash> -m 1 

where 1 indicates parent number 1 (dd3a24c).

If you are trying to revert to that commit, do:

git reset --hard <hash> 

Understand the difference between git revert and git reset from the docs and decide which one you want. git revert is the safer option, but doesn't really do what you want. It just reverts the changes of a (set of) commit. git reset makes you move to a particular commit in history, and will rewrite your history.

like image 121
manojlds Avatar answered Sep 28 '22 05:09

manojlds