I need to extract abbreviated commit names for specific git branches. These are typically 7-digit hexadecimal numbers, and they're used by some systems (including Heroku's COMMIT_HASH environment variable) to identify a specific commit.
There's several ugly ways to get an abbreviated commit name, including:
$ git log -1 --oneline | awk '{ print $1 }'
d4377e3
$ git describe --always --match ''
d4377e3
Is there a cleaner way to get this value?
Great question. I believe are looking for git-rev-parse
, one of the low level git commands.
[jason@star Data]$ git-rev-parse --short github/master
8b81a38
Also, if you want the latest commit on current branch, just pass HEAD
as the parameter.
[jason@star Data]$ git-rev-parse --short HEAD
8b81a38
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