Search code examples
gitmacosvisual-studio-codefile-recovery

Accidentally copied over a folder in MacOS. Both folders had git init. Any way to restore untracked files?


I was programming in Folder A. I accidentally replaced the contents of Folder A with the contents of Folder B using Finder. Both folders were initialized with git, though Folder A had a ton of untracked changes (I was going to push today)

Once I realized the colossal error of my ways, I tried to fix what I could. There was no "Undo" option in Finder. I still had VS Code open, and was able to manually restore any files that happened to be open in the IDE, as well as anything that was tracked that was slated for deletion.

The rest is gone isn't it? Is there any place I can look to try to find these files? Does VS Code have a cache? They're not in Trash (why?). They weren't staged, so this answer doesn't help. Does VS Code have a cache? Does spark have a cache? I downloaded DiskDrill but that didn't seem to help.

Is there any way I can restore any of my work?


Solution

  • The rest is gone isn't it?

    Yes, sorry.

    To avoid this in the future...

    • look into backup options
    • make smaller commits (you don't have to push every commit)
    • work in a branch and push to a remote repository periodically as a backup

    Does VS Code have a cache?

    Check ~/Library/Application Support/Code and ~/.vscode

    They're not in Trash (why?)

    Depends on how you deleted the files. Moving files to the Trash is optional and many commands simply delete files and folders.

    I downloaded DiskDrill but that didn't seem to help.

    With old spinning disk hard drives deleted files weren't actively deleted and could be recovered if you didn't do too many writes to the disk. With new SSDs recovery of deleted files is effectively impossible because of trim.

    That's why the DiskDrill FAQ has this warning...

    ⚠️ So do not use the drive or disk that has the lost file on it at all, until you have completed the Disk Drill scanning and recovery process on your Mac.

    See Variables That Impact File Recovery Chances.