How Git keeps every version of your project without filling your disk
Git commit: how a snapshot of the whole project takes so little space
Every Git commit saves every file of your project, again and again, and the repository still stays small. How can a full snapshot cost almost nothing?
-
1
The frog jumps higher now, after a change you made in one file, game.js. To save this version, you ask Git for a commit, with one line that says what changed: "Higher jumps".
-
2
Git does not save the change alone: it takes a snapshot of every file of the project. That snapshot is the commit, and it also holds your name, the time and your line, called the commit message.
-
3
A whole project at every commit sounds heavy. The picture of the frog has not changed in weeks, so is it kept a hundred times?
-
4
No. Git keeps each version of a file only once. The new commit gets the new game.js, and for the two files that did not change, it points to the copies already kept.
-
5
Four commits now, four whole versions of the game, and the picture of the frog is still kept only once. Tomorrow, though, your folder will hold two changes, and only one of them will be ready.
-
Quick check
A photo album app holds 500 pictures and one text file. You make 10 commits, and each one changes only the text file.
Show the answer
One. Each commit points to the pictures already kept, and only the text file gets a new copy each time.
-
Go further
The real names behind a commit.