gitcommitdelete-fileundorm

How to undo git rm -rf dirname without a first commit?


I did:

git init
git add .
git rm -rf dirname

Looking at other answsers, git reset --hard HEAD, git checkout -f and git reflog did not work, apparently because there is no HEAD to go back to, nor a commit to get the files back from.

Is there a way to get the files back?


Solution

  • There is no way.

    Usually, git rm checks the files have already been committed before deleting them, so you don't lose any of your work. However, using -f overrides this check.

    In short: