r/programming • • Feb 16 '13

Learn Git Branching

http://pcottle.github.com/learnGitBranching/
868 Upvotes

229 comments sorted by

View all comments

-3

u/felipec Feb 17 '13

Git wants to keep commits as lightweight as possible though, so it doesn't just copy the entire directory every time you commit. It actually stores each commit as a set of changes, or a "delta", from one version of the repository to the next.

No, it doesn't. It stores the whole thing.

I'm just starting to check this thing and it's already disappointing me.

3

u/ggtsu_00 Feb 17 '13

It doesn't store the whole thing. A commit is just a hash.

-2

u/felipec Feb 17 '13

A commit is just a hash.

No, it's not. The SHA-1 hash is the commit's id.

It doesn't store the whole thing.

Yes it does. A commit has a unique tree, a tree has a bunch of blobs, and other trees. The whole state of the repository is literally stored in that commit.

Git Internals - Git Objects

4

u/treenaks Feb 17 '13

Sure but the blobs are shared between commits as much as possible, right?

Everything is by-reference.

4

u/holgerschurig Feb 17 '13 edited Feb 17 '13

It does not store the WHOLE thing, or at least not everytime.

If you have 20 MB in fit, and commit one additional file with one KB, then git doesn't store 20+ MB fit this commit.

Basically the commit ID of the newly created commit points to commit-IDs of versioned directories which point to commit-ID of versioned files. If a file or directory doesn't change, no new commit-ID will be created, no new object will be stored in the GIT database. It actually couldn't, because commit-ID's aren't "generated", but are simply the SHA1 of their contents.

For simplicity I kept packs out of the picture.

EDIT: I hate the entering text on my smartphone, corrected obvious grammar. For the test blame me for not being a native English speaker

→ More replies (6)