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 The Git staging area: why you pick before you commit

How Git keeps every version of your project without filling your disk

Git history: how each commit remembers the one before

Change one letter in a Git commit from years ago, and nothing after it matches any more. What holds a Git history together, and why can nobody rewrite it quietly?

  1. 1 When Git makes a commit, it writes into it which commit came just before, its parent. "Fix the score" knows that its parent is "Sound on".Sound onFix the scoreparent

    When Git makes a commit, it writes into it which commit came just before, its parent. "Fix the score" knows that its parent is "Sound on".

  2. 2 Since each commit knows its parent, the commits form a chain. Git walks it back from the newest to the very first, the one with no parent, and that chain is the history of your project.firstnewestFirstriverHigherjumpsMovinglogsSoundonFix thescoreno parenthistory

    Since each commit knows its parent, the commits form a chain. Git walks it back from the newest to the very first, the one with no parent, and that chain is the history of your project.

  3. 3 A commit does not name its parent by its message, which anyone can write twice. It uses a hash, a long code that Git works out from everything the commit holds: its snapshot, its message, its time, and the hash of its parent.snapshotmessagetimeparent's hashhash3f9a2c1

    A commit does not name its parent by its message, which anyone can write twice. It uses a hash, a long code that Git works out from everything the commit holds: its snapshot, its message, its time, and the hash of its parent.

  4. 4 So if you change one letter in an old commit, its hash changes. The commit after it held the old hash, so its hash changes too, and so on up to the newest: nobody can change the past quietly.before9c41e072b7f6a3e05d9137a3c2f83f9a2c1after one letterchanged in Higher jumps9c41e0751d0b8ec8e2a470f6b9d2a4e7153

    So if you change one letter in an old commit, its hash changes. The commit after it held the old hash, so its hash changes too, and so on up to the newest: nobody can change the past quietly.

  5. 5 Your history runs in one straight line, and Miva plays the newest commit every evening. The night sky could break the whole game: how do you try it without touching her version, and without copying the folder again?Mivaplays thisyounight sky

    Your history runs in one straight line, and Miva plays the newest commit every evening. The night sky could break the whole game: how do you try it without touching her version, and without copying the folder again?

  6. Quick check

    Two laptops show the same hash on their newest commit.What do you knowabout the rest oftheir histories?

    Two laptops show the same hash on their newest commit.

    Show the answer

    They are the same all the way back to the first commit. That hash was made from the hash of its parent, which was made from the hash of its own parent, and so on.

  7. Go further

    The real names behind the history.git loglists the history, newestfirst: the hash, who,when and the messageof each commit3f9a2c1e8bSHA-1the recipe Git uses tomake a hash: 40 lettersand digits. Newer Git canalso use SHA-2563f9a2c1short hashthe first 7 characters,enough to name a commitin most projects

    The real names behind the history.

Next episode Git branches: how to try a risky idea without touching the main version

Share this comic

More comics