如何列出单个Git提交中在差异中具有特定文本更改的所有文件?

3

我在另一个回答中发现,我可以使用以下命令列出提交中更改的文件:

git diff-tree --no-commit-id --name-only -r bd61ad98

我该如何仅显示diff中包含特定文本更改的文件?

顺便提一下,您也可以使用 git diff(这可能是我首先想到的方法,因为我尝试保持我的常用命令集最小化)。然后,您就不需要 -r--no-commit-id 标志,但您必须指定与父级 (bd61ad98^) 进行比较的差异。 - Mark Adelsberger
1个回答

3
你可以使用 -G 标记

-G<regex>

Look for differences whose patch text contains added/removed lines that match .

To illustrate the difference between -S<regex> --pickaxe-regex and -G<regex>, consider a commit with the following diff in the same file:

+    return !regexec(regexp, two->ptr, 1, &regmatch, 0);
...
-    hit = !regexec(regexp, mf2.ptr, 1, &regmatch, 0);

While git log -G"regexec\(regexp" will show this commit, git log -S"regexec\(regexp" --pickaxe-regex will not (because the number of occurrences of that string did not change).

See the pickaxe entry in gitdiffcore[7] for more information.

例如:

git diff-tree --no-commit-id -G<regex with what you are looking at> --name-only -r bd61ad98

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接