0

I have committed two files on git (note1a.txt and note1b.txt) with the same contents ("hello"). Given the content is the same I would expect the SHA-1 hash to be the same. However they have a different Hash (see pictures below). Why is this?

I am using Android Studio GUI.

enter image description here

enter image description here

mars8
  • 770
  • 1
  • 11
  • 25
  • Git SHA-1 includes not only the contents of commited files, but many more information like commiter name and commit date. See https://stackoverflow.com/a/68806436/14967413 ("Get the commit hash" heading"). – user14967413 Jan 24 '23 at 12:30
  • @JoachimSauer Just for clarity, what is the reason of such non-Git object ID in Android Studio? Just to compare if contents of two files are equal? – user14967413 Jan 24 '23 at 13:31
  • @JoachimSauer If I run the `hello.txt` code above I see the hash is the same on different machines. I am still unsure why Android Studio shows different ones. Is there some meta data (file name?) that android studio is including as "content"? Git blobs are only concerned with **content** of the file. Are these two hashes in the images not blob hashes? – mars8 Jan 24 '23 at 14:14

1 Answers1

1

So the hash in the image is actually the commit hash and not the object hash. The two txt files were separately committed, hence the hash was different. d'oh...

mars8
  • 770
  • 1
  • 11
  • 25
  • 1
    I'm sorry on being so insistent on a wrong direction in the comments, I hadn't realized that the object hash for the file containing just `hello` was different from your picture. It starts with `b6fc4c`, whereas your picture shows `b6788f`. If I had realized that I wouldn't have misled you. – Joachim Sauer Jan 24 '23 at 17:28