1

Unknowingly, without finding out what the command does, i used the git rm -r command on a folder of a proyect thinking it would delete all files only inside that folder. To my surprise, all my files where deleted.

I found a way to recover my files from my last commit (about 3 days ago) using the following commands:

git reset
git checkout -- $(git ls-files -d)

Now my question is, all the work i have done during that last 3 days, is there ny way i can recover this? Even if its just the files so i can copy and paste. All the files deleted where atleast added to the repository, im trying to find a way to either recover my project the way it was before i did git rm -r or if i can recoverd the files individual so i can copy and past. Thank you for any help

alexwhan
  • 15,636
  • 5
  • 52
  • 66
Carlos
  • 1,261
  • 11
  • 27
  • 1
    You've learned a very valuable lesson today. Commit often. And I'm guessing you'll never forget what that command does again. – Dason Nov 24 '15 at 02:52

1 Answers1

0

As long as the files are added to the repo (not yet committed), there is a chance to recover them.

See "Recovering added file after doing git reset --hard HEAD^"

git fsck --cache --no-reflogs --lost-found --dangling HEAD
cd .git/lost-found/other

But the surest way remains to commit often indeed.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250