Reputation: 41805
I'm reading git basics
Git thinks of its data more like a set of snapshots of a miniature filesystem
I could not understanding the meaning of snapshot of git. Does git store the entire file content in each snapshot/version? For example, version 1
#include <stdio.h>
int main()
{
printf("hello, world");
return 0;
}
In version 2 I added an extra line to the file.
#include <stdio.h>
int main()
{
printf("hello, world");
printf("hello, git");
return 0;
}
Will git store the entire content rather than store only the difference(printf("hello, git")
) between these two versions as svn etc?
If it is, what's the point?
Upvotes: 2
Views: 619
Reputation: 60295
Will git store the entire content rather than store only the difference? [... and if so] what's the point?
Yes. That's what makes constructing good git histories so much simpler, and counterintuitively enough it also results in better compression efficiency.
(edit: relegate lotsa pedantry and elaboration to the revision history)
Upvotes: 1
Reputation: 15109
Will git store the entire content rather than store only the difference(printf("hello, git")) between these two versions as svn etc?
Git stores the entire contents of a file. But it takes no extra space when the file didn't change.
Read this brilliant answer about the Git pack file format: Are Git's pack files deltas rather than snapshots?
Files (and other stuff) are stored in a form of a "blob". Each sequence of bytes has its own sha1-code, which is pretty unique for it.
The following is true about SHA1:
You may have noticed that git indeed shows a diff of text files, pointing out the added and removed lines. This is done with the diff utility for your convenience. This also helps collect contribution statistics. And this is used for resolving merge conflicts. But nevertheless Git treats and stores text (and binary) files as single blobs.
There is a way to force Git to break text files to chunks when staging changes. This may be useful for very large files, but pretty useless for small ones.
git add --patch
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.
Upvotes: 1