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 .
.
I git-rm'd a few files and went on making changes before my next commit when I realized I needed some of those files back. Rather than stash and reset, you can simply checkout the individual files you missed/removed if you want:
This leaves your other uncommitted changes intact with no workarounds.
To regain some single files or folders one may use the following
This will first recreate the index entries for
path/to/file
and recreate the file as it was in the last commit, i.e.HEAD
.Hint: one may pass a commit hash to both commands to recreate files from an older commit. See
git reset --help
andgit checkout --help
for details.I had an identical situation. In my case the solution was:
If you end up with none of the above working, you might be able to retrieve data using the suggestion from here: http://www.spinics.net/lists/git/msg62499.html
I had exactly the same issue: was cleaning up my folders, rearranging and moving files. I entered: git rm . and hit enter; and then felt my bowels loosen a bit. Luckily, I didn't type in git commit -m "" straightaway.
However, the following command
restored everything, and saved my life.