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.

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.