Demo, all content is generated
Question

How do I undo everything Claude Code did in the last hour?

Solved · 563 views · asked by lindiwe_n · edited

It went down a wrong path, changed like 20 files, and the app is worse than an hour ago. I want to go back to how it was. I have git but the last commit is from yesterday and I did some good work this morning myself too.

What I’ve tried

Asked Claude to undo its changes, it tried but missed some files and broke something else.

Comment

3 answers

Marked as helpful by the asker
rafa_dev · edited

Press Esc twice (or /rewind) in Claude Code. You get a list of your earlier messages; pick the one from before it went wrong and choose to restore the code. It rolls back file edits Claude made through its edit tools, and leaves your own edits from this morning alone.

Caveat: changes it made via shell commands (deleting files, npm install, migrations) aren't tracked by that, check those by hand.

For the future: commit your own good work before starting a Claude task. Then "undo the last hour" is just git restore .

Comment
Esc Esc saved me. Didn't know that existed. Committing before every task from now on. lindiwe_n · edited
ingrid_h · edited

Git-only way if you need it: git stash your whole state, then git diff stash@{0} per file and bring back only your own parts with git checkout stash@{0} -- path/to/file. More work, but precise.

Comment
Not needed this time but saving it. lindiwe_n · edited
mira_dev · edited

For next time, work on a branch: git switch -c try-x before a big task. If it goes wrong, switch back to main and delete the branch. Costs nothing.

Comment