user5047085
user5047085

Reputation:

Find most recent commit with certain filename

I don't think Git can do this, I feel like I have asked this question before...

Is there a way to search commit history, to find the most recent commit that has a file with a certain name? We renamed or removed a file, and I am trying to recover it / find it.

I get the feeling I will here an answer like "git works off of diffs and not file names.." ok lol thx, but what I am gonna do now lol

Upvotes: 2

Views: 57

Answers (1)

osbel
osbel

Reputation: 46

I would suggest the following command:

git log --name-only > gitlog.txt

Then look inside your newly created file (gitlog.txt) using vi or any text editor and use the find feature to search for your filename.

For Example:

I modified filename: homer/user/git_repo/mytest.py during a previous commit. Lets assume I didn't add the filename to my commit message(usual way)

I would look for it this way using terminal and Unix variant:

$ git log --name-only > gitlog.txt
$ vi gitlog.txt

while in vi press the / key, and type your filename, then press enter. Press n to search for more results.

$ /filename_goes_here

Upvotes: 1

Related Questions