git log
provides a --pretty
option that lets you customize the format of the output. Here are some examples of how to use the --pretty
option:
Display the commit hash, author, and commit message on separate lines:
git log --pretty=format:"%h%n%an%n%s"
This will display each commit’s abbreviated hash, author name, and commit message on separate lines.
Display the commit hash, author, and commit message separated by a delimiter:
git log --pretty=format:"%h|%an|%s" --delimiter=|
This will display each commit’s abbreviated hash, author name, and commit message separated by a pipe (|
) character.
Display the commit hash, author, commit date, and commit message:
git log --pretty=format:"%h %an %ad %s"
This will display each commit’s abbreviated hash, author name, commit date, and commit message.
Display the commit hash, author, and commit message in a JSON format:
git log --pretty=format:'{%n "hash": "%h",%n "author": "%an",%n "message": "%s"%n},' --no-abbrev-commit | sed '$s/,$//'
This will display the commit hash, author name, and commit message for each commit in a JSON format. Note that the sed
command at the end is used to remove the trailing comma from the output.
These are just a few examples of how to use git log --pretty
. There are many other options and placeholders you can use to customize the output format to your needs.