0

I have a problem which is currently ruing my life. I created an folder to put files in there. Now this folder is gone but i need this! The problem is. I dont know much about git (just the basics like git pull, push, add and commit) and used a command from the internet:

git reset --hard HEAD

I think this deleted the folder. I tried to recover it in multiple ways:

  • I used Recuva to scan deleted files and folders. No chance with this :c
  • I tried some answered questions. No chances with this too
  • Restore windows to an earlier date. You know what not happened ...

The only one which seems to be working with my problem was this question: Is it still possible to restore deleted untracked files in git?

Sadly this also dont helped me. So now my question is. Is there any chance to recover this folder.

larsks
  • 277,717
  • 41
  • 399
  • 399
YoungFlyme
  • 13
  • 4
  • 1
    Nope, git won't help you here. It only knows about files you added & commited/stashed – Reactormonk Aug 19 '17 at 23:10
  • 2
    I can't really help you with your current problem but I'm going to tell you how to cope with the next problem. **Understand** the problem before you try to solve it. You copied and pasted and execute a command "from the internet" without understanding it, and this probably cause you more problems than it solved. Next time, unless you understand what the command is going to do, 100%, don't execute it, go ask for help (like you did here) before doing anything else. – Lasse V. Karlsen Aug 19 '17 at 23:12
  • 1
    Are you sure `git reset --hard HEAD` deleted your untracked folder? At least it does not always happen. – Manuel Schmidt Aug 20 '17 at 00:44
  • Have you stumbled upon any of these yet? https://stackoverflow.com/questions/7374069/undo-git-reset-hard-with-uncommitted-files-in-the-staging-area or https://medium.com/@CarrieGuss/how-to-recover-from-a-git-hard-reset-b830b5e3f60c – Marvin Aug 20 '17 at 10:20
  • @ManuelSchmidt I think the OP means uncommitted changes in an existing folder, since git doesn't touch untracked files. – cst1992 Aug 21 '17 at 10:42
  • If you use an IDE like NetBeans, there is a feature to recover deleted files that is independent of git. – cst1992 Aug 21 '17 at 10:44

2 Answers2

1

No, you can't recover your files with git.

It would have been:

  • easy, if you have stashed or commited your files.
  • difficult but possible, if you have just staged them.

But impossible in your case :-(

Recovery tools are your only last hope but if you already tried them unsuccessfully, I'm sorry to tell you that it's probably definitely lost...

You just learnt the hard way the first rule of git:

If you are not sure of what you will do, commit (to create a backup point) and after try to do your stuff.

Philippe
  • 28,207
  • 6
  • 54
  • 78
0

The essence of the git in its distribution. If you keep the repository in only one place, this is very bad.

If you using linux, you can try restore files using extundelete:

sudo extundelete --restore-directory /home/your_repo/ /dev/sda1
Quarind
  • 244
  • 2
  • 8