3

I was trying to use Git in a folder then I used git glean -df and I found everything gone.

Does that mean I lost my files and is there any way to get them back?

Chris
  • 112,704
  • 77
  • 249
  • 231
E. Aly
  • 321
  • 4
  • 14

1 Answers1

4

When you ran git clean -df you asked Git to

Remove untracked files from the working tree

including directories. You also told Git to ignore its safety net.

If Git knows about the files (i.e. if they've ever been added or stashed, even if they were never commited) then they should be recoverable. Try running git fsck --cache --no-reflogs --lost-found --unreachable and then looking in .git/lost-found/ for objects that you deleted.

Otherwise there is no way for Git to retrieve them; you'll have to rely on other tools like an existing backup, filesystem snapshots, file synchronization tools, or filesystem recovery tools.

Chris
  • 112,704
  • 77
  • 249
  • 231
  • Thanks for your reply, but would please tell me how to recover them? – E. Aly Sep 16 '17 at 20:09
  • @E.Aly, as I said in my answer if those files have never been `add`ed to your repository Git can't recover them. It simply doesn't know that they ever existed. Is that the situation you're in? – Chris Sep 16 '17 at 20:10
  • @E.Aly, I just did some more reading. If the files were `add`ed they would have become tracked. `git clean -df` shouldn't have removed them. Are you sure you `add`ed them? In any case, you can try running `git fsck --cache --no-reflogs --lost-found --unreachable` and then looking in `.git/lost-found/` for objects that you deleted. But if the files were never in Git's index this won't work. – Chris Sep 16 '17 at 20:21
  • I did this and inside the `.git/lost-found/other` folder there are a list of files with type (File) and names like <1fa2f85a378526d292a60974f3b2e63d57f595ea> Are these the files? – E. Aly Sep 16 '17 at 20:28
  • @E.Aly, they're non-commit Git objects. Some may represent files you've lost. Please open them up and see if you can find the lost files. – Chris Sep 16 '17 at 20:34
  • Thanks a million @Chris, it did work and I found my lost files... I don't really know how to thank you! – E. Aly Sep 16 '17 at 20:39