Git – Get Short Hash (SHA-1) from: Long Hash, HEAD, Log

A Git commit ID is a 40 digits long SHA-1 hash, that can be abbreviated up to the shortest 4 digits version (7 by default).

In this note i am showing how to abbreviate the long hash to a short hash in Git and how to display the abbreviated hashes in the outputs of the git log and git show commands.

Cool Tip: Revert a file to the previous commit! Read more →

Get Short Hash in Git

Get the short versions of the git log and git show, including the short SHA-1 hashes:

$ git log --oneline
$ git show --oneline

Get the short hash of HEAD:

$ git rev-parse --short HEAD

Abbreviate the long hash to a short hash (7 digits, by default):

$ git rev-parse --short 1e872b59013425b7c404a91d16119e8452b983f2
1e872b5

Abbreviate the long hash to the shortest hash (4 digits):

$ git rev-parse --short=4 1e872b59013425b7c404a91d16119e8452b983f2
1e87

Cool Tip: Got a hash but don’t know what type is it? Find out how to easily identify different hash types! Read more →