You can get back uncommitted Git files only while something still holds their content. If the files were deleted or overwritten but never committed or staged, Git does not store them automatically — your recovery sources are your editor's local history, your OS trash or a recycle bin, a backup or synced copy, an IDE swap file, or an open program still holding the file in memory. If you already ran git add, recovery improves a lot because the content exists as a blob in the object database. Check the safest source first, before running anything that writes to the repository.

Below are the real recovery routes in the order you should try them, what each one can and cannot return, and the exact way to confirm you got the right version back. This is stable Git behavior, not a version-specific trick, so it applies to current Git releases on Windows, macOS and Linux.

Prerequisites before you touch anything

You need a terminal (Git Bash, Terminal, PowerShell), the repository folder path, and a moment of restraint. Recovery gets harder when you keep working in the same directory, because new saves and new Git operations can overwrite the traces you are trying to find.

Run these five checks first and write down the answers:

1: Did you stage the file with git add at any point? If yes, the content is likely in the object database. 2: Did you commit it? Run git log --all --oneline -- path/to/file and look for the file in any commit. 3: Was it stored in the stash? Run git stash list. 4: Is it in the OS trash/recycle bin, or in your editor's local history? 5: Do you have a cloud-synced folder, backup, or another clone of the repo?

One important boundary: if the answer to all five is no and the file was never staged, Git has no record of it. Do not spend hours running obscure Git commands — verify the non-Git sources instead. The rest of this guide assumes at least one of those traces exists.

Route 1: Editor and IDE local history

This is the fastest source for a file that was deleted or reverted while you were editing it, and it works even when Git never saw the content.

Editor Where local history lives How to open it
VS Code Per-file timeline stored in the workspace Right-click the file in Explorer, choose "Open Timeline" (or use the Timeline view in the Explorer panel)
JetBrains IDEs (IntelliJ, WebStorm, PyCharm) Local History database inside the IDE config Right-click the file or folder, Local History, Show History
Sublime Text Backup copies in the session/backup location Use a local-history plugin if installed; otherwise check the backup folder

In VS Code, the Timeline view lists saved versions of a file with timestamps; if the file itself is deleted from disk, recreate an empty file at the same path first, then open its Timeline. In JetBrains IDEs, Local History keeps revisions even after deletion, and you can right-click a revision and revert it.

Success check: the recovered content matches the version you remember, not a half-saved draft. Compare the timestamp with when you lost the work. If the IDE shows no entries, it may have been closed and its history purged, or the file lived outside the project root.

Route 2: The trash, recycle bin, or a backup copy

A surprising share of "uncommitted file" losses are plain filesystem deletions. Before any Git work, check:

Windows Recycle Bin, macOS Trash, or your Linux desktop trash folder. Cloud sync version history (OneDrive, Google Drive, Dropbox all keep prior versions, usually for 30 days or per plan). Time Machine, File History, or a snapshot tool. Any other clone of the same repository on another machine.

This route is the only one that recovers content Git never stored. If you find the file here, copy it into place rather than moving it, so the backup stays intact. Verify by opening the file and checking a few lines you remember writing.

Failure handling: if the file is in neither trash nor sync history, stop treating the filesystem as a source and move to the staged-file routes below.

Route 3: Files staged with git add, recovered through dangling blobs

If you ran git add and then lost the file (deleted it, or overwrote it and staged the old version), Git wrote the content into its object database as a blob. That blob survives until garbage collection prunes it, which by default only happens after objects sit unreferenced for about two weeks — the exact window depends on gc.pruneExpire and whether git gc --prune=now was run.

Use git fsck --lost-found as the standard first probe:

Git prints lines like dangling blob . Blobs are content-addressed file snapshots with no filename attached, so you have to inspect each candidate:

Open the output and look for your code. When you find the right hash, write it back to the original path with git cat-file or a redirect:

Success check: the restored file diffs cleanly against what you expected and your editor or test suite accepts it. If the blob list is long, filter candidates by size and by keywords with git fsck --lost-found output piped through a loop that greps for a signature string you remember.

Failure handling: git fsck showing no dangling blobs after a file delete usually means the content was never staged, or it was committed and then removed. In the committed-then-removed case, you don't need fsck at all — see the next section.

Route 4: Files that were committed and then deleted or overwritten

If the file ever reached a commit, Git can reconstruct it from history. Find the commit that touched it:

Then extract the version you want without changing your working tree:

