Antonio Sesto
Antonio Sesto

Reputation: 3154

recover files due to mistakes with git

I made the following steps:

Then I made two mistakes:

Now the directory F is empty and I have lost all my files. Is there any way to recover the files?

Upvotes: 0

Views: 45

Answers (1)

matt
matt

Reputation: 534893

Is there any way to recover the files?

No.

This was an interesting perfect storm of errors. Saying

git reset --hard HEAD

is very violent; it means, restore everything in the working tree to be exactly the same as the most recent commit. All uncommitted changes are thus erased.

Fortunately, however, a hard reset does not touch untracked files. So the new files you created should still be there, right?

Wrong, because you first said

git add .

This turned your new untracked files into tracked files! So the hard reset erased them completely.

The files were never committed so they were lost completely. But even if they had been committed, you would then have thrown that commit away when you deleted the .git folder!

So basically you erased your files without backing them up first, and then, just in case you had backed them up, you threw away the backup.

Upvotes: 4

Related Questions