5 ms·
Well, git makes a distinction between a delta and a diff, and it uses both. A delta is a lot like a diff, and loosely speaking, you could say it's one kind of
by adrianmonk 3y ago
Well, git makes a distinction between a delta and a diff, and it uses both.
A delta is a lot like a diff, and loosely speaking, you could say it's one kind of diff. And deltas are used (in packfiles) for storing git objects, so in that sense, a commit is (sometimes) stored as a delta.
But each commit takes a snapshot of the entire tree, so in that sense it is a complete snapshot.
However, even without delta object storage, if a file does not change between one commit and another, then its blob object will be reused because its hash will match, so in that sense, a commit stores (loosely speaking, again) a kind of diff.
Also, a commit object refers to a tree object but also zero or more parent commit objects, and via these parent object(s), you can reach past commits, so a commit does also, in a sense, store (loosely speaking) a history of every past commit. (Well, not every, but every one reachable from this branch.)
So, none of the options is 100% wrong, depending on your interpretation and how you define terms.
- tsimionescu 3y agoCommits are also used as diffs by several git commands - rebase, cherry-pick, patch, probably others. These commands take a commit and a target branch, but they use the commit as a diff from its parent, not as a snapshot. So it's fair to say that git's own API treats commits as diffs in some situations.
- IshKebab 3y agoI think you're getting a bit confused. The delta compression of commits in packfiles is purely a storage optimisation. It has zero effect on the semantics of git. It's completely invisible to users and has nothing to do with diffs between commits and their parents. Git doesn't use diffs at all, except ephemerally for some operations (e.g. displaying diffs between commits, or rebases). Diffs are never stored.
- adrianmonk 3y agoI understand all that. I'm saying, if you write a survey and one of the possible answers is "diff", but you don't clearly define what you mean by "diff", then don't be surprised if respondents use any reasonable definition that makes sense to them. Ask an ambiguous question, get a mishmash of answers. The thing that Git uses for packfiles is called a "delta" by Git, but it's also reasonable to call it a "diff". After all, Git's delta algorithm is "greatly inspired by parts of LibXDiff from Davide Libenzi"[1]. Not LibXDelta but LibXDiff. Yes, how Git stores blobs (using deltas) is orthogonal to how Git uses blobs. But while that orthogonality is useful for reasoning about Git, it's not wrong to think of a commit as the totality of what Git does, including that optimization. (Some people, when learning Git, stumble over the way it's described as storing full copies, thinking it's wasteful. For them to wrap their heads around Git, they have to understand that the optimization exists. Which makes sense because Git probably wouldn't be practical if it lacked that optimization.) The reason I'm bringing all this up is, if you're trying to explain Git, which is what the original article is about, then it's very important to keep in mind that someone who is learning Git needs to know what you mean when you say "diff". Most people who already know Git would tend to gravitate toward the definition of "diff" that you're assuming (the thing that Git computes on the fly and never stores), but people who already know Git aren't the target audience when you're teaching Git. --- [1] https://github.com/git/git/blob/master/diff-delta.c https://github.com/git/git/blob/master/diff-delta.c
- IshKebab 3y agoIt's pretty clear that "diff" means "what git diff shows", not some obscure internal compression system that most users have no idea exists.