问题
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:
git diff -Garegex
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 work
The OP eckes reports it works (with msysgit1.7.4+ only), adding that the diff man page for -G
option includes:
"Look for differences whose added or removed line matches the given regex",
which relates to the diff output where a changed line is printed as one added and one removed line.
Example: I add a new line 'aaa' (without git add
: just a simple edit)
$ git diff -Gaaa
diff --git a/conf/fragments/xxx_repos.conf b/conf/fragments/xxx_repos.coindex 263fa85..3475f9b 100644
--- a/conf/fragments/xxx_repos.conf
+++ b/conf/fragments/xxx_repos.conf
@@ -10,3 +10,4 @@ repo xxx-sdsfwk
RW+ = vonc user1 user2
RW = @xxx_users
xxx-sdsfwk "Owner" = "for..."
+aaa
来源:https://stackoverflow.com/questions/5088907/how-do-i-use-git-diff-g