Is there a cleaner way to get the short version hash of HEAD
from Git?
I want to see the same output as I get from:
git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8
I originally used the above command to generate a version string, but this is even better:
git describe --tags
It will output strings like 0.1.12
(tagged commit) or 0.1.11-5-g0c85fbc
(five commits after the tag).
The short hash is just a shorter version of the original (long) hash. The original Git hash is 40 bytes long while short is only 8 bytes long. However, it becomes difficult to manage it (in terms of using typing or displaying), and that's why the short version is used.
short-sha is a GitHub Action than provides an output sha with the shortened commit SHA. ⚠️ On November 16th, 2020 Github removes the set-env command. Version prior to v1. 2 of this action will not work.
To search for a hash, just enter at least the first 7 characters in the search box. Then on the results page, click the "Commits" tab to see matching commits (but only on the default branch, usually master ), or the "Issues" tab to see pull requests containing the commit.
Try this:
git rev-parse --short HEAD
The command git rev-parse
can do a remarkable number of different things, so you'd need to go through the documentation very carefully to spot that though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With