tags:

views:

467

answers:

2

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 lcoal 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 .".

+3  A: 

Update:

Since git rm . deletes all files in this and child directories in the working checkout as well as in the index, you need to undo each of these changes:

git reset HEAD . # This undoes the index changes
git co . # This checks out files in this and child directories from the HEAD

This should do what you want. It does not affect parent folders of your checked-out code or index.


Old answer that wasn't:

reset HEAD

will do the trick, and will not erase any uncommitted changes you have made to your files.

after that you need to repeat any git add commands you had queued up.

Alex Brown
+5  A: 
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
Brian Campbell
Thank you. I was able to get back a huge amount of files with "git reset --hard HEAD" - looks good.
Note that `git reset --hard HEAD` destroys any useful changes you have made in parent directories of the current working directory.
Alex Brown