Portmint Lighthouse

Undoing Changes Safely

Here is the plain idea: because every good version is saved, you can undo a change by returning to a snapshot from before it — calmly, on purpose, without losing anything you meant to keep.

This is the payoff for all the careful saving. A mistake stops being a catastrophe and becomes a small, reversible step. Knowing you can always walk back is what lets you try bold things in the first place.

The eraser, the earlier draft, and the correction note

There isn't just one kind of undo, and the difference matters. Back to the book.

The eraser — you wrote a sentence today, haven't filed a draft yet, and you simply don't like it. You erase it. In Git, this is discarding changes in your working directory that you never committed. Quick and easy, but gone for good, so only erase work you're sure you don't want.

The earlier draft — you've filed several drafts and decide the book was better three drafts ago. You pull that older draft to the front and keep writing from there. In Git, this is returning to an earlier commit. Your snapshots are all still safe in the drawer; you've just chosen which one to stand on.

The correction note — a draft you already mailed had a mistake, and you can't un-mail it. So you send a new draft that reverses it: "Ignore the change on page 4." The bad draft still exists in the record, but a fresh draft cancels its effect. In Git this is called a revert — undoing a committed change by making a new commit that does the opposite.

Why "revert" is the gentle giant

Of those three, revert is the safest for work you've already committed, especially work you've shared with others.

It never erases history — it adds to it. The mistake stays visible (honest and useful), and a new save-point neatly cancels it out. Anyone looking back sees the full, truthful story: here was the error, here is the correction. Nothing is secretly rewritten under anyone's feet.

The one to handle with care

There's a more forceful undo that actually rewrites history — snipping filed drafts out of the drawer as if they never existed. Git can do this, and on your own private, unshared work it's occasionally fine.

But rewriting history that other people have already copied is the classic way to cause a tangle: their drawer and yours no longer agree. The safe rule for a beginner is simple — prefer revert, which adds a correction, over rewriting, which deletes the past. When in doubt, add; don't erase.

Undo is only possible if you committed

Here's the quiet lesson under all of this: you can only return to save-points you actually made. Work you never committed has no snapshot to come back to.

That's the real reason we commit often and in small bites. Frequent save-points mean many safe places to land. The undo button is only as good as the history behind it.

Your turn

On paper, list three "uh-oh" moments — deleted the wrong paragraph, a layout change that looked worse, a typo you mailed to a hundred people.

For each, name which undo fits: the eraser (uncommitted), the earlier draft (return to a past commit), or the correction note (revert). Matching the tool to the situation is the whole skill.

Next we step into the most freeing idea of all — branches, your private workshop for trying things. 🔦

Stuck or curious?

Ask Pip about this lesson — tap the porthole bottom-right.