Fabio Vitale
Fabio Vitale

Reputation: 2287

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

Upvotes: 7

Views: 2357

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 284836

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.

Upvotes: 11

Related Questions