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.

Who This Is For
  • Anyone actively handling a Git mistake
  • Readers who want a conservative rescue habit before trouble happens
Prerequisites
  • Stop mutating the repo further
  • Be ready to inspect `git reflog`, `git status`, and `git log --graph`
Common Risks
  • 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.

Recover After git cleangit clean is irreversible, but other sources might still help recover files.
Check Sources
TrashEditor undoFilesystem recovery
Possible Recovery
Untracked filesEditor cacheSystem backup
reflog is of little help for clean because clean does not trigger reference changes.

Practical recovery sources

  1. IDE local history or system snapshots
  2. generated artifacts reproducible from scripts
  3. 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.

Use `git clean -fdx` with extreme care

-x also removes ignored files, which may include local config or generated assets you still need.

Good follow-up reads

  1. recover lost stash
  2. git-clean
  3. reflog recovery