Get the free coreGet core

Can you restore untracked files in Git? What works and what does not

Updated 5 min readSection 04 / Incidents & recovery
SHORT ANSWER

Git restore untracked files usually cannot be done, because Git has no source to restore a never-tracked file from. Pro Git says that when untracked files are removed, there is often no retrieving the content of those files. A copy may still exist elsewhere: in a Claude Code or Cursor checkpoint, in a Time Machine local snapshot or in the Trash. Before any git clean -f, run git clean -n to see what would go.

No Git command brings back a file Git never saw. What follows is where a copy may be hiding, in the order worth checking, and how to avoid the loss next time.

01What untracked means

Untracked files are files that are not under version control. You created them, but you never ran git add and committed them. Git can restore a path from a restore source, such as the index, a commit, a branch or a tag. The index, also called the staging area, is the list of changes you have added for the next commit. A file that was never added is in none of those places, so a git restore untracked files attempt finds nothing to copy.

Files you did commit are an easier story. See restore a deleted file in Git for those.

02How untracked files get lost

Before any attempt at git restore untracked files, ask how the file was lost, because the answer decides where a copy might be. Three routes are common. A git clean removed it, since that command removes files not under version control. A git reset --hard overwrote it, since that may overwrite untracked files. Or an agent deleted it with a shell command, in which case Claude Code's checkpoints do not track it when only Bash commands changed it. Knowing which route it was tells you which place below to check first. If you are not sure, go through all of them in the order given.

03Where a copy of an untracked file may still be

Git cannot help here, so the places below are the real options, and each has its own time limit.

Work down this list and stop at the first step that applies.

  1. Did an AI agent write or edit the file? Claude Code tracks Claude's file edits, and /rewind or /undo opens the menu to restore them. Skip this step if only Bash commands touched the file, because that is not tracked. In Cursor, click a checkpoint in the chat timeline to preview your files at that point, then restore.
  2. Is it still in the Trash? Select it and choose File > Put Back, or drag it out.
  3. Does the Mac have Time Machine? Look there, even with no backup disk attached, because local snapshots may let you recover previous versions.
  4. None of the above? Then the content is probably gone. Go to the end of this page to avoid a repeat.

The same places as a table:

PlaceWhat it may holdLimit
Claude Code checkpointClaude's file editsNot files only Bash changed; snapshots deleted about 30 days after the last save
Cursor checkpointSnapshot of the codebase from an Agent sessionReplies on the Cursor forum say only file-editing-tool edits are undone
TrashItems you trashedGone once emptied
Time Machine local snapshotsPrevious versions of filesKept up to 24 hours or until space is needed

The details live on other pages: Claude Code undo, Claude Code checkpoints, Cursor restore checkpoint, recover deleted files on a Mac and restore from Time Machine.

04Check before you clean: git clean -n

Most lost untracked files go this way. git clean cleans the working tree by removing files that are not under version control. The working tree is the files in your project folder, as you see them. Pro Git says to run it with -n first, to double check before changing the -n to a -f and doing it for real.

Use this to see what would be removed. It deletes nothing:

git clean -n

Pro Git also shows the form that includes directories:

git clean -d -n

Warning: the next command deletes the untracked files for real, and what is lost is often unrecoverable. Use it only after you have read the list and agree with it. Git refuses to delete without -f, unless clean.requireForce is set to false, and that setting defaults to true:

git clean -f

05Reset --hard and untracked files

Warning: git reset --hard overwrites all files and directories with the version from the commit, and may overwrite untracked files. If you are undoing a reset, undo a Git reset shows the steps, and the reflog, Git's log of where branch tips used to be, will not hold files Git never tracked.

git restore . is a separate risk. It restores everything in the current directory from the index, so unstaged edits in tracked files are replaced. It does not bring back files Git never tracked, because the index has no copy of them.

06Claude Code's auto mode and git clean

Auto mode in Claude Code blocks git clean -fd, because its classifier, the check that screens each action, presumes it would discard uncommitted changes. See the auto mode page for the full list.

07Stop the next loss

Add and commit new files early, so they stop being untracked and Git can restore them. Once a file is committed, the cases on the restore a deleted file page apply to it.

If you are not ready to commit, set the new files aside before a risky command. Warning: git stash -u takes your uncommitted changes and untracked files out of the folder; it saves them in the stash and then cleans them up:

git stash -u

To get them back, git stash pop applies the saved state on top of your working tree and removes it from the stash list. Applying can fail with conflicts. A stash entry you drop or clear by mistake cannot be recovered through the normal safety mechanisms, so pop it rather than delete it:

git stash pop

If an agent did the deleting, Claude Code deleted files covers the first ten minutes.

08Git restore untracked files: what to remember

Git usually cannot restore untracked files. Check agent checkpoints, the Trash and Time Machine. Run git clean -n before git clean -f. Commit new files early.

FAQ

What does untracked mean in Git?

Untracked files are files that are not under version control, which in plain words means new files you never added to Git. git clean removes files like that.

How do I revert untracked files in Git?

If you mean remove them, use git clean, and run it with -n first, which shows what would be done. Git refuses to delete without -f unless clean.requireForce is set to false. If you mean bring back a deleted one, Git usually cannot.

Does git reset --hard get rid of untracked files?

It may overwrite them. Git's manual says --hard overwrites all files and directories with the version from the commit, and may overwrite untracked files.

How do I git restore all files?

To restore all files in the current directory, Git documents git restore .. It works from the index unless you name another source. It does not help for files that were never tracked.

Can I recover an untracked file that git clean deleted?

Pro Git warns that if you change your mind, there is often no retrieving the content of those files. Check the Trash, Time Machine and any agent checkpoint; the Mac steps are on the Mac recovery pages.

Does Claude Code run git clean?

It depends on the mode. Auto mode blocks git clean -fd, because its classifier, the check that screens each action, presumes it would discard uncommitted changes. In manual mode, Claude Code asks before Bash commands except a built-in set of read-only ones.

Sources

  1. Pro Git, stashing and cleaning
  2. Git documentation, git-clean
  3. Git documentation, git-reset
  4. Git documentation, git-restore
  5. Claude Code docs, checkpointing
  6. Claude Code docs, permission modes
  7. Cursor docs, agent overview
  8. Cursor forum, restore checkpoint reply
  9. Apple Support, back up with Time Machine
  10. Apple Support, restore files
  11. Apple Support, empty the Trash
  12. Artificial Immunity
Lost files Git never tracked? Artificial Immunity watches the Mac where your agents work.Get the free core