
Git from the Inside Out (2015) - dpeck
https://codewords.recurse.com/issues/two/git-from-the-inside-out
======
troughway
>Git from the Inside Out

[https://github.com/git/git](https://github.com/git/git)

[https://www.aosabook.org/en/git.html](https://www.aosabook.org/en/git.html)

[https://codewords.recurse.com/issues/two/git-from-the-
inside...](https://codewords.recurse.com/issues/two/git-from-the-inside-out)

[http://gitimmersion.com/](http://gitimmersion.com/)

~~~
neves
Why these links are better than the original article?

~~~
Mijka
Complementary links from some list i guess. Third one matches with current
article.

------
akkartik
> Notice how just `git add`ing a file saves its content to the objects
> directory. Its content will still be safe inside Git if the user deletes
> data/letter.txt from the working copy.

Holy crap, how do I not know this in 14+ years of working with git?!

The `git add --help` manpage seems to make no reference to this feature, it
just talks about adding the file to the index.

~~~
coldpie
It's not really a feature, more of a side-effect. Git-add causes git to record
the state of added files. You can see this because if you make changes to an
added (but uncommitted) file, you can see the diff between that uncommitted
index and the state on disk. That index state must exist somewhere. Where it
exists is in the object dir, just like everything else Git knows about.

(The article is slightly incorrect in that I think Git will eventually delete
unreferenced state files during git-fsck; it's not stored forever. But there's
a lot of heuristics during fsck to help keep data that could be valuable if
the user messed up.)

~~~
akkartik
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
I 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
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.

~~~
chimeracoder
> 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-
pac...](https://codewords.recurse.com/issues/three/unpacking-git-packfiles)

------
dang
A thread from 2016:
[https://news.ycombinator.com/item?id=12802949](https://news.ycombinator.com/item?id=12802949)

A bit from 2015:
[https://news.ycombinator.com/item?id=9793069](https://news.ycombinator.com/item?id=9793069)

Discussed at the time:
[https://news.ycombinator.com/item?id=9272249](https://news.ycombinator.com/item?id=9272249)

------
sdan
How did they generate those nice looking graphs?

~~~
maryrosecook
Hiya! Author of the article here. I used OmniGraffle.

~~~
sdan
Interesting. Wish there was a way to auto-generate these graphs with my git
history.

I like them!

~~~
coldpie
Have you tried "gitk"?

------
shadykiller
I gave a similar talk “Inside Git Guts with Ruby” at RubyConf India 2013 -
[https://m.youtube.com/watch?v=lPlwkxrG2NM](https://m.youtube.com/watch?v=lPlwkxrG2NM)

I had to learn a lot of git internals and it was super fun

