A quick guide about the git shortsha usage and shorcut in terminal

· Git  · 1 min read

How to display git shortsha in terminal

A quick guide about the git shortsha usage and shorcut in terminal

The answer

The answer is already given in this StackOverflow answer more than 6 years ago (!) and still holds true nowadays :

git rev-parse --short HEAD
# 4d7b213

Why the short sha?

In Git every commit is identified by a 40-character hexadecimal string named the “Git SHA”.

So, I currently have my deploy machine displaying deploys like this :

commit number

See the commit number pointer by the arrow ?

Yes, that’s the git short SHA.

Only the first 7 digits amongst the 40.

The risk of collision is small enough to identify uniquely each commit.

Trick to display the short SHA in the Terminal

You can define an alias, on Linux or Windows, in order to display it without to remember the whole command :

alias shortsha='git rev-parse --short HEAD'

(exemple from my Linux machine)

Will be used like this :

shortsha
# 4d7b213

Neat!

Last trick

Sometimes, you will try some attempt to display it somewhere in the footer, in order to increase confidence about which version of the website is deployed. I like and use it, but I admit it’s not very common though.

Summary

That was a quick recap about the git short SHA.

Share:
Back to Blog

Related Posts

View All Posts »