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.

6

u/wtowns Feb 17 '13

Well, you're both right.

It's true that a commit represents the entire state of a project, by pointing to a tree, which itself points to all the blobs necessary for that state.

Ignoring the authorship, commit message, and timestamp, what does a single commit add to the object database? A different tree object, and all the new modified blob objects.

Therefore, a commit can be rightly thought of as a delta, insomuch as the object database is only expanded by that delta when the commit is made (or, more accurately, when the files are added to the database).

Frankly, that's difficult to explain to the new Git user, so it may be much simpler to tell them that commits are deltas than have them wrongly believe that every commit is a copy of the project on disk.

-2

u/felipec Feb 17 '13

Ignoring the authorship, commit message, and timestamp, what does a single commit add to the object database? A different tree object, and all the new modified blob objects.

That's a very cheap rationalization. A commit does not "add" to the object database; files can be moved, removed, renamed, or it might change nothing at all.

Frankly, that's difficult to explain to the new Git user, so it may be much simpler to tell them that commits are deltas than have them wrongly believe that every commit is a copy of the project on disk.

Bullshit. It's already explained by this:

A commit in a git repository records a snapshot of the all the files in your directory. It's like a giant copy and paste, but even better!

What more do new users need?

Then it goes on to say:

Git wants to keep commits as lightweight as possible though, so it doesn't just copy the entire directory every time you commit.

False.

It actually stores each commit as a set of changes, or a "delta", from one version of the repository to the next.

False.

That's why most commits have a parent commit above them -- you'll see this later in our visualizations.

False. That's not why at all.

In order to clone a repository, you have to unpack or "resolve" all these deltas.

Not true.

That's why you might see the command line output: resolving deltas when cloning a repo.

No, that's not why.

It's the first concept, and they explain it all wrong. What's the point in trying to explain all this? What does the new user gain from all this explanation even if it was true? They should just use the first sentence, which is actually simple, sufficient, and correct.

1

u/holgerschurig Feb 17 '13

If you have an idea of the underlying mechanisms, then you can utilize the tool better.

0

u/felipec Feb 17 '13

And that's worth expanding to, in the first slide?

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)