我正在编写一个小测试套件,该套件运行要在一堆输入文件上进行测试的工具。对于每个输入文件,该工具都会创建相应的输出文件(两者都是 XML 格式)。输入和输出文件在 Git 存储库上签入。
输出文件带有工具编译时的时间,因此输出文件在被测试工具重新创建后肯定会被修改。
为了快速了解输出是否已更改(当我修改工具的源代码时),我想检查节点 OutputFingerprint
的内容是否已更改(对输出文件的相关部分)。
阅读 git-diff
的手册,我发现有-G
选项:
-G<正则表达式>
查找添加或删除的行与给定的 匹配的差异。
不幸的是,他们没有提供如何使用 -G
选项的示例。
我的第一个想法是简单地写,
git diff -GOutputFingerprint
但这是错误的:
> git diff -GOutputFingerprint
error: invalid option: -GOutputFingerprint
接下来的想法是将正则表达式放在斜杠中,但这也不成功:
> git diff -G/OutputFingerprint/
error: invalid option: -GC:/Program Files/Git/OutputFingerprint/
此外,简单地在 -G
和 OutputFingerprint
之间放置一个空格code> 不起作用:
> git diff -G OutputFingerprint
fatal: ambiguous argument 'OutputFingerprint': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
当我在没有任何参数的情况下调用 git diff 时,我得到了修改:
- <OutputFingerprint>e45807ca76fc5bb78e9e928c6fb7eed6</OutputFingerprint>
+ <OutputFingerprint>d0846851bc9d52b37f7919def78660a2</OutputFingerprint>
另一个想法是使用 git diff -S".*OutputFingerprint.*" --pickaxe -regex,但这也没有成功。
git --version
给我 git version 1.7.3.1.msysgit.0
如果相关的话。
当我询问 git diff --help 时,提供的手册向我显示了 -G 选项。
那么,有人可以为我提供一个如何正确使用 git diff -G 的示例吗?
I'm writing a little test suite that runs the tool to be tested over a bunch of input files. For each input file, a corresponding output file is being created by the tool (both are in XML). Input and output files are checked in on a Git repo.
The output files carry the time when the tool was compiled, so the output files are surely modified after they were re-created by the tool being tested.
To have a quick glimpse if the output has changed (when I modified the sources of the tool), I'd like to check whether the content of the node OutputFingerprint
has changed (simple hash over the contents of the relevant parts of the output file).
Reading the manual for git-diff
, I found that there's a -G
option:
-G<regex>
Look for differences whose added or removed line matches the given <regex>.
Unfortunately, they provide no example for how to use the -G
option.
My first thought was to simply write
git diff -GOutputFingerprint
but that's wrong:
> git diff -GOutputFingerprint
error: invalid option: -GOutputFingerprint
Next thought was to put the regex in slashes, which is also not successful:
> git diff -G/OutputFingerprint/
error: invalid option: -GC:/Program Files/Git/OutputFingerprint/
Also, simply putting a space between -G
and OutputFingerprint
doesn't work:
> git diff -G OutputFingerprint
fatal: ambiguous argument 'OutputFingerprint': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
When I call git diff
without any params, I get the modification:
- <OutputFingerprint>e45807ca76fc5bb78e9e928c6fb7eed6</OutputFingerprint>
+ <OutputFingerprint>d0846851bc9d52b37f7919def78660a2</OutputFingerprint>
Another thought was to use git diff -S".*OutputFingerprint.*" --pickaxe-regex
, but this is also not successful.
git --version
gives me git version 1.7.3.1.msysgit.0
if that is relevant.
When I ask git diff --help
, the provided manual shows me the -G
option.
So, could anyone provide me an example for how to use git diff -G
correctly?
发布评论
评论(1)
在 msysgit 1.7.4 上运行良好,但仅在 bash 会话中(在 DOS 会话中,它不返回任何内容)
如果正则表达式与添加的行匹配,它将显示
diff
或从暂存版本中删除。添加或删除:未更改。
这意味着在你的情况下,
它不会工作OP eckes 报告它可以工作(仅适用于 msysgit1.7.4+),并添加
diff-G
选项的 code> 手册页 包括:示例:我添加一个新行“aaa”(不带
git add
:只是一个简单的编辑)请注意,在 Git 2.33(2021 年第 3 季度)中,使用
--pickaxe-regex
(通常为-S
保留)对于-G
是不可能的(无论如何它已经使用了正则表达式)。请参阅 提交 5d93460、提交 22233d4, 提交f97fe35,提交 fa59e7b,提交 9e20442,提交 a8d5eb6,提交 5b0672a,提交 5d35a95,提交 52e011c,提交 2e197a7 , 提交 03c1f14, 提交 d90d441, 提交102fdd2,提交a47fcbe,提交 d26ec88, 提交 188e9e2,提交 7cd5d5b,提交064952f,提交 69ae930,提交 c960939 , 提交 6d0a401, 提交 ecbff14(2021 年 4 月 12 日),作者:Ævar Arnfjörð Bjarmason (
avar
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 4da281e,2021 年 7 月 13 日)runs fine with msysgit 1.7.4, but only in a bash session (in a DOS session, it returns nothing)
It will display the
diff
if the regex matches a line added or removed from the staged version.added or removed: not changed.
Meaning in your case,
it won't workThe OP eckes reports it works (with msysgit1.7.4+ only), adding that the
diff
man page for-G
option includes:Example: I add a new line 'aaa' (without
git add
: just a simple edit)Note that with Git 2.33 (Q3 2021), using
--pickaxe-regex
(normally reserved for-S
) won't be possible with-G
(which already uses a regex anyway).See commit 5d93460, commit 22233d4, commit f97fe35, commit fa59e7b, commit 9e20442, commit a8d5eb6, commit 5b0672a, commit 5d35a95, commit 52e011c, commit 2e197a7, commit 03c1f14, commit d90d441, commit 102fdd2, commit a47fcbe, commit d26ec88, commit 188e9e2, commit 7cd5d5b, commit 064952f, commit 69ae930, commit c960939, commit 6d0a401, commit ecbff14 (12 Apr 2021) by Ævar Arnfjörð Bjarmason (
avar
).(Merged by Junio C Hamano --
gitster
-- in commit 4da281e, 13 Jul 2021)