-1

I have a go project names hello which contains only a main.go source file.

I use go build to get an executable called hello, then md5sum hello to get its md5:9d51bcdbddd40320ba3057f91952865e. Then I use tar cvf hello.tar hello to get hello.tar and calculate its md5:63fda573908ec8c1bfa58ac46419efbe.

Next, I rm hello hello.tar and redo the things above:

hello md5: 9d51bcdbddd40320ba3057f91952865e (still the same)

hello.tar md5: 880dea1e12e5c69b24b83cf13db6606b (changed)

I'v already learned that if I use tar czf command, the md5 will surely change because of the timestamps in the archives are changed. But why tar cf also changes the md5?

refer: reference link

zujian wei
  • 11
  • 2

1 Answers1

0

When you get hash of hello it get the content and calculate the hash.

But when you get hello.tar it include beside the hello file kind of header which include variables like modification time of file hello. And those timestamps change the content (and hash) of hello.tar

For reference of the tar header you can check here.

Romeo Ninov
  • 6,538
  • 1
  • 22
  • 31