Hey everyone, I'm feeling pretty desperate right now and I'm hoping someone can help. I had a complete Next.js portfolio site on my Mac, and everything was pushed to GitHub. The repo included all my source code, app folder, components, images—everything. I was having issues with large file sizes, so I started cleaning the .next folder. A user advised me to run a command that rewrote the repository history, deleted the remote origin, and left me with a very basic repo containing only package.json. When I pushed this, GitHub got updated and now only shows this minimal version of my project.
To make things worse, during the cleanup, I accidentally deleted the actual project folder on my machine. The folder still exists, but it only contains the .git directory, .history, package.json, and node_modules. All my actual files, images, pages, components—everything—is gone.
I checked GitHub but found no old commits, ran `git fsck` but there's nothing recoverable, and it looks like my APFS snapshots don't have my user files in them. I also don't have Time Machine set up. I tried running PhotoRec to recover files and ended up with thousands of random files but most are corrupted or gibberish.
I genuinely don't know whether the source files could still be on the disk, if I can restore anything from GitHub, or if PhotoRec has any chance of getting back my JavaScript files. Is there any hope of getting back my GitHub repo or my Next.js project files, or am I pretty much out of luck? Any advice would be greatly appreciated—thanks!
2 Answers
I feel for you! That sounds super frustrating. You might want to check if you’ve got an audit log on GitHub which might list pushed commits. If there's any chance of a backup, now is the time to grab it. And remember, PhotoRec might still help; just don't lose hope yet!
Great tips! And remember, even if it seems ruined, there might be remnants of useful data waiting to be found.
First off, don't panic! It sounds like you may still have a chance to retrieve your data. If you haven't already, try running `git reflog`. This command tracks updates to the branches and can help you find lost commits.
Also, GitHub keeps a log of commits as long as they haven't been garbage collected. If you remember any good commit hashes, you might be able to retrieve them from GitHub. Just make sure to check their support articles for guidance on this. Good luck!
Definitely give that a shot! And if GitHub support can help retrieve some history, that would be a win. Just keep them in the loop about what’s going on with your repo.
Yep, definitely check the reflog! It might point you to commits you thought were lost.

I hear you! It's a tough situation, but sometimes software can surprise you. Have you looked into cloud backups you might have overlooked?