Why does Zipping the same content twice gives two files with different SHA1?

前端 未结 4 473
失恋的感觉
失恋的感觉 2021-01-03 21:11

I have run into a strange problem with git and zip files. My build script takes a bunch of documentation html pages and zips them into a docs.zip I then check this file into

4条回答
  •  日久生厌
    2021-01-03 21:56

    By default, gzip saves file name and time stamp

    %> gzip -help 2>&1 | grep -e '-n'
     -N --name            save or restore original file name and time stamp
     -n --no-name         don't save original file name or time stamp
    
    %> gzip -V
    Apple gzip 272
    

    Using -n option:

    %> tar cv foo/ | gzip -n > foo.tgz; shasum foo.tgz # sha256sum on Ubuntu
    

    you will consistently get the same hash.

    Try above without -n and you should see a different hash each time.

提交回复
热议问题