The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,100 other followers

tfs – How to retrieve the hash for the current commit in Git? – Stack Overflow

Posted by jpluimers on 2020/06/18

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: