Git
User Commits
Version Control
Software Development
Git Log

How can I view a git log of just one user's commits?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Git's --author flag filters the commit log to show only commits by a specific person. This is useful for code reviews, tracking individual contributions, generating reports, and understanding who changed specific parts of a codebase.

Basic Usage

bash
git log --author="username"

Replace "username" with the name or email of the user. The --author flag performs a pattern match, so partial names work:

bash
1# Full name
2git log --author="Alice Johnson"
3
4# Partial name
5git log --author="Alice"
6
7# Email address
8git log --author="[email protected]"
9
10# Partial email
11git log --author="@example.com"

Formatting Options

One-Line Summary

bash
1git log --author="Alice" --oneline
2# a1b2c3d Fix login validation
3# e4f5g6h Add user dashboard
4# i7j8k9l Update README

With Date and Stats

bash
1git log --author="Alice" --format="%h %ad %s" --date=short
2# a1b2c3d 2026-02-15 Fix login validation
3# e4f5g6h 2026-02-10 Add user dashboard
4
5# With file change statistics
6git log --author="Alice" --stat

Custom Format

bash
git log --author="Alice" --format="%H%n  Author: %an <%ae>%n  Date: %ad%n  Message: %s%n" --date=relative

Common format placeholders:

PlaceholderOutput
%HFull commit hash
%hShort commit hash
%anAuthor name
%aeAuthor email
%adAuthor date
%sSubject (first line of message)
%bBody of commit message

Filtering by Date Range

bash
1# Commits by Alice in the last week
2git log --author="Alice" --since="1 week ago"
3
4# Commits in a specific date range
5git log --author="Alice" --after="2026-01-01" --before="2026-02-01"
6
7# Commits in the last 30 days
8git log --author="Alice" --since="30 days ago"

Filtering by File or Directory

bash
1# Alice's commits touching a specific file
2git log --author="Alice" -- src/auth.py
3
4# Alice's commits in a directory
5git log --author="Alice" -- src/components/
6
7# With diff
8git log --author="Alice" -p -- src/auth.py

Counting Commits

bash
1# Count commits by a user
2git log --author="Alice" --oneline | wc -l
3
4# Count with shortlog (grouped summary)
5git shortlog -sn --author="Alice"
6#     42  Alice Johnson
7
8# All authors ranked by commit count
9git shortlog -sn
10#    142  Alice Johnson
11#     98  Bob Smith
12#     67  Charlie Brown

Searching Commit Messages

Combine --author with --grep to find specific commits:

bash
1# Alice's commits mentioning "bug fix"
2git log --author="Alice" --grep="bug fix"
3
4# Alice's commits mentioning "refactor" in the last month
5git log --author="Alice" --grep="refactor" --since="1 month ago"
6
7# Case-insensitive search
8git log --author="Alice" --grep="Bug" -i

Multiple Authors

bash
1# Commits by Alice OR Bob (regex)
2git log --author="Alice\|Bob"
3
4# Using extended regex
5git log --author="Alice" --author="Bob" --all
6# Note: multiple --author flags are OR'd together

Author vs Committer

Git tracks two identities per commit:

  • Author: who wrote the change (set by git commit --author)
  • Committer: who applied it (set by GIT_COMMITTER_NAME)
bash
1# Filter by author (who wrote it)
2git log --author="Alice"
3
4# Filter by committer (who applied it, e.g., after rebase/cherry-pick)
5git log --committer="Bob"

After a rebase or cherry-pick, the committer may differ from the author.

Useful Aliases

bash
1# Add to ~/.gitconfig
2git config --global alias.by '!f() { git log --author="$1" --oneline; }; f'
3git config --global alias.contributions '!f() { git shortlog -sn --author="$1"; }; f'
4
5# Usage
6git by "Alice"
7git contributions "Alice"

Common Pitfalls

  • Case sensitivity: The --author flag is case-sensitive by default. "alice" will not match "Alice". Add -i for case-insensitive matching: git log --author="alice" -i.
  • Multiple identities: Users may commit with different names or emails across machines. Search by partial email domain: git log --author="@company.com".
  • Regex matching: The --author value is a regex pattern. Special characters like . match any character. Escape them: git log --author="alice\.johnson".
  • Branch scope: By default, git log only shows the current branch. Add --all to search across all branches.
  • Merge commits: git log --author="Alice" includes merge commits. Add --no-merges to exclude them.

Summary

  • Use git log --author="name" to filter commits by a specific user
  • The --author flag matches against both name and email using regex
  • Combine with --since, --until, --grep, and -- path for precise filtering
  • Use git shortlog -sn for commit count summaries per author
  • Add -i for case-insensitive matching and --no-merges to exclude merge commits

Course illustration
Course illustration

All Rights Reserved.