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:
- First parent:
git rev-parse <SHA>^1
- Second parent:
git rev-parse <SHA>^2
et cetera.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…