这个问题在这里已经有了答案:
Search all of Git history for a string? [duplicate]
(3 个回答)
How to grep Git commit diffs or contents for a certain word
(8 个回答)
3年前关闭。
是否有一个简单的 git 命令来列出差异包含给定字符串的文件,或者我是否必须迭代?
我需要与其他更改分开提交重构(方法名称更改),因此我需要确定差异包含新方法名称的文件。
最佳答案
您可以使用 -S
(字符串)或 -G
(regexp) diff
的参数命令以使用特定字符串进行过滤。
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.
关于git - 列出更改 (diff) 包含给定字符串的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52016003/