Last Updated: February 25, 2016
·
691
· michal-lipski

Reverting merge of two branches in git

To revert merge commit you have to find its hash using git log.

git log --merges 

gives you only merge commits (having 2 parents).

Now you can revert to one of parents using:

git revert -m 1 b413689  

Where 1 is the merge commit's first parent - the checked-out branch and 2 the merge's second parent - the branch merged.

You can see both parent commits using:

git cat-file -p b413689  

that gives you info similar to this:

tree 98ddaeeda349fe5b8f8334a290237d990c67b498  
parent b2180b93c6275841879a37fb11b90774e89cc9ad  
parent c6378ad0621bf6ab946c526a2cf7b6b56d10a03a  
author Michal Lipski <...> 1384528720 +0100  
committer Michal Lipski <...> 1384528720 +0100  

merge with feature/BM3329 

Seeing parents commits you can decide to which one revert.