How to undo rm, git reset, and other destructive terminal commands
March 2026
Every developer has that moment. You type rm -rf and hit enter a fraction of a second before your brain catches up. Or you run git reset --hard and realize your uncommitted work is gone.
The terminal has no undo. Every other interface has Ctrl+Z. The terminal, where you can do the most damage, has nothing.
Can you recover a deleted file?
rm — the file is gone. Unlike dragging to Trash, rm bypasses it entirely. Forensic tools like testdisk might recover it, but it's unreliable on SSDs.
git reset --hard — pushed commits are on the remote. Unpushed ones might be in git reflog. Uncommitted changes are gone.
mv overwrite — the overwritten file is gone. No recovery.
sed -i — original content is gone. If it was in git, you can checkout the old version.
Recovery after the fact is unreliable. The real solution is prevention.
What people try
rm -i — asks for confirmation. Gets annoying, most people disable it. Only covers rm.
trash-cli / rip — moves files to trash instead of deleting. Only handles rm. You have to remember to use a different command.
Time Machine / backups — periodic. If you deleted a file 30 seconds ago and your last backup was an hour ago, you're stuck.
The shell hook approach
What if the terminal could detect destructive commands and back up the affected files before they run? That's what oops does. A shell hook runs before every command. Safe commands pass through with zero overhead. Destructive ones trigger a local backup before the original command runs.
AI agents make mistakes too
Claude Code, Cursor, Aider — these run shell commands on your behalf, including rm and git reset --hard. Since they go through the same shell, oops catches them automatically. Read more about protecting your files from AI coding agents.
How backups stay restorable
oops copies files into local trash and records the restore metadata in a journal. Copies use more disk than hard links, but they keep the saved version independent from overwrites, redirects, and in-place edits. See the FAQ and docs for details.
Install
macOS and Linux. zsh, bash, fish. Run oops tutorial after installing for an interactive walkthrough. See the full documentation for all commands.