Reputation: 21972
Is there a general* way to get all commit's parents in a pure** git way?
Yep, parents of merge commit could be parsed from git show
command, and parent of simple commit could be get with $HASH^
-like stuff. But in my opinion it is ugly and clumsy.
So, what I want is:
$> git parents $NON_MERGE_COMMIT_HASH
HASH1
$> git parents $MERGE_COMMIT_HASH
HASH1
HASH2
...
general* - single command for non-merge commits and merge commits.
pure** - simple git command without any parsing of output. I.e. for getting current branch name git rev-parse --abbrev-ref HEAD
is a pure command and git branch
is not.
Upvotes: 2
Views: 113
Reputation: 54163
git rev-parse "${HASH}"^@
The ^@
suffix means "all of the revision's parents" (in order). See git help revisions
.
Upvotes: 2
Reputation: 1180
The following seems to do the job :
git log -1 --pretty=tformat:%P <hash>
Upvotes: 2