4

I try to understand the plumbings command of git and how it's low-level actions build the high-level actions like add and commit.

I know, that each time when I used the:

git update-index file.txt

i create the blob from this file and create the reference (name of file and SHA1 key written together) in index (of course only if the file is changed). If i make commit, i create the the tree which point only to one blob (I was changing only the one file).

But in the .git/objects database is stored not one, but more (for example five or six) blobs created by the update-index command from this one file, which aren't pointed by any tree pointed by any commit object. The git should save only this blob, which are in snapshots created by commit.

Git has some automatic garbage collection, which can remove the not-pointed blob in the future? And the command update-index is the full equivalent for add command?

fingolfin
  • 77
  • 5
  • If you use `git show ` for those objects, does it show anything interesting? `git gc` will handle cleaning up unreferenced objects periodically. – nishantjr Sep 10 '15 at 00:47

1 Answers1

0

Git has a garbage collection process, which is automatically invoked by other commands (such as commit and pull) at a certain interval, or can be manually invoked by running git gc, which will, among other things, clean the object database, removing objects not referenced by another object or a branch/tag pointer.

The git command update-index is the plumbing underneath the porcelain git add command.

This two step process also allows the commit creation process to be quicker as git doesn't have to hash your files when creating the commit, as they were hashed and saved when you added them to the index.

T0xicCode
  • 4,583
  • 2
  • 37
  • 50