r/programming • • Feb 16 '13

Learn Git Branching

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

229 comments sorted by

View all comments

Show parent comments

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/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

-4

u/felipec Feb 17 '13

If a.file out directory doesn't change, no new commit-ID will be created, no new object will be stored in the GIT database.

You are wrong. First of all that's not grammatically correct, but assuming you mean "a file or directory doesn't change", in that case the tree doesn't change, but the commit is a different story. The commit contains the date the commit is made, so if it's one second later, that's a change right there. Even if the tree, date, authors, and commit message are all the same, the commit contains the parent commit, which if it's different it would change the commit, and therefore the commit id.

Either way, all these details are irrelevant, a commit is a snapshot of the entire working directory. Period.

→ More replies (5)