Graphite Reviewer is now Diamond

Listing Git commits with `git log`

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


In this guide, we'll show how to explore, filter, and customize your Git commit history using powerful commands like git log and Graphite’s gt log command.

Every Git commit is a snapshot of your project at a specific point in time. Each commit, when following the Conventional Commits style, includes critical metadata that helps you track changes, collaborate efficiently, and debug issues. Key elements include:

  • Commit hash: A unique identifier generated based on the commit’s content.
  • Author: The individual responsible for the changes.
  • Date: Timestamp marking when the commit was made.
  • Commit message: A clear description of the changes (e.g., feat:, fix:).

To display a list of commits in Git, you can use the git log command. By default, git log presents the commit history of the current branch in reverse chronological order, showing details such as commit hash, author, date, and commit message.

To view the commit history of the current branch, run:

Terminal
git log

You'll see output similar to:

Terminal
commit 4a5b6c7d8e9f0g1h2i3j4k5l6m7n8o9p0q1r2s3 (HEAD -> master, origin/master)
Author: Jane Doe <jane@example.com>
Date: Wed Sep 29 14:33:07 2021 -0400
feat: add login feature
commit 3a4b5c6d7e8f9g0h1i2j3k4l5m6n7o8p9q0r1s2
Author: John Smith <john@example.com>
Date: Tue Sep 28 11:22:33 2021 -0400
fix: correct typo in main.py

Breaking down the output:

  • Commit hash: Each commit is identified by a unique hash. In the example, the first commit hash is 4a5b6c7d8e9f0g1h2i3j4k5l6m7n8o9p0q1r2s3. This hash is generated by Git based on the content of the commit and acts as its unique identifier.

  • Branch information: (HEAD -> master, origin/master) indicates the current state of the branch pointers. HEAD represents the latest commit you're viewing or working on in the current branch. master is the name of the branch you're currently on, which shows that HEAD is pointing to the tip of the master branch. origin/master indicates the position of the master branch on the remote named origin. The presence of both HEAD -> master and origin/master on the same commit suggests that your local master branch is up to date with the master branch on the remote repository.

  • Author: Shows who made the commit. The first commit was made by Jane Doe with the email jane@example.com.

  • Date: The date and time when the commit was made. For example, the first commit was made on Wed Sep 29 14:33:07 2021 -0400. The -0400 indicates the time zone offset from UTC, showing this commit was made in a time zone four hours behind UTC.

  • Commit Message: A brief description of what the commit does. Good commit messages provide a clear understanding of the changes made. In this example, the first commit message is feat: add login feature, indicating a new feature was added to support login functionality. The prefix feat: is a conventional shorthand used in some projects to indicate a new feature.

  • Previous Commits: The log also shows previous commits in reverse chronological order. The second commit listed is by John Smith, with the commit message fix: correct typo in main.py, indicating a bug fix where a typo was corrected in main.py.

To list all commits on a specific branch:

Terminal
git log branch-name

To see the commit history of a specific file:

Terminal
git log path/to/file

This will show you a list of all of the commits that made changes to that particular file. All other commits will be excluded.

To list commits after a specific date:

Terminal
git log --after="2021-09-01"

For a summary view:

Terminal
git log --oneline

You'll see something like:

Terminal
4a5b6c7 feat: add login feature
3a4b5c6 fix: correct typo in main.py

This provides a much more compact view, including only the commit hash and the message.

To list all commits made by a specific author:

Terminal
git log --author="Jane Doe"

To view the actual changes (diffs) made by each commit:

Terminal
git log -p

For a custom format, such as showing hashes and messages only:

Terminal
git log --pretty=format:"%h - %s"

For a comprehensive list of all of the formatting options available in the git log, see the docs.

To visualize branch history with a graph:

Terminal
git log --graph --oneline --all

If git log doesn’t seem to show the commits you're looking for, ensure you’re on the correct branch or use the --all flag to view commits across all branches.

For more detail on the git log command including all of the various output formatting options, see the official documentation.

Graphite simplifies working with multiple interdependent branches by providing streamlined CLI commands to track commit ancestry, review changes, and manage your workflow efficiently. Its intuitive design is ideal for teams that rely on stacked pull requests and advanced version control strategies.

The gt log command in Graphite provides a comprehensive view of your commit history, optimized for stack-based workflows:

  • Standard log view: To see a full view of all commits in your stack, run:
    Terminal
    gt log
  • Simplified log: For a concise display, use:
    Terminal
    gt log short
  • Detailed ancestry graph: For a more detailed view of commit relationships:
    Terminal
    gt log long
  • Filtering by stack: To filter and display only the current branch’s ancestors and descendants:
    Terminal
    gt log --stack
    Here's a visual example of what you'll see in the terminal when you run gt log with Graphite:

screenshot of gt log

For more detailed information on Graphite’s commands, consult the Graphite documentation.

Mastering Git commit history commands, including git log and Graphite’s gt log, is essential for efficient version control and collaboration. This guide equips you with the knowledge to navigate, filter, and customize your Git history, ensuring you stay organized and productive.

Built for the world's fastest engineering teams, now available for everyone