0

I mistakenly have deleted all the files in the local repository via command git clean -xdf which did not commit for once since the creation. One of my codes was not working. It prompted me to use

git clean -xdf.

It removed all the files and my data. Is there any way to recover these?

halfer
  • 19,824
  • 17
  • 99
  • 186
POOJA GUPTA
  • 2,295
  • 7
  • 32
  • 60

1 Answers1

3

It is sad but the answer is no you cannot recover it using git.

Git does not know about them unless you committed them once.

If you are lucky and use git add before deleting the files accidently then you can run this command to recover

git fsck | awk '{print $3}' | xargs git show | tee searchresults.log

You can also use recovery software to recover your deleted files

Software such as photorec or Recuva, you can find plenty of them.

halfer
  • 19,824
  • 17
  • 99
  • 186
Fareed Khan
  • 2,613
  • 1
  • 11
  • 19
  • thanks but i didn't do git add so can't use it :( – POOJA GUPTA May 25 '20 at 10:20
  • you have to try `photorec` or `Recuva` software for recovering your files – Fareed Khan May 25 '20 at 13:22
  • I tried using those. I am pretty aware of testdisk and photorec . Recuva is only for windows and mine is linux. I could get the files but those are all 0 bytes. – POOJA GUPTA May 26 '20 at 06:08
  • 1
    https://askubuntu.com/questions/248334/how-do-i-recover-now-zero-sized-files, as you can see here the `OP` is also highlighting the same answer for recovering the files having `0 bytes` size. You can try again with the help of these guide of `photorec` here https://www.cgsecurity.org/wiki/PhotoRec_Step_By_Step and `testdisk` here https://www.cgsecurity.org/wiki/TestDisk_Step_By_Step – Fareed Khan May 26 '20 at 13:58
  • 1
    Thanks I tried but no help. No worries! – POOJA GUPTA May 27 '20 at 11:36
  • that just saved 6 hours of work!!! thanks – Krishan König Mar 01 '21 at 19:28
  • Thanks! I had added the files before running clean. This really saved my effort. – user3612463 May 06 '21 at 11:25