Using git gui blame difficult to use in scripts, and while git log -G and git log --pickaxe can show you when a method definition appeared or disappeared, I did not find a way to make them list all the changes made in the body of your method.
However, you can use the gitattributes and textconv to put together a solution that does just that. Although these features were originally designed to help you work with binary files, they also work here.
The key is to have Git remove all lines from the file, except those that are of interest to you, before performing any diff operations. Then git log , git diff , etc. Only the area you are interested in will be seen.
Here are the outlines of what I am doing in another language; You can customize it for your needs.
Write a short shell script (or another program) that takes one argument - the name of the source file and displays only the interesting part of this file (or nothing if none of them are interesting). For example, you can use sed as follows:
#!/bin/sh sed -n -e '/^int my_func(/,/^}/ p' "$1"
Define the Git textconv filter for the new script. (For more information, see the gitattributes page.) The filter name and location of the command can be whatever you like.
$ git config diff.my_filter.textconv /path/to/my_script
Tell Git to use this filter before calculating the diff for the corresponding file.
$ echo "my_file diff=my_filter" >> .gitattributes
Now if you use -G. (pay attention to . ) to list all the commits that make visible changes when applying the filter, you will have exactly those commits that interest you. other options that use Git diff routines, such as --patch , will also get this limited view.
$ git log -G. --patch my_file
Voila!
One useful enhancement you might want to make is for your script filter to accept the method name as its first argument (and the second as a file). This allows you to specify a new method of interest by simply calling git config , instead of having to edit your script. For example, you can say:
$ git config diff.my_filter.textconv "/path/to/my_command other_func"
Of course, the script filter can do whatever you like, accept more arguments, or something else: there is more flexibility than what I showed here.
Paul Whittaker Jun 04 '13 at 23:45 2013-06-04 23:45
source share