filter git commits by author

2020-03-18

 | 

~2 min read

 | 

242 words

In the past, I’ve written about diving into the git log with grep and the pickaxe.

Those do not search by the author of a commit, however, which is something I often find the need to do after merging in master locally.

To search for authors of a commit, git log provides an --author flag.

It’s worth noting that author will match on what’s provided, even if it’s only a partial name.

To find all of my commits, I can write:

git log --author="Stephen Weiss"

As long as I’m the only Stephen Weiss, this will work.

If I’m the only Stephen who has committed to the code base, I could save some key strokes and do:

git log --author=Stephen

However, if there’s another Stephen, their commits would show up as well.

As Adam Dymitruk points out in his answer to this question on StackOverflow, there are a few more things worth knowing:

  1. By default, the git log will search only the current branch. If you want to search all branches, use the --all
  2. The author flag can accept regular expressions for more advanced searching.
git log --author="\(Stephen\)\|\(John\)"

Will search for commits where the author is Stephen or John.

Similarly, you can exclude commits by those authors using a regular expression in combination with the --perl-regexp (to get negative lookaheads).

git log --author='^(?!Stephen|John).*$' --perl-regexp

(Note: the single quotes matter with the perl syntax.)


Related Posts
  • Git: Search Commits By Date, Branch, Author
  • Multi-Line Bash Scripting


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!