8

I accidentally merged a branch and had "Push changes immediately" checked. Unfortunately I made a merge error and now I wan't to make a reverse commit to remove it. However every time I do it in SourceTree I get the following error:

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

Is there any way to do this or do I have to use the terminal for this? Been reading about it but could not find a solution to this specific case.

Ogglas
  • 62,132
  • 37
  • 328
  • 418

2 Answers2

4

You can find answers about how to bring back your branch (or master) back to the state of before it was merged (hard revert). If it's okay to revert everything back to that state, it's fine. But usually I have to revert the merge of a feature branch while preserving commits made after that merge.

Just do:

git revert -m 1 [copy-paste-the-id-of-the-merge-commit-here]

if necessary, edit conflicts and commit.

edit: and yes, SourceTree should be passing the -m 1 arguments if you're undoing a merge commit.

edgraaff
  • 481
  • 4
  • 5
2

You may want to right click on the latest commit and click:

"Reset current branch to this commit"

enter image description here

and select the Hard mode when prompted.

enter image description here

Important Note: All working copy changes will be discarded upon clicking the hard mode.

Hope this helps!

Cheers!

Cyan Baltazar
  • 3,462
  • 1
  • 17
  • 11