gitgit-hash

How do I get the hash for the current commit in Git?


How do I get the hash of the current commit in Git?


Solution

  • To turn any extended object reference into a hash, use git-rev-parse:

    git rev-parse HEAD
    

    or

    git rev-parse --verify HEAD
    

    To retrieve the short hash:

    git rev-parse --short HEAD
    

    To turn references (e.g. branches and tags) into hashes, use git show-ref and git for-each-ref.