提供的解决方案并不完全符合我的需求,这解决了我的问题。
(
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
我无法让行号工作,但我真的不需要它们来让它们工作。附加的文件名对我来说已经足够了。
我的确切问题:
在 70 多个文件中查找添加了 afrom __future__ import ..
或 a的所有文件。-*- coding: utf-8 -*-
(
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/)'
输出如下所示:
....
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
...