Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Lalitha June 8, 2016

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

0 votes
Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2016

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

 

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2016

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events