SWE.for vibe coders
Lesson 4 of 412 min

Reading a diff & undoing safely

See exactly what changed, and get back to safety when a change goes wrong.


Two skills round out the basics: reading a diff (seeing what changed) and undoing (getting back to safety). Together they make you fearless.

What a diff is

A diff shows exactly what changed between two versions — line by line. When your AI assistant edits code, the diff is how you check its work before trusting it. Learning to read one is the single best defense against “the AI changed something and I don’t know what.”

Run git diff to see your unsaved changes:

terminal
$git diff
diff --git a/greeting.js b/greeting.js
index e69de29..8b1a2c3 100644
--- a/greeting.js
+++ b/greeting.js
@@ -1,3 +1,3 @@
function greet(name) {
-  return "Hi " + name;
+  return "Hello, " + name + "!";
}

Ignore the noisy header lines. The part that matters is the bottom:

So this diff says: the old greeting "Hi " + name was replaced with "Hello, " + name + "!". That’s it. A diff is just removed lines and added lines, side by side.

Check yourself

In a diff, a line that starts with a minus sign (-) means what?

Undoing, from gentle to nuclear

Things go wrong. Here’s your ladder of undo, from safest to most drastic.

1. Throw away unsaved changes to one file. You edited a file, it’s worse, you haven’t committed. Restore it to the last commit:

terminal
$git restore greeting.js

The file snaps back to how it was at your last save point. (Your other files are untouched.)

2. Go back to how a whole project looked at a past commit. This is why you commit often — every commit is a place you can return to.

Check yourself

You spent an hour on a feature but never committed, and now it's badly broken. What's the lesson for next time?

Putting the module together

You can now: take snapshots (commit), work safely in parallel (branch), see what changed (diff), and get back to safety (restore). That’s the core of version control — and honestly more than a lot of working developers can clearly explain.

Module project: rescue yourself

Prove the safety net works end to end:

  1. In a git project, make sure everything is committed (git status shows a clean tree).
  2. Now deliberately break something — delete a chunk of a working file and save it.
  3. Run git diff and read what you removed (the red - lines).
  4. Run git restore <that-file> to undo it.
  5. Confirm with git status that you’re back to clean.

You just broke your code and recovered it in four commands. That confidence — knowing you can always get back — is the whole point of this module.