要么我无法获得 git-log 的 regexp grep 功能来使用基于 perl 的 regexp (pcre) 进行搜索,要么我可以,但它不能与负向后查找一起工作。
git log -p -P -G'(?<!-)title'
输出结果
fatal: invalid regex: Invalid preceding regular expression
但是,如果 git-grep 是任何指标的话,PCRE 支持和负向后查找似乎有效。
例如。 git grep -P '(?<!-)title'
返回预期结果。
git 版本 2.21.0 (Apple Git-122.2)
最佳答案
-P
不影响-G
。您可以通过将 -P
替换为 -F
(或 --fixed-string
)来验证它:您仍然会收到相同的错误,即使固定字符串中根本没有环视。
-P
的文档说
Consider the limiting patterns to be Perl-compatible regular expressions.
注意“模式”这个词。事实上,--grep
选项提到了它:
--grep=<pattern>
另一方面,-G
则不会:
-G<regex>
关于regex - 为什么带有 perl 正则表达式的 git-log 负向后查找会导致 fatal error ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59608275/