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.
A little goodie: in shell
This is a solution in F#.
A little Bash script that should produce identical output to
git hash-object
:And in Perl (see also Git::PurePerl at http://search.cpan.org/dist/Git-PurePerl/ )
It is interesting to note that obviously Git adds a newline character to the end of the data before it will be hashed. A file containing nothing than "Hello World!" gets a blob hash of 980a0d5..., which the same as this one:
Full Python3 implementation: