Customizing Commit Summaries
While the default git log
command provides a wealth of information about your commit history, you may sometimes want to customize the commit summaries to better suit your needs. Git offers several options to tailor the commit summary output.
git log --pretty
Option
The --pretty
option allows you to specify the format of the commit summary. You can use various placeholders to include specific pieces of information, such as the commit hash, author, date, and commit message.
For example, to display a more concise commit summary with just the commit hash and message, you can use the following command:
$ git log --pretty=format:"%h %s"
1234567 Implement new feature: user profile page
9876543 Fix bug in login functionality
Here, %h
represents the abbreviated commit hash, and %s
represents the commit message.
Git also provides several predefined formats that you can use with the --pretty
option. Some common examples include:
oneline
: Displays a single-line summary of each commit.
short
: Displays a more concise summary, including the commit hash, author, and commit message.
full
: Displays the full commit information, including the commit hash, author, date, and commit message.
fuller
: Displays even more detailed information, including the committer and commit notes.
$ git log --pretty=oneline
1234567 Implement new feature: user profile page
9876543 Fix bug in login functionality
If the predefined formats don't suit your needs, you can create your own custom formats using the --pretty=format:
option. This allows you to specify the exact information you want to include in the commit summaries.
For example, to display the commit hash, author, date, and commit message in a specific format, you can use the following command:
$ git log --pretty=format:"%h | %an | %ad | %s"
1234567 | John Doe | Fri Apr 14 14:23:42 2023 +0000 | Implement new feature: user profile page
9876543 | Jane Smith | Thu Apr 13 10:15:20 2023 +0000 | Fix bug in login functionality
Here, %h
represents the commit hash, %an
represents the author name, %ad
represents the author date, and %s
represents the commit message.
By customizing the commit summaries, you can make the commit history more readable and tailored to your specific needs.