1

I accidentally deleted almost all of my file by executing git clean -df command in terminal. Is there any way to undo this action? Now all my files in my computer is gone. Thank you.

KKK
  • 53
  • 1
  • 10
  • Solution is reported here https://stackoverflow.com/questions/25722470/how-can-i-recover-files-after-accidentally-running-git-clean-df – ES2018 Oct 28 '18 at 09:20
  • "all my files in my computer", can you clarify what you mean by that? Did you put a repository on the root of your system disk or something like that? Note that `git clean` will, when given the right options, remove files that aren't tracked and unless you have a separate backup of them, then *no*, there is no way to ask *git* to restore those files. – Lasse V. Karlsen Oct 28 '18 at 22:40
  • @ES2018 That is not a very good answer for this question as the conclusion there is that something else must've been done as well, since `git clean` only removes *untracked* files. – Lasse V. Karlsen Oct 28 '18 at 22:42
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+clean – phd Oct 29 '18 at 19:24

3 Answers3

1

sadly, the short answer id no.

Unless you added file or committed them once, git has no mean to know about them; that is exactly what you meant with your git clean (from man git clean):

Cleans the working tree by recursively removing files that are not under version control

thus git cannot help you here...

OznOg
  • 4,440
  • 2
  • 26
  • 35
1

If anyone facing same issue and using any modern IDEs (like PHP storm or Intelli j etc.), these IDEs store local files in their change history.

I used git clean -f -d and one of my untracked files was removed from code base, however I was able to recover it by:

Going to View menu of PHP storm and clicking recent changes.

I am sure other IDEs would have same change history log somewhere just google it.

Nitin
  • 59
  • 2
  • 8
0

In general every action done on git is logged in git reflog. Then you see the git hashtags of each action done on git. So, you can write that command and then do git reset --hard to the hashtag of the command before you did git clean. So for example if you did git commit ... (and git hashtag is #exampl) before git clean ..., you write in your terminal: git reset --hard #exampl and you're back to the state you were before you did your unwanted command.