Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git reverse commit a pushed merge in SourceTree [duplicate]

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.

like image 560
Ogglas Avatar asked Feb 26 '16 13:02

Ogglas


People also ask

How do I revert a pushed commit in SourceTree?

When you push a commit, the safest way to revert it (rather than forcing the push with -f) is to use the revert function, so a new commit is created on top of your previous commit. This is possible to do using Sourcetree, right clicking in the commit that you want to revert, and selecting "Reverse commit...".

How do I revert a merge that has been pushed?

Now, if you have already pushed the merged changes you want to undo to your remote repository, you can right-click on the merge commit and select Revert commit from the context menu.

Can you reverse a merge commit?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.

How do I Unmerge in SourceTree?

Under the Branches heading, you will see the two branches for this repository, the main branch, and the wish-list branch. Double-click the main branch to switch to that branch. Click the Merge button. From the popup that appears, make sure the commit on your wish-list branch is highlighted.


1 Answers

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.

like image 153
edgraaff Avatar answered Oct 06 '22 18:10

edgraaff