How to View Git Log of One User’s Commits?

In collaborative software development, it’s often necessary to view the commit history of individual contributors. Git provides powerful tools to filter and examine commits based on various criteria, including the author. This guide will walk you through the steps to view the Git log of one user’s commits.

Prerequisites

Search by Username

The most common way is using the `–author` option with `git log`:

git log --author="<username>"

Replace “ with the actual name of the developer whose work you want to see.

Partial Username Search:

`–author` allows searching by a part of the username:

git log --author="htom*"  # This shows commits by users starting with "htom"

Note : By default, `git log` only shows commits from the current branch. To include all branches:

git log --author="<username>" --all

By using these options with `git log`, you can easily filter the commit history and focus on a specific developer’s contributions to your Git project.

Customize the Output

The default git log shows commit hashes and messages. You can customize the format for better readability:

Format String:

git log --author="Author Name" --pretty=format:"%h - %an, %ar : %s"

This displays:

  • %h: Abbreviated commit hash
  • %an: Author name
  • %ar: Author date
  • %s: Subject line of the commit message

Fuller Details:

git log --author="Author Name" --pretty=fuller

This shows more information about each commit, including author and committer details, date, and the full commit message.

–pretty variations

Limiting the Number of Commits:

To see only a specific number of commits (e.g., the last 10), use the -n option:

git log --author="Author Name" -n 10

This shows only the most recent 10 commits by the specified author.

Filtering by Commit Message:

    git log --author="<username>" --grep="fix bug"

This shows commits by the specified author containing the phrase “fix bug” in the message.

Filtering by Date Range:

  • Since a specific date:
    git log --author="<username>" --since="2024-05-15"

This shows commits by the user since May 15th, 2024.

  • Until a specific date:
git log --author="<username>" --until="2024-04-30"

This shows commits by the user up to April 30th, 2024.

  • Between a date range:
git log --author="<username>" --since="2024-04-01" --until="2024-05-15"

This shows commits by the user between April 1st and May 15th, 2024 (excluding the endpoints).

For more Git log filters visit : Git Log filters


Contact Us