Based on [WayBack] tfs – How to retrieve the hash for the current commit in Git? – Stack Overflow
Get current hash:
git rev-parse HEAD
Show summary of current commit, including hash:
git show --summary
Show all hashes of all branches (both in heads and in remotes) and tags:
git show-ref
Get current hash with a *
marking if it is dirty:
git describe --always --abbrev=0 --match "NOT A TAG" --dirty="*"
The last one was [WayBack] answered by [WayBack] Rado:
display the full sha1 of the commit, but append an asterisk to the end if the working directory is not clean. …
Here is the one liner that does:
git describe --always --abbrev=0 --match "NOT A TAG" --dirty="*"
Result:f5366ccb21588c0d7a5f7d9fa1d3f85e9f9d1ffe*
Explanation: describes (using annotated tags) the current commit, but only with tags containing “NOT A TAG”. Since tags cannot have spaces, this never matches a tag and since we want to show a result
--always
, the command falls back displaying the full (--abbrev=0
) sha1 of the commit and it appends an asterisk if the working directory is--dirty
.
–jeroen