If a file disappeared from your Mac project before you committed it, check the Mac’s Trash and any Time Machine or cloud recovery first. Then check Git: it can restore a deleted file if the version is in the index or a commit, and may uncover content saved as an unreachable object. If the file existed only as unsaved or unstaged working-copy content, Git may have no copy. Work through these checks before creating new files in the project.

1. Check Trash and search the Mac

Open the Trash from the Dock and look for the file by name. If you find it, control-click it and choose Put Back to return it to its original location, or drag it somewhere safe. Apple also recommends searching with Spotlight if the file may have been moved or renamed. For a project folder in iCloud Drive, check Trash and iCloud’s Recently Deleted or Data Recovery options as well; Apple says eligible deleted iCloud Drive files can generally be recovered within 30 days. Apple’s iCloud recovery instructions

If a developer tool deleted the file directly, or Trash has been emptied, move on. Don’t assume every deletion passes through Trash.

2. Look in Time Machine, including local snapshots

If Time Machine was enabled, connect the backup disk if available. In Finder, open the folder that used to contain the file, use Spotlight to open Time Machine, then browse the timeline or backup arrows to a date before deletion. Select the file and click Restore. Apple says restored items return to their original location, so consider restoring to a separate location if you want to compare versions before replacing anything. Apple’s guide to restoring Time Machine items

A disconnected backup disk does not necessarily rule out recovery. Time Machine can use local snapshots stored on the Mac, but these are temporary: Apple says snapshots are generally saved hourly and kept for 24 hours, with additional snapshots subject to available space. They exist only when Time Machine is in use, and are not a substitute for an external backup. About Time Machine local snapshots

3. Restore a tracked file from Git

Open Terminal, change to the project directory, and check the file’s status before restoring anything:

git status --short

If the deleted path appears and the file was tracked, restore it from the index with its project-relative path:

git restore -- path/to/file.ext

This copies the indexed version into the working tree. If the index did not contain the file, but it exists in the latest commit, restore from HEAD instead:

git restore --source=HEAD -- path/to/file.ext

The distinction matters: git restore defaults to the index for a working-tree restore; --source=HEAD explicitly selects the latest commit. A restore overwrites the specified working-tree path with the selected version, so first copy aside any file there whose contents matter. Git documents these restore sources and behavior in its git restore manual.

These commands cannot recover a brand-new untracked file or edits that were never staged or committed. Git only knows about versions that made it into its index, commits, or object database.

4. Search Git’s unreachable objects as a last resort

Sometimes Git has stored a file’s content even though no branch or commit points to it—for example, a version that was staged and then removed from the index. From the project directory, inspect unreachable objects:

git fsck --unreachable

Git may report an unreachable blob followed by an object ID. To inspect a candidate without changing the project, use:

git cat-file -p OBJECT_ID

Replace OBJECT_ID with the reported ID. If the output is the missing file, redirect it to a recovery copy outside the project, for example:

git cat-file -p OBJECT_ID > "$HOME/Desktop/recovered-file.txt"

The filename and extension here are examples; choose a destination and name that suit the file. Git blobs store content, not the original path, so you may need to inspect candidates and identify the right name yourself. git fsck reports unreachable objects, and its --lost-found option can write blob content under .git/lost-found/other/; neither method guarantees a recoverable version. Git’s git fsck documentation

When no recovery source has the file

If Trash, backups, cloud recovery, the Git index, commits, and unreachable Git objects do not contain it, there may be no copy available through these documented tools. In particular, an untracked file that was never staged is outside Git’s saved history. Check your editor’s own local history or another backup service if you used one; availability and recovery steps depend on that product. Preserve the project as it stands while you investigate, and save any recovered content under a new name until you confirm it is the version you need.

Sources