The solutions offered didn't exactly fit my needs, this solved my issue.
( START_DIFF=abc123 END_DIFF=123dcf # loop over all the files that have changed inside the diff # you can add a `| grep '<ext>$'` to the end of `--name-only` # if you need to be more aggresive with the filtering / or # make it go faster... for file in $(git diff $START_DIFF $END_DIFF --name-only); do # loop over every line of the diff FOR that file. while IFS= read -r line; do # prepend the file name to every line echo "$file:$line" done < <(git diff $START_DIFF $END_DIFF $file) done ) | grep what-youre-looking-for
I could not get the line numbers working, but I didn't really need them to get them to work. The prepended filename was enough for me.
My exact issue:
Find all the files that added either a from __future__ import .. or a -*- coding: utf-8 -*- out of 70+ files.
( START_DIFF=branch-a END_DIFF=HEAD for file in $(git diff $START_DIFF $END_DIFF --name-only); do while IFS= read -r line; do echo "$file:$line" done < <(git diff $START_DIFF $END_DIFF $file) done ) | grep ':+' | awk '(/import/ && /__future/) || (/coding/)'
The output looks like this:
.... app/tests/test_views.py:+# -*- coding: utf-8 -*- app/tests/test_views.py:+from __future__ import absolute_import app/tests/test_views.py:+from __future__ import division app2/tests/test_views.py:+from __future__ import division ...