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

Question

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

Answer

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.

How can I delete the current Git branch?

Difference between git stash pop and git stash apply