Git reverse commit a pushed merge in SourceTree

14,854

Solution 1

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.

Solution 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!

Share:
14,854
Ogglas
Author by

Ogglas

My biggest interest in life is technology, primarily computers. It started out with a general computer interest and the need to know how and why something works. This interest has continued to grow but instead of dissecting computer hardware and removing viruses from friends computers all day long my focus has changed to IT security and programming. The programming language that I prefer is C#. On my spare time I like to do small (and large) technology projects. This can be everything from creating an RFID-reader or 3D printer using an Arduino to participating in vulnerability bounty programs. Another big interest is also my entrepreneurial side. I like to see something grow and instead of just seeing obstacles I try to see possibilities.

Updated on July 06, 2022

Comments

  • Ogglas
    Ogglas almost 2 years

    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.