In git revert -m, the -m option specifies the parent number. This is needed because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.
When you view a merge commit in the output of git log, you will see its parents listed on the line that begins with Merge: (the second line in this case):
commit 8f937c683929b08379097828c8a04350b9b8e183
Merge: 8989ee0 7c6b236
Author: Ben James <ben@example.com>
Date: Wed Aug 17 22:49:41 2011 +0100
Merge branch 'gh-pages'
Conflicts:
README
In this situation, git revert 8f937c6 -m 1 will get you the tree as it was in 8989ee0, and git revert 8f937c6 -m 2 will reinstate the tree as it was in 7c6b236.
To better understand what you're about to revert do git diff <parent_commit> <commit_to_revert>, in this case:
git diff 8989ee0 8f937c6
and
git diff 7c6b236 8f937c6
However, it's very important you realize that in doing so
Answer from Ben James on Stack Overflow"...declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want. See the revert-a-faulty-merge How-To for more details." (git-merge man page).
In git revert -m, the -m option specifies the parent number. This is needed because a merge commit has more than one parent, and Git does not know automatically which parent was the mainline, and which parent was the branch you want to un-merge.
When you view a merge commit in the output of git log, you will see its parents listed on the line that begins with Merge: (the second line in this case):
commit 8f937c683929b08379097828c8a04350b9b8e183
Merge: 8989ee0 7c6b236
Author: Ben James <ben@example.com>
Date: Wed Aug 17 22:49:41 2011 +0100
Merge branch 'gh-pages'
Conflicts:
README
In this situation, git revert 8f937c6 -m 1 will get you the tree as it was in 8989ee0, and git revert 8f937c6 -m 2 will reinstate the tree as it was in 7c6b236.
To better understand what you're about to revert do git diff <parent_commit> <commit_to_revert>, in this case:
git diff 8989ee0 8f937c6
and
git diff 7c6b236 8f937c6
However, it's very important you realize that in doing so
"...declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want. See the revert-a-faulty-merge How-To for more details." (git-merge man page).
Here's a complete example:
git revert -m 1 <commit-hash>
git push -u origin master
git revert ... commits your changes.
-m 1indicates that you'd like to revert to the tree of the first parent prior to the merge, as stated by this answer.<commit-hash>is the commit hash of the merge that you would like to revert.
git push ... pushes your changes to the remote branch.
Videos
You can revert the merge following the official guide, however this leaves Git with the erroneous belief that the merged commits are still on the target branch.
Basically you have to :
git revert -m 1 (Commit id of the merge commit)
Try using git reflog <branch> to find out where your branch was before the merge and git reset --hard <commit number> to restore the old revision.
Reflog will show you older states of the branch, so you can return it to any change set you like.
Make sure you are in correct branch when you use git reset
To change remote repository history, you can do git push -f, however this is not recommended because someone can alredy have downloaded changes, pushed by you.