Curious Pandas

Snapshots with names

Git saves snapshots of your whole project and names each one by its contents. Make your first commit and see the name it gets.

12 min+30 XP for finishing

Every project you’ll ever work on changes. Files get edited, deleted, renamed, broken and fixed again. Git is the tool almost every software team uses to remember all of it. It can tell you what the project looked like last Tuesday, who changed this line, and give you back the version from before you broke it.

The idea underneath is simpler than its reputation:

  1. You work on files as normal, in your working tree.
  2. When you have something worth keeping, you put those changes in the staging area (git add).
  3. Then you take a snapshot of everything staged (git commit). The snapshot is permanent, and it gets a name.

That name is the interesting part. Git doesn’t number snapshots 1, 2, 3. It runs the snapshot’s exact contents through a hash function called SHA-1 and uses the 40-character result as the name. Same contents, same name, on every computer in the world. Change one letter and you get a completely different name.

Your first commit

The playground below is a small git that runs entirely in your browser. It isn’t a recording: it stores files exactly the way real git does. Every hash you see is the hash real git would print for the same file, author and time. Follow the mission, and use hint if you get stuck.

Your first repositoryreal git hashes
Working tree
    Staging area
      Last commit
        Commit graph

        No commits yet.

        Check yourself+10 XP

        Two files in different folders contain exactly the same text. How many copies of that text does git store?

        Why staging exists

        Beginners often ask why you can’t just commit straight away. Staging lets you choose what goes into a snapshot. Say you fixed a bug and also left some debugging junk lying around: you stage the fix, commit it, and the junk stays out of history. One commit should be one idea.

        Check yourself+10 XP

        git status shows a file under 'Untracked files'. What does that mean?

        Do it for real · your machine+50 XP bonus

        Everything above ran in your browser. Now do it on a real cluster withthe tilt platform. You need Docker, kind and Tilt, about 15 GB of free disk and 8 GB of spare RAM. Setup guide · Can my machine run it?

        On your own machine, with git installed:

        mkdir panda && cd panda
        git init
        echo "hello, panda" > hello.txt
        git add hello.txt
        git commit -m "my first commit"
        git log
        git hash-object hello.txt

        git hash-object hello.txt prints the same hash the playground showed for the same contents. Try it.

        Self-reported. We can't see your machine, and we don't want to. This is a bonus, never required.

        Sources

        Finished reading?

        Missions and quizzes above earn their own XP. This marks the lesson done.