0

I wanted to remove a file from my git staging to commit. So I did "git reset --hard". At some point in trying to commit and push the files, I deleted the files inside the folders. So the folders are now shells. I tried "git reflog" and "git reset" to a previous log, but I cannot get the files back. I have however some static files. How did I delete the files within the folders? Can I recover the files?

$ git reflog
189dab7 (HEAD -> master, origin/master) HEAD@{0}: reset: moving to HEAD
189dab7 (HEAD -> master, origin/master) HEAD@{1}: checkout: moving from 189dab70a4f924bb575b55162012516e2867730a to master
189dab7 (HEAD -> master, origin/master) HEAD@{2}: checkout: moving from master to remotes/origin/master
189dab7 (HEAD -> master, origin/master) HEAD@{3}: commit: large commit
8f4498f HEAD@{4}: reset: moving to 8f4498f
8f4498f HEAD@{5}: reset: moving to HEAD
8f4498f HEAD@{6}: reset: moving to HEAD
8f4498f HEAD@{7}: reset: moving to HEAD
8f4498f HEAD@{8}: commit: authors and quote ranks
8524f92 HEAD@{9}: commit: 'navigation'
7317450 HEAD@{10}: commit: Angular
373db2e HEAD@{11}: commit (initial): PreMean
S George
  • 9
  • 1
  • If you're new to git you should stay away from commands such as reset and clean, with the wrong options they do much more harm than you intend, and much of that harm, such as deleting files, does not come with an undo function. – Lasse V. Karlsen Jul 11 '20 at 20:50

2 Answers2

0

I wanted to remove a file from my git staging to commit. So I did "git reset --hard"

What? No! A simple git reset -- aFile is enough.
A git reset --hard would override all files from the working tree (your disk) by the content of HEAD (and reset the index as well).

git reflog applies only if you committed those files, but here, I suspect you did not.

So, as in here, try the git fsck --lost-found option:

for b in $(git fsck --lost-found | grep blob | awk '{print $3}'); do \ 
   git cat-file -p $b > ../$b ;\
done
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Do another git reset to change history by rolling forward instead of rolling backwards. So you’ll have to do git reset –-hard <commit id for authors and quote ranks>

git reset –-hard 8f4498f