Warning, mateor's answer won't work anymore with Git 2.35 (Q1 2022).
# WRONG:
git log --invert-grep --author=<pattern>
quodlibetor's answer remains valid:
git log --perl-regexp --author='^((?!excluded-author-regex).*)$'
But: no more git log --invert-grep --author=<pattern>
to exclude an author.
"git log --invert-grep --author=<name>
"(man) used to exclude commits written by the given author, but now "--invert-grep
" only affects the matches made by the "--grep=<pattern>
" option.
See commit 794c000 (17 Dec 2021) by René Scharfe (rscharfe
).
(Merged by Junio C Hamano -- gitster
-- in commit 2043ce8, 05 Jan 2022)
log
: let --invert-grep
only invert --grep
Reported-by: Dotan Cohen
Signed-off-by: René Scharfe
The option --invert-grep
is documented to filter out commits whose messages match the --grep
filters.
However, it also affects the header matches (--author
, --committer
), which is not intended.
Move the handling of that option to grep.c
, as only the code there can distinguish between matches in the header from those in the message body.
If --invert-grep
is given then enable extended expressions (not the regex type, we just need 'git grep
'(man)s --not
to work), negate the body patterns and check if any of them match by piggy-backing on the collect_hits
mechanism of grep_source_1()
.
Collecting the matches in struct grep_opt
is a bit iffy, but with "last_shown"
we have a precedent for writing state information to that struct.
Why? After an initial discussion in June 2017, this was discussed again in Dec. 2021:
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.