{"thread":{"id":"62529","subject":"[question] When an identical file is added","startedAt":"2024-11-24T02:24:24Z","lastAt":"2024-11-26T15:19:24Z","messageCount":2,"participants":["A bughunter","Konstantin Ryabitsev"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"507975","messageId":"lSW86a4L1xWHfSTWIq732o26YCBCIN_B0rd6B1bCP8VIAY8d1V9pD1WEcCyW7Wyw2T14VVYka5XMTwJGFZEKcovBYIgOBUO5lbPWQ44cIfM=@proton.me","threadId":"62529","inReplyTo":null,"subject":"[question] When an identical file is added","fromName":"A bughunter","fromEmail":"a_bughunter@proton.me","sentAt":"2024-11-24T02:24:19Z","receivedAt":"2024-11-24T02:24:24Z","isPatch":false,"sender":{"key":"a_bughunter@proton.me","avatar":null},"body":"-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\n[question] When an identical file is added\n\nWhile objects are immutable, if I do mixed mode reset switching to an old-commit under HEAD then 'add' the same files again\nQ. Will it keep two copies as objects? \nA. No because when an identical file is added the object file is identical.  These become tree entries pointing to the same object. \nQ. May this overwrite the same object file because it is the same file? or because it is immutable will it reuse the old object file?\nA. When an identical file is added the old object shall be _ANSWER_HERE_\n\n\n\nfrom A_bughunter@proton.me\n\nSent with Proton Mail secure email.\n-----BEGIN PGP SIGNATURE-----\nVersion: ProtonMail\n\nwnUEARYKACcFgmdCjlAJkKkWZTlQrvKZFiEEZlQIBcAycZ2lO9z2qRZlOVCu\n8pkAADfCAP0fuC5Rc0gHALam7YkQHjZg54dGrnEUa6tZJZpSzNuiBgEA5c0a\nG+ZwfchdHP0gMPwHx4+TBL6LhW7ogj7u2IubQA4=\n=xVzR\n-----END PGP SIGNATURE-----\n"},{"id":"508186","messageId":"ortjg2pjq6eb6ruz72mcalemqgjr7lqoleqxpiqlghzu3ibwzj@rhvqxlpnkcl2","threadId":"62529","inReplyTo":"lSW86a4L1xWHfSTWIq732o26YCBCIN_B0rd6B1bCP8VIAY8d1V9pD1WEcCyW7Wyw2T14VVYka5XMTwJGFZEKcovBYIgOBUO5lbPWQ44cIfM=@proton.me","subject":"Re: [question] When an identical file is added","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2024-11-26T15:19:21Z","receivedAt":"2024-11-26T15:19:24Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Sun, Nov 24, 2024 at 02:24:19AM +0000, A bughunter wrote:\n> Q. May this overwrite the same object file because it is the same file? or because it is immutable will it reuse the old object file?\n> A. When an identical file is added the old object shall be _ANSWER_HERE_\n\nThe file contents are represented as a \"blob\" inside the git repository, so\nwhen you add a file with identical contents, the existing blob will be reused.\nThe file metadata (permissions, name, timestamp, etc) will be recorded as part\nof the tree information. If the tree information is exactly identical to an\nexisting tree in the repository, then that tree object will also be reused.\n\nBasically, for any object that it operates on, git will calculate the\nchecksum. If it then finds an identical checksum already present in the tree,\ngit will just use that existing object instead.\n\nReusing objects happens all the time in git. For example, imagine the scenario:\n\n0. you have an existing repo\n1. you add a file foo.c, and git commit\n2. you change your mind and delete foo.c, and git commit\n3. you decide you want foo.c after all, re-add it, and git commit\n\nAll tree and blob objects are identical in steps 0,2, and 1,3. However, commit\nobjects will be different in all 4 states.\n\n-K\n"}]}