简体   繁体   中英

Recover deleted files from using git rm -r

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM