Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are git parent numbers assigned?

Tags:

git

From the documentation for git-rev-parse:

^, e.g. HEAD^, v1.5.1^0

A suffix ^ to a revision parameter means the first parent of that
commit object. ^<n> means the <n>th parent (i.e. <rev>^ is equivalent
to <rev>^1). As a special rule, <rev>^0 means the commit itself and is
used when <rev> is the object name of a tag object that refers to a
commit object.

I understand that git commits can have multiple parents, and that this syntax can be used to disambiguate which parent is referred to, but what determines which parent is the 'first parent' or 'second parent'? Is it just based on which commit was checked out when the commits were merged?

For example, would git checkout master; git merge feature result in master being parent 1, whereas git checkout feature; git merge master would result in feature being parent 1? Or is there something else going on here?

like image 577
Ajedi32 Avatar asked Jun 30 '26 18:06

Ajedi32


1 Answers

Is it just based on which commit was checked out when the commits were merged?

That's right. You can look at the parents of a commit using git show or git cat-file -p HEAD.

like image 151
user3426575 Avatar answered Jul 03 '26 09:07

user3426575



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!