gitdata-recoverygit-clean

How can I recover files after accidentally running "git clean -df"?


I have accidentally run git clean -df. It removed my files from my current commit, which I had yet to push. Now, in git status, those files are marked with D, which means "deleted".

Is there any way to get those files back?


Solution

  • git clean only untracked files and not committed ones.

    You might have done other operations if you see D as the status for already committed files.

    You get back those files, do:

    git checkout .
    

    or

    git reset --hard