Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

git revert <commit_hash> alone won't work. -m must be specified, and I'm pretty confused about it.

Did anyone experience this before?

1 Answer

0 votes
by (27.5k points)

The -m option specifies the parent number.

This is due to a merge commit has more than one parent, and git doesn't recognize automatically which parent was the mainline, and which parent was the branch you want to un-merge.

When you read a merge commit within the output of git log, you may see its oldsters listed on the road that begins with Merge:

commit 5g937c683929b08379097828c8a04350b9b8e183

Merge: 5459ee0 2r6b336

Author: XYZ

Date: Sat Jul 20 22:09:12 2019 +0100

Merge branch 'gh-pages'

Conflicts:

        README

In this scenario, git revert 5g937c6 -m 1 can get you the tree as it was in 5459ee0, and git revert -m 2 can reinstate the tree as it was in 2r6b336.

To better understand the parent IDs, you can run:

git log 5459ee0

and

git log 2r6b336

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...