Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert a "git rm -r ."?

Tags:

git

git-rm

I accidentely said git rm -r .. How do I recover from this?

I did not commit.

I think all files were marked for deletion and were also physically removed from my local checkout.

EDIT: I could (if I knew the command) revert to the last commit. But it would be a lot better if I could just undo the git rm -r .. Because I am not really sure what I did after the last commit and before the git rm -r ..

like image 902
user89021 Avatar asked Jan 24 '10 02:01

user89021


People also ask

What does git rm -- cached R do?

The Git rm –cached flag removes a file from the staging area. The files from the working directory will remain intact. This means that you'll still have a copy of the file locally. The file will be removed from the index tracking your Git project.


1 Answers

git reset HEAD 

Should do it. If you don't have any uncommitted changes that you care about, then

git reset --hard HEAD 

should forcibly reset everything to your last commit. If you do have uncommitted changes, but the first command doesn't work, then save your uncommitted changes with git stash:

git stash git reset --hard HEAD git stash pop 
like image 81
Brian Campbell Avatar answered Sep 20 '22 23:09

Brian Campbell