0

On bitbucket I have merged a Pull request which had 2 commits. I didn't squash merge them. Other than the 2 commits, I find that there is an additional "grey commit" with the total changes of the 2 commits.

enter image description here

If I open the grey commit, I can see the newly merged commits as "parent commits" : enter image description here

Now, I want to revert my merge. I can revert the 2 commits individually in the correct sequence, but this will become difficult if I have several commits in the merge. One option is squash merge, but I want to retain each individual commit. So, I want to write a code which takes the commit id of the grey commit and then list out the commits in it so that I can revert them in order. Is there any such command?

Amit
  • 121
  • 1
  • 3
  • 12
  • 1
    Please read [Rollback a Git merge](https://stackoverflow.com/questions/11722533/rollback-a-git-merge/29110174), which discusses how to use `git revert` against a merge commit. – Tim Biegeleisen Apr 01 '19 at 13:26
  • 1
    Possible duplicate of [How to revert a merge commit that's already pushed to remote branch?](https://stackoverflow.com/questions/7099833/how-to-revert-a-merge-commit-thats-already-pushed-to-remote-branch) – Raul Rene Apr 01 '19 at 13:34

1 Answers1

1

You can revert a whole merge:

git revert -m 1 <hash-of-merge-commit>

And it will create a single revert commit with the content of the whole branch reverted.

The -m option is the index of the parent commit of the merge. In the case of a single branch merged, -m 1 is usually what you need.

padawin
  • 4,230
  • 15
  • 19