Recovery
Recover after an accidental git clean
After `git clean` removes untracked files, recovery usually depends on external history sources; prevent recurrence with dry-run and stash -u safeguards.
- Anyone actively handling a Git mistake
- Readers who want a conservative rescue habit before trouble happens
- Stop mutating the repo further
- Be ready to inspect `git reflog`, `git status`, and `git log --graph`
- Running more reset or rebase commands before preserving a checkpoint
- Changing shared history before assessing blast radius
git clean removes untracked files. Git often has no commit history for those files, so recovery is typically external.
What to verify first
If you ran preview first, use that file list:
git clean -nd
If deletion already happened, avoid further write-heavy actions on the same disk.
TrashEditor undoFilesystem recovery
Untracked filesEditor cacheSystem backup
reflog is of little help for clean because clean does not trigger reference changes.
Practical recovery sources
- IDE local history or system snapshots
- generated artifacts reproducible from scripts
- teammate branches or shared backups
Why reflog is usually limited here
Reflog tracks ref movement, not arbitrary untracked file contents.
Prevention habit
Before destructive clean:
git clean -nd
git stash push -u -m "pre-clean backup"
Preview scope first, then create a safety stash for untracked files.
-x also removes ignored files, which may include local config or generated assets you still need.
Good follow-up reads
recover lost stashgit-cleanreflog recovery