Why does git hash-object return a different hash than openssl sha1?

前端 未结 4 416
广开言路
广开言路 2020-12-05 12:42

Context: I downloaded a file (Audirvana 0.7.1.zip) from code.google to my Macbook Pro (Mac OS X 10.6.6).

I wanted to verify the checksum, which for that particular f

4条回答
  •  日久生厌
    2020-12-05 13:13

    Git stores objects as [Object Type, Object Length, delimeter (\0), Content] In your case:

    $ echo "A" | git hash-object --stdin
    f70f10e4db19068f79bc43844b49f3eece45c4e8
    

    Try to calculate hash as:

    $ echo -e "blob 2\0A" | shasum 
    f70f10e4db19068f79bc43844b49f3eece45c4e8  -
    

    Note using -e (for bash shell) and adjusting length for newline.

提交回复
热议问题