Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for and view a file deleted from the repo

I'm working on a project in git, and I know that at some time in the past (long before I had the code) there existed a file called exec.js. I want to view the contents of this file. I know which repository used to contain this file, but I don't know the exact path.

like image 641
user429400 Avatar asked Aug 07 '12 11:08

user429400


2 Answers

You could use wildcard characters in git log:

git log -- *exec.js

will give you all log messages when any file called exec.js was modified.

Once you find the deleting commit (say A), you could

git checkout A -- *exec.js

This will bring you the last version of exec.js.

If you want to view the full history of exec.js, you could use gitk:

gitk -- *exec.js

This will show you all the modifications again. If you're particularly interested in one commit, you could right click the file in the gitk dialog and then select external diff tool. This will open the external diff tool with the full files, not only the patches.

like image 144
eckes Avatar answered Oct 26 '22 17:10

eckes


You can search for that particular file inside log history using -

If you don't have filepath then

git log --diff-filter=D --summary | grep filename

If you have filepath then you can use -

git log -- filepath
git log -n 1 -- filepath

and once you get the revision you can checkout that particular revision to get that file

like image 43
Sandip Ransing Avatar answered Oct 26 '22 17:10

Sandip Ransing