1

Why does git assign the same SHA-1 to files with different names and different locations although contents is the same?

100644 43efcd84207788e5289ee23a9ce95d9f43b13d9a 0 dir1/dir1_d2/dir1_d2_f1.txt 100644 43efcd84207788e5289ee23a9ce95d9f43b13d9a 0 test.txt

Show file contents:

$ git cat-file -p 43efcd84207788e5289ee23a9ce95d9f43b13d9a Line 1

Thanks

appu
  • 471
  • 1
  • 8
  • 26

1 Answers1

6

Because content is the same!

Git tracks content in blob object.
Paths are resolved by git with tree objects.

You can read Pro Git - Git Internals - Git Objects to know how git store data.

zigarn
  • 10,892
  • 2
  • 31
  • 45
  • Does git performs a comparison of __Each__ file's content with __Each__ file in the cache/staging area and upon matching adds a new entry in the index with the same hash (reference to same object) as that of the original file and its corresponding name to that of newly tracked file? – appu Jul 02 '17 at 09:43
  • No, for any new object to store, git simply hash it, then if the hash already exists the object is already stored, else it's a new object to store. – zigarn Jul 02 '17 at 15:02