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:
- Magento upgrading with Git
- opendiff or other merge tool talking with remote machine's Git over ssh
- forgot to pull changes before merge
- When I am using Git, should I rebase before I merge?
- Git workflow: “Your local changes would be overwritten by merge”
- View already-committed Git merge in external 3-way diff tool
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.
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:
- Check out the branch you made the mistake on
- Right click on the commit you want to reset the branch to
- Click “Reset current branch to this commit”
- Select “Hard” mode and click “OK”
- Unfortunately you need terminal to do this bit. Launch Terminal from SourceTree and type
git push origin NAME_OF_BRANCH --forceinto 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.
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”
and select the Hard mode when prompted.
All working copy changes will be discarded upon clicking the hard mode.
Hope this helps!