So I'm working on a project with other people, and there's multiple github forks being worked on. Someone just made a fix for a problem and I merged with his fork, but then I realized that I could find a better solution. I want to revert the commit I just made. I tried doing this with
git revert HEAD but it gave me this error:
fatal: Commit <SHA1> is a merge but no -m option was given.
What does that mean? When I merged and committed, I did use the -m option to say "Merged with <username>".
What am I doing wrong here?
git revert refuses to revert a merge commit as what that actually means is ambiguous. I presume that your
HEAD is in fact a merge commit.
If you want to revert the merge commit, you have to specify which parent of the merge you want to consider to be the main trunk, i.e. what you want to revert to.
Often this will be parent number one, for example if you were on
master and did
git merge unwanted and then decided to revert the merge of
unwanted. The first parent would be your pre-merge
master branch and the second parent would be the tip of
In this case you could do:
git revert -m 1 HEAD
git cat-file -p [MERGE_COMMIT_ID] will show the parent branches in order. The first one listed would be -m 1, the second -m 2.