How to get the latest git commit SHA-1 in a repository?

How to get the latest git commit SHA-1 id in a repository?

And how to get the first 8 digits of the SHA-1?

asked Jan 20, 2016 by anonymous

1 Answer

Instead of the method introduced here, you may use

$ git rev-parse HEAD

to get the commit SHA-1 hash ID.

If you want to get the first 8 digits only, use

$ git rev-parse HEAD | cut -c 1-8

Here, cut -c 1-8 gives you bytes 1 to 8.

BTW: if you have tags tagging the versions, you may use

$ git describe --tags --long

to get a better string for IDs like

v2.0-40-gdc25d60

Here, 'v2.0' is the latest tag. '40' is the number of commits after the 'v2.0' tag and 'gdc25d60' is the first 8 digits of the commit sha-1 hash ID.

answered Jan 20, 2016 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...