Search code examples
gitgit-rm

recover file after git rm with no previous history


Not sure there´s a solution to this:

I accidentally staged a directory with:

git add *

then, upon seeing this, I did (major, major mistake, should have of course unstaged)

git rm -r my_directory

To top it all, I followed up with:

git commit -m ¨horrible commit¨

Now the files are nowhere to be found. Is there a way to recover the files?

Thanks


Solution

  • If I'm not mistaken, the git rm shouldn't have deleted this directory but complained:

    error: the following file has changes staged in the index: my_directory
    (use --cached to keep the file, or -f to force removal)
    

    So the directory should still be there...

    If you ran it with -f, sorry, then I guess there's nothing you can do.