Git: exclude commits by an author in git log with --perl-regexp

Artist’s depiction of a dependabot.

git log has an --author option to limit the output to commits from matching authors:

$ git log --author=<pattern>

But there’s no option to invert the filter and show commits from all authors except those matching a pattern.

Instead, you can build the negation into the pattern itself, using a regular expression with a negative lookahead, enabled with the --perl-regexp option:

$ git log --author='^((?!<pattern>).)*$' --perl-regexp

A breakdown of the regular expression:

  1. ^ matches the start of the author line, which contains both the author’s name and email address.
  2. (?!<pattern>) is a negative lookahead: it fails the match if <pattern> matches at the current position, without consuming any characters.
  3. . matches any single character.
  4. The wrapping (…)* repeats the previous two steps as many times as possible, applying the lookahead at every position in the line.
  5. $ matches the end of the line.

The overall effect is to match commits where the author line does not contain <pattern> at any position.

Note that --perl-regexp requires Git to be compiled with PCRE support. That’s the case for typical installations, but if yours isn’t, the command will fail with an error message mentioning PCRE.

Example: hide the bots

I recently used this technique to read the history of a project’s .github/workflows directory, which contains its GitHub Actions workflows. By default, the history is peppered with dependency update commits from GitHub’s Dependabot:

$ git log --format='%h %an %s' .github
...
5ca72f6 Adam Johnson Improve Coverage.py configuration (#615)
52b515f dependabot[bot] Bump the github-actions group with 2 updates (#612)
e72f1d8 Adam Johnson Restore building Windows ARM wheels (#606)
...

To skip those, commits, I used the above negative lookahead technique with the pattern “dependabot”, adding -p to show patches:

$ git log --author='^((?!dependabot).)*$' --perl-regexp -p .github
commit 7065c7c79e7b964d73d2c9cab7db950ad27891ce
Author: Adam Johnson <me@adamj.eu>
Date:   Wed Jul 29 23:03:00 2026 +0100

    Support Python 3.15 (#631)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 21122be..297ee88 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -27,6 +27,8 @@ jobs:
         - '3.13t'
         - '3.14'
         - '3.14t'
+        - '3.15'
+        - '3.15t'

This command let me browse a bot-free history.

Fin

May you find it easy to ignore noisy fools,

—Adam


😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸


Subscribe via RSS, Twitter, Mastodon, or email:

One summary email a week, no spam, I pinky promise.

Related posts:

Tags: