how do i revert a pull request done on master by my team mate? which command to use on source tree

git -c diff.mnemonicprefix=false -c core.quotepath=false revert --no-edit 33caab3d919b176504aed8ed57edcdd93fd8bc5a
error: Commit 33caab3d919b176504aed8ed57edcdd93fd8bc5a is a merge but no -m option was given.

fatal: revert failed

Completed with errors, see above.

2 answers

Don't use SourceTree, you'll need to go to the git command line for this.

Undoing a merge is basically similar to undoing any other commit, but there are a few additional complications. If you are lucky enough to catch your erroneous merge before pushing it, you can just use reset --hard. If you've already pushed, or if you're following best practice and doing your commits via Pull Requests, then you'll need to use git revert. But in order to use git revert with a merge commit, you need to use the -m flag to specify which of the commit's parents to use as a baseline.

A merge commit, to Git, is just a commit with two parents. Typically one of them represents the branch you "merged into" (probably the master branch or the development branch, depending on your workflow) and the other represents the branch that you merged (such as a feature branch). But to Git, they are just parent 1 and parent 2.

The "merged into" branch represents your baseline while the "merged" branch represents the changes that you want to revert. It seems like the "merged into" branch is usually P1, but I wouldn't count on this - examine your Git history to determine for sure. If you look at the details of a commit in SourceTree or using the command

git show --pretty=%P <commit>

the first parent listed will always be P1.

Once you've determined which parent is your baseline, the command is

git revert -m <baseline> <commit>

where baseline is the number 1 or 2 (or, rarely, another number for a commit with more than two parents)


git revert -m 1 3


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,227 views 4 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you