开发者

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 开发者_C百科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?


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


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


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.


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.


Alternative solution compatible with Git 2.35+ found in here

git log --format='%H %an' |  # get a list of all commit hashes followed by the author name
  grep -v Adam |             # match the name but return the lines that *don't* contain the name
  cut -d ' ' -f1 |           # from this extract just the first part of the line which is commit ref
  xargs -n1 git log          # call git log 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