Some Git commands take the parent as a revision; others (such as git revert), as a parent number. How can I get the parents for both cases?
I don’t want to use the graphical log command as that often requires scrolling down a long tree to find the second parent.
Simple
git log <hash>called for a merge commit shows abbreviated hashes of its parents:gitoutputs parents according to their number: the first (leftmost) hash is for the first parent, and so on.If all you want is just the hashes, the two equivalent choices are:
git rev-listcan also show the parents’ hashes, though it will first list the hash for a commit:If you want to examine the parents, you can refer to them directly with carats as
<commit>^1and<commit>^2, e.g.:This does generalize; for an octopus merge you can refer to the nth parent as
<commit>^n. You can refer to all parents with<commit>^@, though this doesn’t work when a single commit is required. Additional suffixes can appear after the nth parent syntax (e.g.<commit>^2^,<commit>^2^@), whereas they cannot after^@(<commit>^@^isn’t valid). For more on this syntax, read therev-parseman page.