I need to do a git revert -m , but I have not been able to find any documentation on how the commit parents are numbered. Everything I've seen (including the help pages for rev-parse) just tells me that the parents are numbered but do not say how they are numbered. Could someone point out to me where this is defined and how to determine this?
Unlike other commits, the merge commit is a commit which has multiple (generally two) parents. For instance, when a branch named feature is merged with master, a new commit is created on the branch master which has two parents, the previous head of master and the head of feature.
This new commit records both as its parents; the branch/commit you're merging in and the branch you are on when the merge occurs. The parent that gets recorded first (in the commit object of the new commit) is considered the "first parent", while the other one is considered the "second parent".
-m parent-number --mainline parent-number. Usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows cherry-pick to replay the change relative to the specified parent.
Every commit in git has at least one parent (except for the first/initial commit). A commit's parent is the previous one. C1 is the initial commit. C2 is the second one.
git show --format="%P" <SHA>
will give you the parent SHAs of the given commit in numerical order. Most often the one you'll want to specify for git revert
will be 1
.
In the case of most merges, the SHA of the branch that was checked out will be the first parent, and the SHA of the branch that was merged in will be the second. (Basically, the checked out branch is always the first parent; the other parents are the branches that were specified to the merge command in the order of their specification.)
If you want to find the SHA for a particular parent, use the caret operator:
git rev-parse <SHA>^1
git rev-parse <SHA>^2
et cetera.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With