Git: Show all commits that affect a certain line
I found a bug on a particular line, and need to track down the history for that line. This is easy enough with git blame
, but in this case I'm getting false positives. There was a previous check-in that changed whitespace on that line. Obviously that was not the commit that introduced the bug.
Using git log
with the -L
flag you can specify a file and and range of lines to search through.
git log -L 57,57:index.php
This will show all the commits in index.php
where there was a change on line #57.
See also: Finding commits that match a search term