🚀 Alguni Start learning

Unit 3: Seeing Changes

What exactly did I do?

Unit 3 of 8 in Git and version control for kids. Its 4 lessons are What Changed?, The Diff That Vanished, Inside an Old Commit and Diff Detective — below is everything each one explains, and a question or two from it to try.

Every terminal session on this page was replayed before it shipped, on a git whose every message is tested against the real one.

This unit opens with a fortnight’s trial of everything — no card needed — or with a family plan, bought in the iPhone app. The first two units of every track are free for ever. Try it in the app.

🔬 What Changed?

Line by line

git status says *which files* changed. git diff says *what changed inside them*.

A line starting with - was there before. A line starting with + is there now. A line with a space is untouched, shown so you can see where you are.

Terminal

$ git diff
diff --git a/poem.txt b/poem.txt
index 1c27a27..0d47f1f 100644
--- a/poem.txt
+++ b/poem.txt
@@ -1,2 +1,2 @@
 Roses are red
-Violets are blue
+Violets are purple

Adding, not replacing

When you only add a line, the diff has a + and no - at all. The @@ line is git telling you which line numbers it is talking about.

Terminal

$ git diff
diff --git a/list.txt b/list.txt
index 4245cc7..01cc058 100644
--- a/list.txt
+++ b/list.txt
@@ -1,2 +1,3 @@
 milk
 eggs
+bread

Try it yourself

In a diff, what does a line starting with - mean?

  • It is a mistake
  • That line used to be there and is not any more
  • That line is new
  • That line is a comment

What does this diff say happened?

Terminal

git diff
  • Nothing changed
  • A line was added at the end
  • A whole file was deleted
  • A line was changed from one thing to another

Answer them in the app

🫥 The Diff That Vanished

Where did my diff go?

Run git add, then git diff, and git says nothing. It has not lost your work.

Plain git diff means "what is on my desk that is *not* in the box yet". Once it is in the box, there is nothing left to report.

Terminal

$ git diff
diff --git a/hello.txt b/hello.txt
index f893417..d7353d5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-hello
+hello world
$ git add hello.txt
$ git diff

Asking about the box instead

git diff --staged shows what is in the staging area — in other words, exactly what your next commit will contain.

It is the last thing worth doing before you commit.

Terminal

$ git diff --staged
diff --git a/hello.txt b/hello.txt
index f893417..d7353d5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-hello
+hello world

Try it yourself

You staged a change. Which command still shows it?

  • git diff
  • git diff --staged
  • git status --short
  • git log

Answer it in the app

🗝️ Inside an Old Commit

git show

git show opens up a commit: who made it, its message, and the diff of what it changed.

On its own it shows the newest commit. HEAD~1 means "one before the newest", HEAD~2 two before, and so on.

Terminal

$ git show
commit f75a37f0604a7a9b9d5c6fbe46745701153620b4 (HEAD -> main)
Author: You <you@example.com>
Date:   Mon Jan  6 09:02:00 2025 +0000

    Add eggs

diff --git a/list.txt b/list.txt
index a04b167..4245cc7 100644
--- a/list.txt
+++ b/list.txt
@@ -1 +1,2 @@
 milk
+eggs

Comparing any two moments

git diff also takes two names. git diff HEAD~2 HEAD shows everything that changed across the last two commits at once — handy when you cannot remember what you did yesterday.

Terminal

$ git diff HEAD~2 HEAD
diff --git a/f.txt b/f.txt
index f08dc37..f844632 100644
--- a/f.txt
+++ b/f.txt
@@ -1 +1,3 @@
 one
+two
+three

Try it yourself

What does HEAD~2 mean?

  • The second commit ever made
  • Two commits before where you are now
  • The second file in the folder
  • Two branches away

Answer it in the app

🏆 Diff Detective

Try it yourself

You have changed a file but not staged it. Which shows the change?

  • git diff
  • git diff --staged
  • git show
  • git log

A diff shows only + lines and no - lines. What happened?

  • Lines were only added
  • Lines were only deleted
  • The file was renamed
  • Nothing happened

Answer them in the app