tags:

views:

33

answers:

4

I've got a file that's been installed on my system that is known to be part of a git repo. I'd like to find out which commit(s) (re-)introduced that version of that file, ie which commit is responsible for putting the file in its current state.

I know that the file is in the repo because git show $(git hash-object $the_file) works.

At this point I don't really need a solution to this example problem, I'm more just hoping to learn a bit more about how to navigate git's data structures.

A: 

How about git log <the file>?

adamk
That would tell me which commit introduced the *current version* of the file. It also requires that I know where in the repo the source file is located, and I think also that it hasn't gone through a rewrite that would prevent git from identifying one of its revisions as a copy.
intuited
+1  A: 

If the current version introduce a particular comportement you can test (by a unit test program, a shell script, etc.), you can use the git bisect tool to find the commit responsible for this comportement.

Here is the manual of this command: http://www.kernel.org/pub/software/scm/git/docs/git-bisect.html

Benoit Courtine
interesting idea, but in this case the repo doesn't have a toolset which can test the «behaviour» of the program, and I'm not really sure what any revision of that file is supposed to do. In any case, I'm more interested in figuring out how to traverse the git data structures than I am in solving this particular problem.
intuited
A: 

Get the hash of given version of file using git hash-object <file>, then use git log --raw -- <file>, and search through pager (it is '/' in 'less' and in 'more') for this hash.

Jakub Narębski
+1  A: 

Thanks to @Jefromi for pointing out the duplicate. Since this question hasn't been closed as a duplicate, I'm going to answer it with a reference to the accepted answer on that other thread, which contains a perl script that seems to do just what I want, with more or less optimal efficiency.

intuited