At first the answer is not git. Check the history of shell commands. Well, if you didnโt use the shell with the command history, then you donโt ...
Git answer. Usually you cannot find THE $ commit. Typically, the same content could be part of many commits, and I donโt think that git keeps a log of what you checked for one file (it keeps a log of previous HEAD values)
Here is the brute force of script git-find-by-contents. Call it your $ filename as a parameter, and it will show you all the commits where this file was included. As the name says, he is looking for content. That way, it will find files with any name if the content matches.
#! /bin/sh tmpdir=/tmp/$(basename $0) mkdir $tmpdir 2>/dev/null rm $tmpdir/* 2>/dev/null hash=$(git hash-object $1) echo "finding $hash" allrevs=$(git rev-list --all)
I would not be surprised if there is a more elegant way, but it worked for me a couple of times in such situations.
EDIT: here comes a more technical version of the same problem: What commit does this blob have?
source share