kofucii
kofucii

Reputation: 7653

Is there a way to get a HEAD~<number> by commit hash sum in git

I have a particullar commit hash. Is there a way to get the "number" of the HEAD for this commit?

Upvotes: 0

Views: 107

Answers (1)

CB Bailey
CB Bailey

Reputation: 791869

If you temporarily tag your HEAD then you can use git describe --contains to get this information.

# make a temporary tag because describe will only use tags
git tag tmpXYZ

git describe --contains --match tmpXYZ <commit-id>
# prints something like tmpXYZ~21, or perhaps something more complex

# remove temp tag
git tag -d tmpXYZ

Note that if the commit that you are looking at is not on a direct, first-parent path from HEAD you may get a more complex description such as (real example): tmpXYZ~64^2~14^2~1.

Upvotes: 4

Related Questions