Git reverse commit a pushed merge in SourceTree

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.

  • Git: Managing Branches
  • Git shows no merge conflicts when it should
  • Git: merge hides certain changes
  • Git merging release branches conflicts because of minor version changes
  • How can i merge a git commit from a different branch?
  • TFS 2010 API - Get work items from merge
  • Missing files after git pull?
  • Using ediff as git mergetool
  • 3 Solutions collect form web for “Git reverse commit a pushed merge in SourceTree”

    Found a good answer at last, it seems you need to use the terminal for this to work in SourceTree. This method is based on history deletion so not the best if others are also working on the project:

    1. Check out the branch you made the mistake on
    2. Right click on the commit you want to reset the branch to
    3. Click “Reset current branch to this commit”
    4. Select “Hard” mode and click “OK”
    5. Unfortunately you need terminal to do this bit. Launch Terminal from SourceTree and type git push origin NAME_OF_BRANCH --force into terminal (you may need to enter your git repo username and password for it to accept the command)

    If a message pops up later down the line asking if you would like to abort the rebase or continue. Click “continue”. If you abort, the merge will appear on your local copy again.

    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.

    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!

    Git Baby is a git and github fan, let's start git clone.