警告,mateor的answer将不再与Git 2.35(2022年第一季度)兼容。
# WRONG:
git log --invert-grep --author=<pattern>
quodlibetor的answer仍然有效:
git log --perl-regexp --author='^((?!excluded-author-regex).*)$'
但是:不再使用git log --invert-grep --author=<pattern>
来排除某个作者。
"git log --invert-grep --author=<name>
"(手册)曾用于排除给定作者所写的提交,但现在"--invert-grep
"只影响由"--grep=<pattern>
"选项匹配到的内容。
参见提交 794c000 (2021年12月17日) by René Scharfe (rscharfe
)。
(由Junio C Hamano -- gitster
--在提交 2043ce8中合并,2022年1月5日)
log
: 只让--invert-grep
反转--grep
报告者: Dotan Cohen
签名: René Scharfe
选项
--invert-grep
的文档说明是过滤掉符合
--grep
过滤器的提交消息。
然而,它也会影响标题匹配(
--author
,
--committer
),这并不是预期的行为。
将该选项的处理移至
grep.c
, 因为只有那里的代码才能区分标题中的匹配和正文中的匹配。
如果给出
--invert-grep
,则启用扩展表达式(不是正则表达式类型,我们只需要 '
git grep
'
(man)s
--not
即可工作),否定正文模式并检查它们是否匹配,通过利用
grep_source_1()
的
collect_hits
机制来实现。
在
grep_opt
结构体中收集匹配结果有点棘手,但是通过
"last_shown"
我们已经为向该结构体写入状态信息设立了先例。
为什么?在2017年6月的初步讨论之后,这个问题再次于2021年12月进行了讨论:
What did you do before the bug happened?
$ git log -8 --author=Shachar --grep=Revert --invert-grep
What did you expect to happen?
I expected to see the last 8 commits from Shachar
that did not have
the string "Revert
" in the commit message.
What happened instead?
The list of commits included commits by authors other than Shachar
.
What's different between what you expected and what actually happened?
The "--author
" filter seems to be ignored when the "--invert-grep
"
option is used.
I also tried to change the order of the options, but the results
remained the same.
git log --author=bot --invert-grep
命令。该命令的作用是筛选出除"bot"以外的作者所做的提交记录,并将结果输出。 - larhatgit log --author=bot --invert-grep
)将在 Git 2.35+ (2022年第一季度) 开始失效。 - VonC