Read Anthropic’s case study about Graphite Reviewer

Listing Git commits with `git log`

Greg Foster
Greg Foster
Graphite software engineer


Note

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


This guide will explore various commands to view and manage your Git commit history.

Each commit in Git represents a snapshot of your project at a particular point in time. Commits include metadata like the author, date, and a commit message, which, when following the conventional commits style, includes a prefix to indicate the purpose of the change (e.g., feat:, fix:, for features and bug fixes, respectively).

The git log command is the primary tool for viewing commit history.

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
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2