You are signed in. Close

You are signed out. Close

Thank you. Your subscription has started. Close

Thank you. You will get an email when a new comic comes out. Close

We could not confirm your payment. If you paid, use the link "Sign in" at the bottom of the page. Close

Something went wrong on our side. Please try again in a moment. Close

Previous episode Git: why copying your project folder is not enough

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. 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".youSave thisversion!frog-gameindex.htmlgame.jsfrog.pngchanged

    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. 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.frog-gameGitHigher jumpsyou, 10:42a commit

    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. 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?you100 frogpictures?100 commits

    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. 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.repositoryFirst riverHigher jumpsgame.js(old)index.htmlfrog.pnggame.js(new)

    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. 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.FirstriverHigherjumpsMovinglogsSoundonrepositoryfrog.pngkept once

    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.

  6. 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.How many copiesof each picture doesthe repository keep?

    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.

  7. Go further

    The real names behind a commit.git committhe command you typeto make a commitblobGit's word for onestored version of afile, like the new game.jsdiffwhat changed betweentwo commits: Git worksit out from the twosnapshots when you ask

    The real names behind a commit.

Next episode The Git staging area: why you pick before you commit

Share this comic

More comics