Suppose a commit X changes line 500 of the file foo.java. I want to see all the past commits that have changed this line.
Inspired by this thread, I understand that since git 1.8.4, we can use the -L
option of git log
to view the evolution of a specific line range. So I use git log -L 500,500:foo.java
However, I got a error saying
file foo.java has only 450 lines
I suspect that the reason is that my git log
command operates on the HEAD. But between commit X and HEAD, the file foo.java has been modified and ended up with only 450 lines.
So, how can I get all the commits that have changed this line 500 from commit X?