1

I have a hobby project with many commits, and somewhere in the past I probably accidentally removed a file which is committed/pushed.

Is there a way to find / restore the file? (or getting the contents, it's a text file).

I don't know in which commit it has happened.

Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119

1 Answers1

1

If you know the file name, you can find when it was deleted

git log --full-history -1 -- aFile

From there, knowing the commit (thanks to the previous query), you can restore it with:

git restore <commit>~ -- aFile

The ~ would take the commit parent (where the file was still there)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I found out I cannot use git commands directly from the console (as I use GitHub) and Eclipse, but I will try to find a way to enter git commands. – Michel Keijzers Apr 23 '20 at 08:06