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.
When working with Git, the need to focus on the contributions of a single user often arises. Whether for code reviews, performance assessments, or historical interest, viewing a Git log of just one user's commits can be invaluable. In this article, we will delve into how you can achieve this, providing you with a streamlined, user-specific view of your project's history.
Understanding Git Logs
Git logs are the history of changes to a repository. They include commit IDs, authorship details, timestamps, and commit messages. By default, a git log command displays these rich details for all commits in the current branch. To filter this log for a single user's contributions requires an understanding of a few key Git features.
Filtering Commits by Author
One of the simplest ways to view commits made by a specific user is to use the --author flag with git log. This flag allows you to query commits by the author's name or email address.
Basic Command
Here's an example command that fetches the log for a specific author:
You can replace Author Name with part or all of a user's name or their email address. Git will match this argument against commit authorship details.
Regular Expressions
If a developer has used different variations of their name or email, or if you only remember part of the author's credentials, you can use regular expressions:
This example would match any committer whose name starts with "John" and ends with "Doe". Regular expressions in Git follow standard PCRE (Perl Compatible Regular Expressions) syntax.
Enhancing the Log Output
While filtering for a single author's commits, you might want to customize the log output to include or exclude specific information.
Customized Log Format
You can use the --pretty option to customize the log's format:
%h: Abbreviated commit hash.%an: Author name.%ar: Relative timestamp.%s: Commit message.
Additional Filters
It is possible to refine the output further by filtering for specific files or date ranges:
- Date Range:
- Specific Files:
Viewing Changes per Commit
If you wish to not only see which commits a user made but also want to inspect the changes introduced in those commits, you can add the -p option to show the patch (diff) of each commit:
Summary Table
Here's a quick summary of key commands and their purpose:
| Command | Purpose |
git log --author="Author Name" | List commits from a specific user. |
git log --author="^John.*Doe$" | Use a regex to find commits from authors matching a pattern. |
git log --author="Author Name" -p | Display changes in each commit by a specific author. |
git log --author="Author Name" --since="date" | View commits from a specific user after a certain date. |
git log --author="Author Name" -- path/to/file | Show commits by a user for a specific file. |
git log --author="Author Name" --pretty=format:"<format>" | Customize log entry format for readability. |
Conclusion
Being able to filter and view Git logs based on specific user contributions is a powerful feature for developers, team leads, and project managers. By employing Git's filtering options and understanding formatting commands, you can obtain a clear record of individual contributions. These skills enhance your ability to audit code, facilitate focused reviews, and gain insights into a project's development history.

