I am using Git to version control a large java project.
Is it possible to know at which commit a certain method is added or removed from a certain class?
You can search for the name of the method and you will find the all commits that entered or deleted that string:
git log -c -S'methodName' /path/to/file.java
Another solution is to find the last commit in which that method exists:
$ git blame --reverse START_COMMIT.. file.ext
START_COMMIT is a commit in which you know for sure the method still exists. You will get a git blame output in which you can see the last commit in which that method existed, something like:
f590002e (user 2014-01-13 17:27:25 +0000 26)     public void save() {
f590002e (user 2014-01-13 17:27:25 +0000 27)         JPA.em().persist(this);
f590002e (user 2014-01-13 17:27:25 +0000 28)     }
                        Try the "pickaxe" option of git log:
git log -S<your-method-name>
That will give you all the commits where the string  is added or removed.
Note there is no space after the -S.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With