0 votes
1 view
in Devops and Agile by (20k 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 (28.4k 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 !


Categories

...