Working Fearlessly: The Git Undo Ladder
The safety net that lets you experiment freely — and lets you turn an agent loose without fear of losing work
Why undo comes before everything
The whole point of directing agents is to delegate — often away-from-keyboard, letting Claude Code run while you do something else. But you only delegate fearlessly if you can always get back to safety. That safety net is git.
So we don't start with "what is a commit." We start with the four ways to undo — and why "undo" almost never means "gone forever." Once you trust the net, you stop tiptoeing and start moving.
Most people picture undo as one button. In git it's a ladder: each rung reaches deeper and recovers more. Knowing which rung to climb is the difference between a calm thirty seconds and a panicked afternoon.
The four rungs
Read this top to bottom. The shallower rungs handle the everyday "oops"; the deeper ones rescue you when you think the work is destroyed — or stop the risk before it can happen.
working files → git restore (shallowest — uncommitted edits)
commits → git reset (unwind commits)
lost commits → git reflog (recover what you thought was gone)
(avoid it) → git worktree (deepest — a separate copy to play in)
Rung 1 throws away edits you haven't committed yet.
Rung 2 takes back commits you already made.
Rung 3 finds commits you thought a reset destroyed.
Rung 4 is preventive — an isolated copy, so there's nothing to undo.
Rungs 1 and 2: the everyday "oops"
These two cover ninety percent of real situations — an agent made a mess in your working files, or you committed something too early.
git restore — throw away uncommitted edits
You (or Claude Code) changed files, haven't committed, and want the last committed version back.
git restore src/app.ts # one file
git restore . # everything in the working tree
git reset — unwind commits
You made commits you want to take back. The flag decides what happens to the work.
git reset --soft HEAD~1 # undo the commit, KEEP the changes (staged)
git reset --hard HEAD~1 # undo the commit AND discard the changes
--soft is "I committed too early" — the work stays, just un-committed. --hard is "make it like that commit never happened" — the changes are dropped. Same command, opposite outcomes. Read the flag before you press enter.
Rungs 3 and 4: the rescue and the prevention
These are the rungs most beginners don't know exist — and they're exactly why a seasoned developer stays calm when a beginner panics.
git reflog — recover the "lost"
Even after a --hard reset, the old commit isn't really gone. Git keeps a private journal of everywhere HEAD has been.
git reflog # find the line for the commit you want back
git reset --hard a1b2c3d # ...and return to it
git worktree — don't need undo at all
A worktree is a second checked-out copy of your repo, on its own branch, in its own folder — so a risky experiment (or an agent) runs without touching your main work.
git worktree add ../experiment my-wild-idea
The Alembic and Opus Magnum loops isolate each agent in its own worktree for exactly this reason. The agent gets a sandbox to work in; your main copy never moves. That's prevention beating cure.
The one habit that holds the whole ladder up
A commit is git's atom of "saved." Anything committed is recoverable — via reflog if you have to. The only thing git can truly lose is work you never committed. So the habit is simple: commit early, commit often. That turns "did I just destroy everything?" into "which rung do I climb?"
Before you let an agent loose: commit your current state (your rung-2 escape hatch is ready), or give it a worktree (rung 4, full isolation). Whatever it does, one command returns you to safety. No safety net means no fearless delegation — and no leverage.
The highest-trust source on all of this is the free Pro Git book — the chapters "Undoing Things" and "Data Recovery" (the reflog). When you want the full picture under these commands, read those before quoting any of it.
Pick the right rung
Recall beats re-reading. Three situations — climb the correct rung for each.
Claude Code edited three files but hasn't committed anything. You want the last committed versions back.
Which rung?
You committed too early. You want to undo the commit but keep the changes staged so you can redo it.
Which command?
After a git reset --hard you fear the commits are gone forever.
Git's private journal that finds them is the…
Make a throwaway repo, write a junk file, commit it, then break and recover it on purpose: restore an edit, reset a commit, find it again with reflog. Do it once with your own hands and the panic never comes back. Then go let an agent run.