Data report"State of code review 2024" is now liveRead the full report

How to use the git log -1 command

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


The git log command helps you to view the history of commits in the repository. In this guide, we'll focus on a specific use of the git log command—git log -1—which is used to display only the most recent commit.

Before exploring git log -1, let's first understand the git log command. git log displays the commit logs. The output includes the ID, author, date, and message for each commit. By default, git log lists all the commits starting with the most recent.

The syntax git log -1 uses a shorthand option to modify the output of the git log command. This option limits the number of commit entries returned by the command. Specifically, -1 tells Git to show only the most recent commit. This is useful when you want a quick look at the last commit without scrolling through an extensive commit history.

This is a shorthand for --max-count=1, which limits the output to just one commit. The number following the dash can be changed to any integer to specify the exact number of commits you want to see. For example, git log -3 would show the three most recent commits.

This option is part of a broader set of filtering and formatting options available with git log that can help you customize the output to better suit your needs, such as limiting the number of commits, restricting the commits to certain authors, or modifying the display format.

The output will show the most recent commit's details, including:

  • Commit hash: A unique identifier for the commit.
  • Author: The name and email of the user who made the commit.
  • Date: The date and time of the commit.
  • Commit message: A brief description of the changes made in the commit.

You can combine git log -1 with other options to customize the output.

If you want a more concise output, you can use the --pretty=format:"%h - %s" option, where %h is the abbreviated commit hash and %s is the subject (commit message). This will display the latest commit in a single line, which addresses the use case for the keyword "git log 1 line".

Example command:

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

To see the latest commit by a specific author, use the --author option:

Terminal
git log -1 --author="Author Name"

To see the actual changes (diff) made in the latest commit, use the -p option:

Terminal
git log -1 -p

This will display the diff of the latest commit along with the commit details.

For further reading see the official Git 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