Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

Once upon a time, there was a file in my project that I would now like to be able to get.

The problem is: I have no idea of when have I deleted it and on which path was it at.

How can I locate the commits of this file when it existed?

1 Answer

0 votes
by (27.5k points)

You can use the following command if you do not know the exact path:

$ git log --all --full-history -- **/thefile.*

Use the following command If you know the path the file was at: 

$ git log --all --full-history -- <path-to-file>

This command should display a list of commits in all branches which touched that file. Now you can find the version of the file you want, and display it with...

$ git show <SHA> -- <path-to-file>

Or restore it into your working copy with:

$ git checkout <SHA>^ -- <path-to-file>

The caret symbol (^), which gets the checkout prior to the one identified, because at the moment of <SHA> commit the file is deleted, we need to look at the previous commit to get the deleted file's contents

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers

500 comments

108k users

Browse Categories

...