1

My uncommitted files deleted by git reset --hard command. How can I recover? I tried git reflog etc but it stays at 0%.

Checking object directories: 100% (256/256), done.ories:   0% (1/256)

enter image description here

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • 1
    Can you share the output of your `git reflog` and/or which command you did then? – Gaël J May 19 '21 at 19:27
  • @GaëlJ https://prnt.sc/134ru9u – Berk Birkan May 19 '21 at 19:47
  • 3
    Ah, I didn't notice you said uncommited files, these one are lost if you mean uncommited in the sense of never tracked by Git – Gaël J May 19 '21 at 20:07
  • 2
    Does this answer your question? [Recovering added/staged file after doing git reset --hard HEAD^?](https://stackoverflow.com/questions/1108853/recovering-added-staged-file-after-doing-git-reset-hard-head) – dejanualex May 19 '21 at 20:54

2 Answers2

2

For staged file, you can check the output in git fsck, but for private files, as in not even staged (git add), then those files are gone.
git reflog would only help to restore past commits.

Double-check with:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

If you have staged your file, you can try git fsck --lost-found then take a look into .git/lost-found/other and using git show <SHA> check what you can recover

So I've recreated your scenario: (created new_file then stage it, and git reset --hard afterwards)

enter image description here

Checked the content of .git/lost-found/other enter image description here

Then recover the content git show <SHA>: enter image description here

Fortunately in my case I had a small number of commits so it was easy to find it.

dejanualex
  • 3,872
  • 6
  • 22
  • 37