Getting a deleted file back from VS Code depends on how it disappeared. If the file lived on a local disk and was deleted inside the editor, VS Code's built-in Timeline view, your operating system's trash, or a local history extension is often enough. If the file was never saved to disk, or the deletion came from Git, you're relying on Git's object database instead. The core rule: stop writing to the affected drive and check the lightest recovery source first, because every further save, checkout, or build can overwrite the data you want back.
Why the Recovery Path Splits: Local Files, Git, and Unsaved Buffers
VS Code is an editor, not a file manager or a backup service. It stores your project files wherever they live—usually an NTFS, APFS, or ext4 volume—and keeps only a few caches of its own. That shapes recovery into three distinct cases.
The first case is a file that existed on disk and was deleted in File Explorer, Finder, or from VS Code's Explorer pane. The operating system's trash or recycle bin is the primary recovery source, and VS Code's Timeline view can sometimes help because it retains local history snapshots for tracked files. The second case is a file that was deleted inside a Git repository and staged or committed. Here Git's object database holds the content, and recovery is a Git operation, not a filesystem one. The third case is content that was never saved to disk—a new untitled tab, or edits to a saved file—where VS Code's hot exit backups and per-tab undo stack are the only realistic sources.
Knowing which case you're in prevents the most common mistake: running a filesystem undelete tool on a Git repo problem, or trying to use Git on a file that was never committed.
Prerequisites Before You Touch Anything
A few preparations make recovery more reliable and prevent accidental data loss.
Confirm the exact path and filename you're looking for. If you don't remember it, note the folder and approximate modification time; recovery tools filter by both.
Stop using the drive or partition that held the file. On a spinning disk or SSD, deleted blocks may be reused by any write operation, including background indexing, downloads, or new saves. Close VS Code and other applications that might write to that volume if you plan to use a filesystem undelete tool.
Decide whether the file was tracked by Git. Open a terminal in the project folder and run git status and git log --oneline -10. If the file appears in recent history or in the index, Git is your fastest route. If the folder isn't a repository at all, skip the Git sections entirely.
Know where your trash lives. Windows uses the Recycle Bin (normally on the same drive as the deleted file); macOS uses Trash (per volume, so external drives have their own); Linux desktop environments use a per-user trash under ~/.local/share/Trash, though files deleted from a terminal with rm bypass it.
Method 1: VS Code Timeline and Local History
VS Code's Timeline view, in the Explorer sidebar, records local history for files that are part of a folder you've opened, along with Git commits when the folder is a repository. It's the least invasive check and takes seconds.
1: Open the folder in VS Code and press Ctrl+Shift+E (Cmd+Shift+E on macOS) to focus the Explorer. 2: Look in the Timeline section at the bottom of the Explorer. If the deleted file no longer exists, the Timeline for that path may be gone—so this method works best when the file still exists but has unwanted content, or when the file was restored from the trash first. 3: If you restored the file, click it, then click entries in the Timeline to preview earlier versions and use the restore icon or right-click to restore a snapshot.
The success check is straightforward: the restored content appears in the editor and matches the version timestamp you selected. If the Timeline shows nothing, local history isn't available for that file; move on. A limitation worth knowing: VS Code's local history is tied to the workspace and preserved across sessions, but it isn't a full backup—large files and some configurations may be excluded, and clearing your VS Code data folder removes it.
Method 2: The Operating System Trash
Most deletions from VS Code's Explorer pane go to the system trash rather than being permanently removed.
On Windows, open the Recycle Bin from the desktop, sort by Date deleted, find the file, right-click, and choose Restore. The file returns to its original folder. If it isn't there, the deletion may have been permanent (Shift+Delete) or the file may have been on a network location that doesn't use the local Recycle Bin.
On macOS, open Trash from the Dock, locate the file, right-click, and choose Put Back. External drives have separate trash folders; check the volume's .Trashes directory if Put Back isn't available.
On Linux, check ~/.local/share/Trash/files and the matching info directory, which records original paths. Files deleted with the rm command or from certain tools skip the trash, so absence here is common.
Expect restored files to keep their original names unless a duplicate exists, in which case the system may append a suffix. If the file isn't in the trash, its blocks may already be marked free; that's when filesystem undelete tools become relevant.
Method 3: Git for Tracked Files
If the project is a Git repository and the file was committed at some point, Git almost certainly still has the content. Git keeps deleted files in history until garbage collection prunes unreachable objects, which by default happens after a grace period measured in weeks, not days.
Start by checking whether the file exists in the current branch's history:
1: Run git log --all --oneline -- path/to/file to list commits that touched that path. If you see commits, the file existed in those snapshots. 2: To restore the version from the most recent commit before deletion, run git checkout -- path/to/file. This writes the file back into your working tree and stages it. Verify the content, then commit if appropriate. 3: If the file was deleted but the deletion isn't committed yet, git restore path/to/file (or git checkout -- path/to/file) brings it back from the index or HEAD. 4: If the file was staged for deletion but you want it back in the index, git restore --staged path/to/file followed by git restore path/to/file reverses the staging.
For a file that was never committed but was staged at least once, git fsck --lost-found can list dangling blobs, and git show reveals their content. This is a real but fiddly route: dangling blobs have no filenames, so you identify the right one by inspecting content.
The success check: git status shows the file as restored rather than deleted, and the content matches the commit you chose. One warning—running git gc or git prune after the deletion can remove unreachable objects sooner than the default schedule, so avoid those commands until you've recovered what you need.
Method 4: VS Code Undo, Hot Exit, and Unsaved Buffers
If the file was deleted from the Explorer pane while VS Code was open and you haven't closed the editor since, Ctrl+Z (Cmd+Z) in the Explorer can undo the deletion, because VS Code routes file operations through an undo stack. This is the fastest recovery of all and works for both deletions and renames.
For unsaved work, VS Code's hot exit feature restores unsaved editors when you reopen the application, provided the window closed normally. Reopen VS Code and check whether the tab returns. If the window crashed or was force-quit, hot exit backups may still exist in the user data directory: on Windows under %APPDATA%\Code\Backups, on macOS under ~/Library/Application Support/Code/Backups, and on Linux under ~/.config/Code/Backups. These are backup folders containing the unsaved buffer content; they're readable text for most file types, though you may need to match them to the right original filename by inspecting content.
A related edge case: if you deleted text inside a file rather than deleting the file itself, the editor's undo stack (Ctrl+Z) still holds the change until the tab closes. Reopening a closed tab usually discards that in-memory undo history, which is why acting before closing matters.
Method 5: Filesystem Undelete Tools as a Last Resort
When the trash is empty, there's no Git history, and no VS Code backup exists, the file's data may still sit on disk in unallocated space. Recovery then depends on the filesystem and on how much writing has happened since deletion.
On Windows, tools such as Recuva or the built-in File History (if enabled) can help; File History requires that you turned it on beforehand, so check Settings > Update & Security > Backup. On macOS, Time Machine is the equivalent—open the folder in Finder, enter Time Machine, and step back to a date before deletion. On Linux, extundelete and testdisk work on ext3/ext4, and photorec carves files by signature when metadata is gone.
The practical constraints matter more than the tool names. Undelete success falls sharply once the freed blocks are reused, which is why you should avoid installing recovery software onto the same drive you're recovering from—install it on another drive or run it from a USB stick. SSDs with TRIM enabled may have already erased the blocks at the firmware level, making software recovery impossible; in that case, backups are the only path. Expect recovered files to sometimes lack original names or timestamps.
Method 6: Backups and Cloud Sync Versions
If the project folder syncs to OneDrive, Google Drive, Dropbox, or iCloud Drive, version history and trash features in those services are often the most reliable recovery route, because they snapshot independently of your local disk.
In OneDrive, right-click the folder in the web interface and open Version history; deleted items also sit in the OneDrive recycle bin for a limited retention period. Google Drive keeps deleted files in its trash for 30 days by default and offers version history per file. Dropbox retains deleted files for 30 days on its basic plans and longer on paid tiers, with version history of 30 days or more depending on plan. iCloud Drive's Recently Deleted folder holds items for 30 days.
The check is to confirm the restored version's timestamp predates the deletion. One caveat: sync clients can propagate deletions quickly, so if a file was deleted locally and the sync ran, the cloud copy may also be gone from the current view but still recoverable from version history or trash before retention expires.
Choosing the Fastest Route for Your Situation
The right method depends on three facts: whether the file was tracked by Git, whether it went to the trash, and whether unsaved content is involved. The table below maps common situations to the first method worth trying.
| Situation | First method | Fallback |
|---|---|---|
| Deleted in Explorer pane, editor still open | Undo in Explorer (Ctrl+Z) | OS trash |
| Deleted from disk, normal delete | OS Recycle Bin/Trash | Filesystem undelete tool |
| Committed in Git, then deleted | git checkout -- file | git fsck dangling blobs |
| Never committed, never saved | Hot exit backups | Editor undo stack |
| Folder syncs to a cloud service | Service version history | Service trash |
| Permanent delete, no Git, no backup | Undelete tool on another drive | Professional data recovery |
The distinctions that change a real choice: Git history is deterministic and fast but only exists for committed content; trash recovery is trivial but only for reversible deletions; undelete tools are powerful but probabilistic and degrade with every write. Preference plays a smaller role—most people should simply start at the top of the list that matches their case.
Edge Cases That Break the Simple Steps
Several situations don't fit the standard flow and deserve specific handling.
A file deleted from a multi-root workspace may have local history stored under the workspace that contained it, not the folder you currently have open; check each root's Timeline separately. Files inside .gitignored paths still get local history in current VS Code versions, but files in very large repositories or on remote development hosts (SSH, containers, WSL) store history on the remote machine, not your local disk—connect to that remote to find it.
If you're using VS Code's remote development, the Timeline and hot exit backups live on the remote server or container, and a container rebuild can wipe them. In that case, the Git repository on the remote is your best source, and container volumes configured for persistence are the only protection against rebuilds.
Deleting a file through a terminal command like rm inside VS Code's integrated terminal bypasses both VS Code's undo stack and, on Linux and macOS, the desktop trash. Recovery then falls to Git or filesystem tools only.
Finally, if the file was deleted by a branch switch or a git clean, the working-tree copy is gone, but committed content remains in history; git clean -n shows what would be removed before you run it destructively, which is the prevention step worth adopting.
Preventing the Next Loss
Recovery is easier when the file has more copies. Keep projects under Git and commit small changes often; enable a cloud sync folder for documents you edit outside repositories; and check that your OS backup (File History, Time Machine, or a Linux backup tool) is actually running, since these are off by default on many systems. VS Code's local history covers recent edits well, but it's a convenience feature, not a backup strategy—treat it as the first line of defense and Git or cloud versioning as the durable one.