0

I have a file abc.txt whose file size is 3 and contains exact 3 characters abc. If I drag it into https://hexed.it, it is:

enter image description here

git hash-object abc.txt then produces f2ba8f84ab5c1bce84a7b441cb1959cfc7093b7f, whether with the --no-filters option or not.

However, if I go to any of the online SHA1 generators, the three characters abc gives a9993e364706816aba3e25717850c26c9cd0d89d.

What is the content that git hash-object is using to compute the hash?

Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • 2
    The hash is calculated from this content: `blob 3\0abc`, more specifically, `blob <0-byte>`. It's explained in that link @evolutionxbox provided although I wouldn't say it's a clear explanation. – Lasse V. Karlsen Aug 04 '21 at 11:05
  • @evolutionxbox Yes. So it's the string "blob " followed by file size as a string followed by a byte of binary 0 and then the file contents. – Old Geezer Aug 04 '21 at 11:07
  • @LasseV.Karlsen it's rather difficult answer to understand – evolutionxbox Aug 04 '21 at 11:08

0 Answers0