equivalence of: git log --exclude-author?
At work we have a git repo where the majority of all commits are automated commits by a bot user. There are times when I prefer to view a git log from that repo, but without seeing the auto commits. I guess it could be described as an inverted "git log --author" or a "git log --exclude-author=botuser", if such as option had existed.
Currently I do the following, shortcuted to a bash alias.
git log --format="%H %aE" | grep -v -F botuser@domain | while read hash email; do git log -1 $hash; echo; done | less
My question is if there is a less hackish solution to what I want to accomplish?
Solution 1:
From https://coderwall.com/p/tzdzwa :
git log --perl-regexp --author='^((?!excluded-author-regex).*)$'
This worked for me.
If you don't want to specify --perl-regexp
every time you can do:
git config --global grep.patternType perl
Solution 2:
Some other answers reference portions of this, but I had success in my repo using the tactic I saw here
git log --invert-grep --author=<pattern>
You can add as many author patterns as needed. In my case, the best pattern was the full email, since it is known to be unique
Solution 3:
Not currently, although there seems to have been some discussion about supporting a -v
option in the future, or making the current git log --not
work for --author
, --committer
and --grep
.
See also: How to invert git log --grep
pattern.
Solution 4:
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 thecollect_hits
mechanism ofgrep_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.