If I create a file foo
with touch foo
and then run shasum foo
it will print out
da39a3ee5e6b4b0d3255bfef95601890afd80709
This Gist from Carl Mäsak explains it better than I ever could:
https://gist.github.com/masak/2415865
alex@yuzu:~/foo$ git show HEAD
commit 7438e0a18888854650e6a53a9a5d823d6382de45
Author: Foo Bar
Date: Wed Jul 30 19:35:32 2014 -0700
foo
diff --git README README
new file mode 100644
index 0000000..e69de29
Which is the SHA-1 checksum of "commit\0" followed by a character count (length) followed by git cat-file commit HEAD
.
alex@yuzu:~/foo$ git cat-file commit HEAD
tree 543b9bebdc6bd5c4b22136034a95dd097a57d3dd
author Foo Bar 1406774132 -0700
committer Alex Balhatchet 1406774132 -0700
foo
Put it all together and...
alex@yuzu:~/foo$ (printf "commit %s\0" $(git cat-file commit HEAD | wc -c); git cat-file commit HEAD) | sha1sum
7438e0a18888854650e6a53a9a5d823d6382de45 -
The sha1sum output matches the commit SHA-1!