First off, add this to your project's .gitattributes
file:
*.java diff=java
Now, you're all set, you can now pass -L :<method>:file
to git log
to see all changes related to a Java method.
Here I want to see all changes related to the toString()
method inside HttpSolrCall.java
:
git log -L :call:./core/src/java/org/apache/solr/servlet/HttpSolrCall.java
Cool, right?
Other languages
To get this magic shining for other languages than Java, check out
man gitattributes
and the section Defining a custom hunk-header, there you'll see a
list of languages you can add to .gitattributes
as:
*.suffix=<language>
If your language is not listed there, you can write your own
[diff "foo"]
function to tell git log
how to identify a method (the man page
shows an example of this).
Happing code searching!