Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why a different SHA-1 for the same file under windows or linux?

Why on the same machine computing the SHA-1 hash of the same file produces two completely different SHA-1 hashes in windows and inside a msysgit Git bash?

Doesn't the SHA-1 algorithm was intended to produce the same hash for the same file in all OSes?

On windows (with HashCheck):
File hello.txt
22596363b3de40b06f981fb85d82312e8c0ed511

Inside a msysgit's Git bash windows (same machine, same file):

$ git hash-object hello.txt
3b18e512dba79e4c8300dd08aeb37f8e728b8dad

like image 302
Fabio Vitale Avatar asked May 30 '10 05:05

Fabio Vitale


1 Answers

Git adds a header ("blob ", the length, then null) before calculating the SHA-1. See this blog post for how to emulate the calculation outside git.

like image 139
Matthew Flaschen Avatar answered Sep 28 '22 03:09

Matthew Flaschen