Reputation: 147
it is written in git documentation that for every commit snapshot is done. It is strongly highlighted that git does not store files as series of diffs but rather as series of snapshots. It is highlighted also that snapshot contains a copy of file (if the file was changed of course). So, let's immerse to it:
git init
git add file.bin # (file.bin has 1024 MB)
git commit -m "."
ls -l --block-size=M -a
drwxr-xr-x 1 john 197121 0M lis 13 08:27 .git/
-rw-r--r-- 1 john 197121 1024M lis 13 08:19 file.bin
echo "X" >> file.bin # file was changed
git commit -am "Changed file.bin"
ls -l --block-size=M -a
drwxr-xr-x 1 john 197121 0M lis 13 08:27 .git/
-rw-r--r-- 1 john 197121 1025M lis 13 08:19 file.bin
So, .git
'size is still < 1 MB. It shows that file.bin
was not copied. Why?
Upvotes: 3
Views: 214
Reputation: 3366
When using the ls -l
command, the size you are seeing for a folder is not the size of all its components, but the size of the folder itself (and on linux, a folder is a simple small file).
To achieve what you want to do, you should use the du -sh
command.
du -sh * # print size of all non-hidden files in directory
du -sh .[^.]* # print size of all hidden files in directory
Upvotes: 1
Reputation: 2521
The .git size does not increase linearly along with your codebase size. If that's the case then it would takes a huge amount of space to store. This explanation is extracted from an article. Please read that for more in-depth explanation.
In fact when you commit git does only two things in order to create the snapshot of your working directory:
- List item
- If the file didn’t change, git just adds the name of the compressed file (the hash) into the snapshot.
- If the file has changed, git compresses it, stores the compressed file in the object folder. Finally it adds the name (the hash) of this compressed file into the snapshot.
This is a simplification, this whole process is a little bit complicated and will be part of a future post.
And once that snapshot is created, it will also be compressed and be name with an hash, and where all those compressed objects end up ? In the object folder.
Upvotes: 2