Ogglas Ogglas - 1 year ago 661
Git Question

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download