Removing <path>... — git clean permanently deleted untracked files
ID: git/clean-unrecoverable
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
git clean -f permanently deletes untracked files from the working directory. These files were never committed to git, so there is no reflog, no object database entry, and no way for git to recover them. This is one of the few truly irreversible git operations. -fd also removes untracked directories, -fdx also removes files matched by .gitignore.
genericWorkarounds
-
99% success Always use git clean -n (dry run) first
Run 'git clean -n' (or 'git clean -nd' for directories) before any actual clean. This shows what WOULD be deleted without deleting anything. Review the list carefully. Only then run with -f. Make this a strict habit.
Sources: https://git-scm.com/docs/git-clean
-
95% success Use git clean -fX (uppercase X) to only remove gitignored files
git clean -fX only removes files matched by .gitignore (build artifacts, cache, etc.) and leaves untracked source files alone. This is usually what you actually want when 'cleaning' a workspace. Compare: -x (lowercase) removes ignored AND untracked; -X (uppercase) removes ONLY ignored.
Sources: https://git-scm.com/docs/git-clean
-
15% success Use file recovery tools (ext4undelete, photorec, testdisk) as last resort
If the deleted files were on an ext4 filesystem, tools like ext4undelete or photorec may recover recently deleted files by scanning the raw filesystem. Stop writing to the disk immediately to avoid overwriting. Success rate is very low and depends on disk activity since deletion.
-
98% success Use git stash -u before cleaning to save untracked files
Run 'git stash -u' (or '--include-untracked') before git clean. This stashes all modifications AND untracked files. After cleaning, recover with 'git stash pop'. This creates a safety net since stash entries are stored as git objects.
Sources: https://git-scm.com/docs/git-stash
Dead Ends
Common approaches that don't work:
-
Using git reflog or git fsck to recover files deleted by git clean
99% fail
Reflog tracks changes to commit references. fsck finds dangling git objects. Files deleted by git clean were never tracked by git at all (they were untracked), so they have no git objects and no reflog entries. Git has zero information about these files.
-
Checking the system recycle bin or trash for git-cleaned files
99% fail
git clean uses direct file system deletion (unlink), which bypasses the desktop trash/recycle bin. The files are deleted at the filesystem level, not moved to any trash directory.
-
Running git clean -fd thinking it only removes build artifacts
85% fail
git clean -fd removes ALL untracked files and directories, not just build artifacts. This includes new source files you haven't added yet, configuration files, database dumps, scratch notes, and anything else not tracked by git. The -X flag (uppercase) is needed to only remove gitignored files.