As I understand it when Git assigns a SHA1 hash to a file this SHA1 is unique to the file based on its contents.
As a result if a file moves from one repository to another the SHA1 for the file remains the same as its contents have not changed.
How does Git calculate the SHA1 digest? Does it do it on the full uncompressed file contents?
I would like to emulate assigning SHA1's outside of Git.
This is how Git calculates the SHA1 for a file (or, in Git terms, a "blob"):
So you can easily compute it yourself without having Git installed. Note that "\0" is the NULL-byte, not a two-character string.
For example, the hash of an empty file:
Another example:
Here is a Python implementation:
You can make a bash shell function to calculate it quite easily if you don't have git installed.
In JavaScript
In Perl:
As a shell command:
Take a look at the man page for git-hash-object. You can use it to compute the git hash of any particular file. I think that git feeds more than just the contents of the file into the hash algorithm, but I don't know for sure, and if it does feed in extra data, I don't know what it is.
Using Ruby, you could do something like this: