Git – Why does git need to remove duplicate objects when merging branches

gitversion control

Git displayed "removing duplicate objects" after I merged a branch to another and noticed my .git/objects folder has significantly reduced (from 40.7 MB to 33.5 MB).

Isn't branch just supposed to be a pointer, so why git needs to delete some objects?

What actually happened there?

Is it simply git's natural behavior?

Best Answer

During garbage collection, git takes the objects from your .git/objects directory, and packs them into the packfile in .git/objects/pack. During this phase, it also compresses the files and takes advantage of the similarity between files to reduce their size. Typically the packfile will increase in size a lot less than the size of the objects that have been moved into it, as it is able to do inter-file optimisations.

Once these objects are in the packfile then there these objects are actually in your local repository twice, once as an object file, and once in the packfile. The "removing duplicate objects" phase, then removes these duplicates from your .git/objects directory, and so the size of the directory is decreased.

Related Topic