How to undo git clean
May 2026
git clean removes untracked files. That is the point of the command, but it also means git usually cannot restore what it removed because untracked files were not in the repository.
Before running git clean
Use git clean -n first. It previews what would be deleted. If the list includes generated files only, proceed carefully. If it includes notes, local config, fixtures, or work in progress, move or commit them first.
After running git clean
If you already ran git clean -fd, check editor history, local snapshots, build cache, or external backups. Git cannot restore files it never tracked.
How oops protects git clean
oops sees destructive git clean commands before they run and stashes untracked content where possible. Undo applies the recorded recovery action.
Use dry-run for confidence
oops undo --dry-run shows what would be restored before changing files. That matters when you cleaned generated output and then created new files with the same names.
Install
For tracked-file resets, read how to undo git reset --hard. For regular deletes, read how to undo rm.