Skip to content
MyDSHMy DSH Field Notes
中文
Independently maintained; not affiliated with DeepSeek. No association with mydsh.dev or other MyDSH sites.

Home/Workspace & files/Cleanup & undo

Recovering from an accidental delete: make recoverability a fact first

A cleanup went too far, or the AI deleted something it should not have while tidying up.

VerifiedVersion and environmentChecked 2026-11-14
Scope
project directories (personal directories have stricter rules)
Checked
2026-11-14

Copyable command

tar -czf /tmp/ws-$(date +%H%M%S).tgz -C . --exclude='./.git' .
Boundary first: this page covers project directories. Bulk deletion in personal directories like Desktop, Downloads, or Documents is out of scope for direct execution — scan, report, confirm, then act.

Recovery requires something to recover from. The real work is making recoverability a daily fact, not a scramble after the fact.

Three layers, increasing cost

LayerHowRecovery timeCovers
Version controlA git repo and committing promptlySeconds (git restore)Everything committed
Snapshottar the directory before a runMinutesUncommitted changes
NoneRebuild from memoryUnboundedNothing

A minimal snapshot flow, measured:

tar -czf /tmp/ws-$(date +%H%M%S).tgz -C . --exclude='./.git' .
# after the fact
tar -xzf /tmp/ws-113045.tgz -C .

Rescuing files git deleted

  1. git status shows an uncommitted deletion: git restore brings it back.
  2. A committed deletion: git checkout HEAD~1 -- .
  3. Not even the commit is obvious: git log --diff-filter=D --name-only finds which one deleted it.

rm'd with no git

  • Check the recycle bin — many tools move files there rather than deleting.
  • Look for editor or system temp and backup files (*.bak, ~$*, swap files).
  • If nothing, accept that it is gone. Do not run recovery software writing to the same disk — it overwrites what might still be salvageable.

Turn the lesson into rules

  • Every cleanup: list with find first, then delete. Never combine listing and deleting in one command.
  • Batch deletes of no more than ten, verified after each batch.
  • When asking the AI to tidy up, require 'list first and wait for my confirmation' — never 'clean it up'.

What counts as working

Check every line. All of them pass or the job is not done.

  • Recovered content matches the original (hash or inspection)
  • You know which of the three layers you are on
  • Cleanup now lists before deleting

Where it fails

Symptom, cause, what to do — written in the order it actually happens.

SymptomCauseWhat to do
git restore does not recognise the pathWrong path, or the file was never trackedCopy the full path from git status; git cannot save untracked files
The restored version is stalePulled from an older commitUse git log -- file to find the commit with the latest content

Sources

Verified means measured here. Compiled means every line carries a source.