1

I have merged a feature branch into develop and now need to revert this merge. In Azure devops when I did the pull request I couldn't see any option to squash commits (new to azure devops) and so the develop branch history looks like this..

Commit history

So the point at which I merged the branch is 61575 but it includes all the commits on the branch. I need to revert all of the merged branch and all those commits so that the develop branch is showing as commit 0063d782. How would I do that please?

Many thanks for any help

Blingers
  • 789
  • 1
  • 9
  • 22
  • See [How to revert a merge commit that's already pushed to remote branch?](https://stackoverflow.com/q/7099833/1256452) – torek Mar 11 '21 at 21:56
  • This is what you needed https://stackoverflow.com/questions/59467200/revert-merge-in-pending-changes-but-keep-local-changes-azure-devops – D3vtr0n Sep 13 '21 at 18:50

1 Answers1

0

To "unmerge" the branch, you need to reset develop to the last commit. However, by doing so you rewrite git history, so please be careful. Please make sure that no one has already pulled the merge commit you are going to remove.

If I understood correctly, your initial situation is:

enter image description here

In my example master points to 6146480, which is the merge commit. In order to remove the merge commit i need to hard reset to 82185bd, which is effectively the commit before the merge commit.

I can do this by executing git reset --hard HEAD~1 on the master (or develop in your specific case) branch.

By doing so the commit graph looks like this: enter image description here

All you need to do now, is to push (you might need to force push) your changes to remote.

zanseb
  • 1,275
  • 10
  • 20
  • Thanks for your answer, unfortunately I didn't have the balls to try this and in the end just reverted the changes back manually – Blingers Mar 11 '21 at 13:59