Re: [question] When an identical file is added

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Nov 24, 2024 at 02:24:19AM +0000, A bughunter wrote:
> 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?
> A. When an identical file is added the old object shall be _ANSWER_HERE_

The file contents are represented as a "blob" inside the git repository, so
when you add a file with identical contents, the existing blob will be reused.
The file metadata (permissions, name, timestamp, etc) will be recorded as part
of the tree information. If the tree information is exactly identical to an
existing tree in the repository, then that tree object will also be reused.

Basically, for any object that it operates on, git will calculate the
checksum. If it then finds an identical checksum already present in the tree,
git will just use that existing object instead.

Reusing objects happens all the time in git. For example, imagine the scenario:

0. you have an existing repo
1. you add a file foo.c, and git commit
2. you change your mind and delete foo.c, and git commit
3. you decide you want foo.c after all, re-add it, and git commit

All tree and blob objects are identical in steps 0,2, and 1,3. However, commit
objects will be different in all 4 states.

-K




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux