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 .
.
undo git rm
undo git rm -r
undo git rm -rf
Uncommitted changes
includesnot staged changes
,staged changes but not committed
.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:This should do what you want. It does not affect parent folders of your checked-out code or index.
Old answer that wasn't:
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.If you've committed and pushed the changes, you can do this to get the file back
Should do it. If you don't have any uncommitted changes that you care about, then
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
:Get list commit
For example, Stable commit has hash:
45ff319c360cd7bd5442c0fbbe14202d20ccdf81
There are some good answers already, but I might suggest a little-used syntax that not only works great, but is very explicit in what you want (therefor not scary or mysterious)