How to list and search commits with Git Log

Git Log allows users to display and filter every commit in a project. You can achieve even better results by using different specifications.

$1 Domain Names

Register great TLDs for less than $1 for the first year.

Why wait? Grab your favorite domain name today!

Matching email
SSL certificate
24/7/365 support

What is Git Log?

The Git Commit command can be found at the very beginning of every Git tutorial. Git Commit ensures that current state snapshots are created and tracks saved changes. Numerous commits can occur with large projects, which probably have several large teams working on them. This can make the history quite confusing. Therefore, the Git command Git Log is an important tool when working with the version control system. It allows you to list, filter, and search commits for specific changes. While Git Status scans the working directory, Git Log focuses only on commits which have been made.

What is the Git Log syntax?

The syntax of Git Log is very simple. The command simply lists all the commits in your project in reverse chronological order. It begins with the most recent commit and you can scroll step by step through the previous snapshots. The date, name and email address of the respective user are listed along with some other information.

git log

This function is useful as it gives users a general overview of a project’s history. However, it is worth refining the search criteria to get more accurate results when looking into larger projects. Git offers several options for this. We have put the most important ones in a table for you to use in addition to our handy Git cheat sheet with PDF download.

What are the main uses of Git Log?

git log The default variant lists all commits in reverse order.
git log -p This command maps all changes in detail.
git log --stat Displays statistics on changes and lists them clearly.
git log --graph --decorate --oneline Lists the changes as a graph.
git log -n <count> Use this command to limit the number of commits shown.
git log --oneline Summarizes each commit on a single line for a better overview.
git log --author="name of author" Shows only commits by a specific author.
git log --grep="message" Filters the commits based on their explanation.
git log <since>..<until> Displays commits between a specific time period.
git log <file> Displays commits which contain a specific file.
git log --pretty Changes the output’s format according to specifications.

How do I combine filters?

You can combine different arguments to perform a more precise search. The following code illustrates a simple example of a very specific listing with Git Log. This command example displays the commits by the user John Smith in detail.

git log --author="John Smith" -p example.py

Let’s that the commits of the same author and a colleague should only be considered for between September and October 2021 as a more comprehensive example. The commits should only have changes in the text directory and there should be no merges. The code would look like this:

git log --author="John Smith\|Jane Smith" --since="2021-09-01" \ --before="2021-10-31" --no-merges --t example.py

How do I format Git Log with pretty?

You can choose the display in Git Log using the pretty formats. The following formats are common:

  • oneline: Shows all information in one line.
  • short: Lists only commit and author or author and title.
  • medium: Lists commit, author, date, title, and statement.
  • full: Adds the committer.
  • fuller: Lists the date of the author and the committer.
  • email: Shows the information in email format.
  • raw: Lists the commits exactly as they were stored.
  • format: Allows you to format the text exactly as you wish. For example, you can present important information in sentence form, include paragraphs, or specify a particular order for the information.

How do I use Git Log and Git Diff together?

Git Log is an important tool for keeping track of your project and filtering certain information. The command is often used with Git Diff and allows users to list the changes between two commits. This shows you how your project has changed over time and which team members have performed certain tasks. It is also useful for identifying errors.

Tip

Use Deploy Now from IONOS to benefit from optimized workflows, fast setup and maximum scalability! Deploy your websites and apps directly using GitHub.

We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.