问题描述
我对git中版本控制的大量文件进行了简单的更改,我希望能够检查是否没有其他更改正在滑入此大型提交中。
所有变化都是这种形式
- main(),
+ OOMPH_CURRENT_FUNCTION,
其中main()可以是任何函数的名称。我想生成所有不是这种形式的变化的差异。
git diff的-G和-S选项非常接近 - 他们发现变化DO匹配一个字符串或正则表达式。
有没有一种很好的方法来做到这一点?
目前为止尝试
另一个描述了正则表达式如何被否定,使用这种方法我认为命令应该是
git diff -G '^((?! OOMPH_CURRENT_FUNCTION)。)* $'
但这只是返回错误消息
fatal:invalid log-grep正则表达式:前面的正则表达式无效
所以我猜git不支持这个正则表达式功能。
我还注意到标准的unix diff有-I选项忽略其所有行都匹配RE的更改。但我无法找到正确的方法来用unix diff工具替换git自己的diff。尝试以下操作: / p>
$ git diff> full_diff.txt
$ git diff -G你的模式> matching_diff.txt
然后你可以比较两者:
$ diff matching_diff.txt full_diff.txt
如果所有更改都符合该模式, full_diff.txt
和 matching_diff.txt
将相同,并且最后一个 diff
命令不会返回任何东西。
如果有与模式不匹配的更改,则最后一个 diff
会突出显示这些内容。
您可以将上述所有步骤和避免必须创建两个额外的文件,例如:
diff
I've made a single simple change to a large number of files that are version controlled in git and I'd like to be able to check that no other changes are slipping into this large commit.
The changes are all of the form
- "main()",
+ OOMPH_CURRENT_FUNCTION,
where "main()" could be the name of any function. I want to generate a diff of all changes that are not of this form.
The -G and -S options to git diff are tantalisingly close--they find changes that DO match a string or regexp.
Is there a good way to do this?
Attempts so far
Another question describes how regexs can be negated, using this approach I think the command should be
git diff -G '^((?!OOMPH_CURRENT_FUNCTION).)*$'
but this just returns the error message
fatal: invalid log-grep regex: Invalid preceding regular expression
so I guess git doesn't support this regex feature.
I also noticed that the standard unix diff has the -I option to "ignore changes whose lines all match RE". But I can't find the correct way to replace git's own diff with the unix diff tool.
Try the following:
$ git diff > full_diff.txt
$ git diff -G "your pattern" > matching_diff.txt
You can then compare the two like so:
$ diff matching_diff.txt full_diff.txt
If all changes match the pattern, full_diff.txt
and matching_diff.txt
will be identical, and the last diff
command will not return anything.
If there are changes that do not match the pattern, the last diff
will highlight those.
You can combine all of the above steps and avoid having to create two extra files like so:
diff <(git diff -G "your pattern") <(git diff) # works with other diff tools too
这篇关于忽略在git diff中匹配字符串的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!