git - 列出更改 (diff) 包含给定字符串的文件?

标签 git git-diff

这个问题在这里已经有了答案:





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/

相关文章:

git - 如何检查远程 Git 存储库的状态?

git - araxis merge for mac 和 git diff

Git 说一个文件被修改了,即使它没有

git - 从 git patch 中删除行而不损坏

git - 在 Git 中管理发布分支

git - 获取任意 git 对象的 SHA 的最简单方法?

iphone - 不能做 git stash apply

Git hook 脚本失败,但脚本在终端中运行良好

分支 A 和 B 之间的 Git diff,选择一组文件模式更改,将这些更改重置到分支 A

git diff 不会打印错误文件名的错误