列出其更改(差异)包含给定字符串的文件?

List files whose changes (diff) contain a given string?

是否有一个简单的 git 命令来列出差异包含给定字符串的文件,或者我是否必须迭代?

我需要与其他更改分开进行重构(方法名称更改),因此我需要识别差异包含新方法名称的文件。

您可以使用 diff 命令的 -S(字符串)或 -G(正则表达式)参数来过滤特定字符串。

git diff --name-only -S"your_method_name"

并且只有在更改中出现此特定字符串的文件才会显示在列表中。

the doc这里看看:

-S<string>

Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file. Intended for the scripter’s use.

It is useful when you’re looking for an exact block of code (like a struct), and want to know the history of that block since it first came into being: use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.