testdisk icon indicating copy to clipboard operation
testdisk copied to clipboard

Lost all project files after git reset --hard β€” how to recover ?

Open ashishmi8113 opened this issue 9 months ago β€’ 1 comments

Description

I encountered an issue where all files in my JavaScript project folder (D:\JavaScript_Repo) were deleted after running: git reset --hard

I was trying to fix some line ending warnings (LF will be replaced by CRLF), and ran git reset --hard to clear changes. But it seems to have removed all my project files (not just untracked ones).

What I Did

  1. Cloned repo using Git Bash/PowerShell.
  2. Installed node_modules.
  3. Got repeated warnings like: warning: LF will be replaced by CRLF the next time Git touches it
  4. Ran git config --global core.autocrlf true
  5. Then ran: git reset --hard

But after that, most of my files and folders were deleted, including node_modules, src, etc.

πŸ” What I’ve Tried

  • I checked git reflog β€” but couldn't recover untracked files.
  • Using PhotoRec now, but it’s hard to recover the exact folder structure.
  • I want a safer or Git-based method if available.

❓ What I Need Help With

  • Is there any way to recover the files removed by git reset --hard?
  • Can GitHub/Git help in recovering untracked but deleted files?
  • What are the safest practices to avoid this kind of loss in the future?

🧠 Additional Info

  • Windows 10
  • Local repo, not published on GitHub yet
  • Files were not committed before deletion

πŸ™ I’d really appreciate guidance on recovery options (Git or non-Git) β€” this is a serious project loss for me.

ashishmi8113 avatar Apr 12 '25 06:04 ashishmi8113

You can try

  • TestDisk, Advanced, Undelete. Be careful to store the recovered files on another partition than the source partition.
  • "git fsck --lost-found" and check files in .git/lost-found/
  • "git reflog show" followed by a "git reset XXXX" where XXX is the commit you want

cgsecurity avatar Apr 12 '25 08:04 cgsecurity