Skip to content
shellhacks.dev
Command Line

Show Git Commits by a Specific Author with git log

Filter history with git log --author=pattern, which matches the name and email together. It is case sensitive unless you add the ignore-case option.

2 min read
Summarize in AI

You want the commits written by one person, but the name is spelled in several ways.

Shell
git init -q repo && cd repo
git -c user.name='Ann Lee' -c [email protected] commit -q --allow-empty -m 'first'
git -c user.name='Bob Ray' -c [email protected] commit -q --allow-empty -m 'second'
GIT_AUTHOR_NAME='Cy Wu' GIT_AUTHOR_EMAIL=[email protected] git -c user.name='Ann Lee' -c [email protected] commit -q --allow-empty -m 'third, authored by Cy'
echo "--- ann"; git log --format='%an | %cn | %s' --author=ann
echo "--- ANN"; git log --format='%an | %cn | %s' --author=ANN
echo "--- ANN with -i"; git log --format='%an | %cn | %s' -i --author=ANN
echo "--- corp.example"; git log --format='%an | %s' --author=corp.example
echo "--- Ann or Bob"; git log --format='%an | %s' --author='Ann\|Bob'
echo "--- committer Ann"; git log --format='%an | %cn | %s' --committer=Ann
Text
--- ann
Ann Lee | Ann Lee | first
--- ANN
--- ANN with -i
Ann Lee | Ann Lee | first
--- corp.example
Bob Ray | second
--- Ann or Bob
Bob Ray | second
Ann Lee | first
--- committer Ann
Cy Wu | Ann Lee | third, authored by Cy
Ann Lee | Ann Lee | first

--author is matched as a regular expression against the whole Name <email> string, so ann matched through the email address, corp.example matched a domain, and basic-regex alternation found two people at once. Matching is case sensitive, so ANN found nothing until -i was added. The author and the committer are different fields: the third commit was written by Cy but committed by Ann, so --committer=Ann lists it while --author=Ann does not. See git log.

A person who commits with two names or two emails needs a pattern for each, or a .mailmap file that maps them, which git log honors in its format output. The filter reads the author in the commit and not the account that pushed it.

Taggedgit
Share

More snippets

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.