Finding Deleted File with GitHub
Published on Jan 27, 2020
This is such a handy little thing that I've used a fair amount. It's quite frequent that I refactor code, sometimes even breaking the code into new projects.The challenge with this is the history of the file disappears with it making it difficult to remember the previous state of that file. Enter git log
Using git log to find a deleted file
The key piece to making this work is that you, at a minimum, need to know the name of the file and its previous location. With this information you can use the following code to find the last commit to this file:
git log --all --{path to file}
This will return a list of commit messages and the associated commit ID. Once you find the right commit, you can navigate to GitHub and view the commit with the ID:
https://github.com/{your username or company name}/{your repository name}/commit/{commit id}
Once you have this URL you can view the full history of this file prior to it being deleted.