Stack Overflow: find and restore a deleted file in a Git repository

Amongst all the suggestions there I had to find something, that fits my scenario.

First find the commit ID, that includes the deletion of the resp. file (use either --summary or --raw!) (git log displays its output through $PAGER, presumably the utility less):
$ git log --summary # find the file and the commit ID (in the pager)
$ git log --raw     # find the file and the commit ID (in the pager)

Now use the commit_ID to specify, that you are interested in  a commit to that file but before that commit_ID, therefore the “^” after commit_ID:

$ git checkout commit_ID^ THE_FILE


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.