Search code examples
gitreferencesha1dereference

How to "dereference" a string to a git sha1 hash?


How do you get the sha1 hash for references like HEAD, HEAD^^^, HEAD~8?

I know I can hack up git show to get what I want, but it spits out a bunch of other stuff I don't want. Eg.

git show HEAD^^ --pretty=format:%H | head -n1

What is a simpler command that is more direct to the intent of what I am trying to achieve?


Solution

  • You want to use:

    git rev-parse HEAD