How to Use Git Log to Format the Commit History?
Last Updated : 30 May, 2024
The commit history in a Git repository serves as a timeline of changes, documenting the evolution of a project over time. While Git's default commit history display provides important information, customizing the format of the commit log can offer deeper insights and improve readability.
Git's powerful git log
command allows you to use the presentation of commit history to suit your preferences and requirements. In this article, we'll explore how to use git log
to format the commit history effectively, enabling you to gain better visibility into project changes and streamline collaboration.
What is Git Log?
git log command is used to view the list of commit logs. The data is represented in a reverse log manner, i.e., showing the recent ones at the top and others at the bottom. The log contains details about the timestamp of the commit, the author of the commit, the branch on which the commit was made, the SHA(Secure Hash Algorithm) ID of the commit, and the commit message.
Formatting Commit History
Git provides a range of options to customize the format of the commit history displayed by git log
. These options allow you to specify which commit metadata to include, how it should be formatted, and even add custom elements to the output.
The various options to format the git log are as follows:
--author=<Name>
It helps to format the log for those commits only where the author was a specific user. This option helps to review any logs made by any specific user overtime on a repository.

--since=<Date> / --after=<Date>
These options help to format the log based on the timestamps and query only those commit logs which fulfill the criteria.

-n <number>
The -n option helps to limit the log commits view, i.e. only a certain number of recent commits will be displayed instead of showing a bulk of updates.
--grep=<pattern>
The --grep options help the user to search for a particular pattern or word in the whole commit history and display on those commits which consist of the pattern. This option is useful when a user is looking for updates related to a specific file or object.

--graph
The --graph option displays the updates in a graphical format, displaying the branching and the merging commits as diverging and converging graph nodes. Each commit is actually a graph node in the log graph.

--oneline
The - -oneline option is used to format the commit log in as compact as much possible way.

--all
The --all option is used to view the commit log of all branches in a single log.

Note: Although, there are various options to format the log messages. The most useful options are the above-listed ones.
Similar Reads
How To Get The Git Commit Count? Tracking the number of commits in your Git repository can provide insights into the development progress, team activity, and overall project health. Whether you want to get the total commit count or see the number of commits by each contributor, Git offers several ways to retrieve this information.
2 min read
How To Update The Date Of An Old Commit In Git? Changing the date of a commit in Git is not a common practice, but it can be necessary in certain situations. For example, you might need to correct the timestamp of a commit for compliance reasons, to reflect the actual time work was done, or to fix an error. This process involves rewriting Git his
3 min read
How to Search Through Committed Code in Git History Using Grep? Searching through the history of committed code in a Git repository is an important skill for developers. It allows you to track changes, find the introduction of bugs, understand the evolution of the codebase, and more. One powerful tool that provides this process is grep, a command-line utility fo
1 min read
Git - Filtering the Commit History Git source code versioning tool provides a lot of features. One of the most important and useful features is log or history. We can use git log command in order to list, filter, view commit history in different ways. Here we will examine git log command usage in detail with examples. List Commit His
4 min read
How To Search All Of Git History For A String? Searching through Git history can be important for debugging, auditing, or understanding code changes. Git offers powerful tools to search the entire history of a repository for specific strings or patterns, even if they have changed across different commits. This article explores various methods to
3 min read