我在另一个回答中发现,我可以使用以下命令列出提交中更改的文件:
git diff-tree --no-commit-id --name-only -r bd61ad98
我该如何仅显示diff中包含特定文本更改的文件?
-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, ®match, 0); ... - hit = !regexec(regexp, mf2.ptr, 1, ®match, 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
git diff
(这可能是我首先想到的方法,因为我尝试保持我的常用命令集最小化)。然后,您就不需要-r
或--no-commit-id
标志,但您必须指定与父级 (bd61ad98^
) 进行比较的差异。 - Mark Adelsberger