If the file was deleted in a known commit, git log --diff-filter=D --oneline -- path/to/file narrows the list to the deletion. If it was rewritten on a branch, the reflog for that branch (git reflog) shows prior branch tips, and you can inspect any tip with git show :path/to/file.

Success check: git diff HEAD -- path/to/file shows only the changes you intended to restore, and the file behaves as before. Failure handling: run git log --all (with the --all flag) to see branches and tags you forgot; a commit on an unmerged branch is invisible without it.

Route 5: Content that survived in the stash

If you stashed work before switching branches and forgot, git stash list shows entries like stash@{0}: WIP on main: .... Inspect without applying:

To restore, apply the specific stash and keep it for safety:

Success check: the file you lost appears with the stashed content. If the stash conflicts, Git leaves conflict markers; resolve them manually. The stash is not deleted by apply, so you can retry with pop later once you're satisfied.

Route 6: Reflog, temp index, and merge-conflict leftovers

Git keeps more copies than most people expect, and these are worth checking before you declare the file gone:

Reflog entries after an amend, rebase, or reset point to older commits that may still hold your file. The index's staged copy: if the file is staged and modified, the staged version is retrievable with git show :path/to/file even when the working file is garbage. ME RGE state: during a conflicted merge or rebase, the "ours" and "theirs" copies are retrievable with git show :2:path/to/file and git show :3:path/to/file (stage numbers follow git ls-files -u). Untracked-file backups: if git stash --include-untracked was run, untracked content lives in stash entries too.

Success check for each: the file writes out at full length and a quick git diff against your intent is clean. Failure handling: if git fsck and reflog both come up empty and the stash doesn't contain it, escalate to your IDE's Local History and then the filesystem backup — don't keep running Git write commands that could trigger garbage collection.

What Git can't recover, and why

Git stores content only when you stage or commit it. An untracked file that you saved, deleted, and never staged exists only on the filesystem, so Git has zero record of it — no command name or flag will bring it back. That's why the editor-history and trash routes come first: they are the only realistic recovery path for never-staged work.

A second hard limit: expired garbage collection. Dangling blobs from staged-but-never-committed work are pruned when git gc runs with an expiration shorter than the age of that blob, and a --prune=now run removes them immediately. If you suspect a recent GC ran, keep the repository untouched until you've checked git fsck --lost-found and the reflog, because writing new objects and pruning is exactly what removes the trace.

A third limit applies to overwrites: if you saved over a file and never staged either version, Git has no copy of the old content, and only the editor's local history, OS-level versioning, or a backup can help. Knowing this distinction — staged versus never staged — determines whether Git commands are worth trying at all.

A safer habit that prevents the next loss

The practical fix is to shorten the window in which valuable work exists only as an untracked, unstaged file.

Stage early and often with git add -p or plain git add — staging writes a blob, which is what makes Route 3 and the index copies possible. Commit small, even on throwaway branches: git commit on a temp branch is cheap and gives you a full history trail. Use git stash --include-untracked before destructive experiments. Keep a cloud-synced copy of the working directory or enable the IDE's autosave with local history. That covers the case Git cannot. If you're about to run a command that rewrites history (git reset --hard, git rebase -i, git clean -fd), check git status first — git clean -fd deletes untracked files outright, which is the classic way to destroy uncommitted work.

Success check on the habit: git status rarely shows an untracked file you care about for more than a work session. That single discipline closes most of the loss scenarios this guide covers.

FAQ

Does git checkout -- file bring back an overwritten file?

No. git checkout -- path restores the file from the index or a commit; if the overwritten content was never staged or committed, that command can't find it. It works only when the version you want already exists in Git's history or index.

Will git stash pop recover files I deleted without committing?

Only if you stashed them before deleting. The stash captures working-tree and, with --include-untracked, untracked changes at the moment you stash. Deleting files afterward doesn't put anything into the stash retroactively.

How long do dangling blobs stay recoverable?

Until garbage collection prunes them. git gc skips unreachable objects younger than the gc.pruneExpire setting (two weeks by default), and git gc --prune=now removes them right away. Check git config --get gc.pruneExpire and avoid running GC while you're still recovering.

Can I recover an uncommitted file from a different machine's clone?

Yes, if the other clone has the content staged or committed, or if you pushed a branch from it. The same git fsck --lost-found, reflog, and commit-history checks apply there. Clones without the content give you nothing to recover.

Is git fsck --lost-found safe to run on a live repository?

Yes — it only reads and reports unreachable objects. The risky part is what you run next, so avoid git gc --prune=now and destructive resets until you've extracted the file.