3 ms·
I always assumed the state of the index is stored in the binary file `.git/index`, and that mutations of the index overwrite this file. Is this not accurate?
by akkartik 7y ago
I always assumed the state of the index is stored in the binary file `.git/index`, and that mutations of the index overwrite this file. Is this not accurate?
- akkartik 7y agoI just `git add`ed a 100MB file to a test repo, and `.git/index` only grew to 104 bytes. So it seems to only contain metadata. TIL.
- coldpie 7y agoAnd if you go dig into `objects/`, you'll find your (possibly compressed) 100 MB object under its hash, and can view it with "git cat-file -p $hash" without ever having committed it :) Edit: And I bet if you dig around your index file enough, you'll find that hash someplace in there.
- chimeracoder 7y ago> And if you go dig into `objects/`, you'll find your (possibly compressed) 100 MB object under its hash, and can view it with "git cat-file -p $hash" without ever having committed it :) > > Edit: And I bet if you dig around your index file enough, you'll find that hash someplace in there. And if you want to know how that works, there's an article in the next issue of Code Words that goes into that as well: https://codewords.recurse.com/issues/three/unpacking-git-packfiles https://codewords.recurse.com/issues/three/unpacking-git-pac...
- coldpie 7y agoI admit I'm getting out of my knowledge here (it's been a while since I read gitcore-tutorial), but I think that's the "to-be-committed" commit object. So the index file "points to" the object file that stores the state of the object you added.
- tux1968 7y agoThe index doesn't contain objects themselves, every added file (whether it is committed or not) is held as a regular object. The index simply holds a list of object ID's. So yes, if you change a file and re-add it, the index will be overwritten and the original object will become dangling without any references to it.
- gcz 7y agoYou're mostly right. The index is a representation of the working directory tree and any modification of the index will modify .git/index. The thing is in git a directory (a tree in git language) is a collection of files references (of blobs hashes), thus the index is the staged tree, a collection of blobs hashes that will become the tree of your next commit. Blobs content are stored objects in .git/objects. There is a reference of the index format in: Documentation/technical/index-format.txt [1] [1]: https://github.com/git/git/blob/master/Documentation/technical/index-format.txt https://github.com/git/git/blob/master/Documentation/technic...