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 »
Is React beginner friendly?

Is React beginner friendly?

My opinion about React for junior developers. Popular it is, job-friendly it is, but is it accessible to junior developers?

My Rails 8 opinion

My Rails 8 opinion

Rails 8 has been incredibly enjoyable so far, removing large parts of complexity, and allowing devs to replace any parts of the stack.

Rails 8 Bootstrap 5 tutorial

Rails 8 Bootstrap 5 tutorial

A very simple tutorial about Rails 8 and Bootstrap 5, since starting with Boostrap is already given by the framework by default with little config.