Let's say we see a line in our code:
a = foo.bar + xyz.abc + fn() * 3;
now we know foo.bar
is the "buggy" code or the code causing some issue. And git blame
will show that the line is by Michael. However, Michael might not have checked in that part of the code. He might have only altered the * 3
part. So in this case, how could we find the first occurrence of the foo.bar
in the repo, and find out who wrote it or added that in?
I thought of using
git show HEAD:path/to/file.js | grep 'foo.bar'
and then
git show HEAD~1:path/to/file.js | grep 'foo.bar'
git show HEAD~2:path/to/file.js | grep 'foo.bar'
and just increase the 2
to 3
, 4
, etc, until I don't see that line showing the foo.bar
.
But what if the number can be big, like 120
or 343
. Is there a better way or faster way?