日本語

How to customize the output format of git log –pretty

​​Git​command line

Writing git log --pretty="%h %ad %an %s" changes the commit history display into one line per commit, in an order you choose. This is useful for making a list of changes before a release, or for fitting the default multi-line output onto one screen.

Note

The test environment is Ubuntu 24.04 with Git 2.43.0. I made the commits with sample author values such as Neko <neko@example.com>. The time zone is Japan Standard Time. I did not test Windows or macOS terminals, or formats not shown in this article, such as email or raw.

Output with no option

First, the output without --pretty. In a repository with three commits, I showed the two newest.

console
$ git log -2
commit 97cacdb097facdaea98d397d593669494f3f1ebc
Author: Neko <neko@example.com>
Date:   Tue Nov 3 09:15:00 2026 +0900

    トップ画面を追加

commit 911e92d6fc8bb6fb321ebc882e853fed1b2d34fc
Author: Tama <tama@example.com>
Date:   Mon Nov 2 14:30:00 2026 +0900

    ログイン画面を追加
    
    パスワードの入力欄を付けた。

Each commit takes five or more lines. This format is named medium. The description of --pretty in the git log reference says that this is the format used when --pretty is omitted.

Choose a built-in format by name

Writing a name after --pretty= switches to a built-in format. oneline puts the hash and the subject on one line.

console
$ git log --pretty=oneline
97cacdb097facdaea98d397d593669494f3f1ebc トップ画面を追加
911e92d6fc8bb6fb321ebc882e853fed1b2d34fc ログイン画面を追加
e5639665d087edf66b4a5c0d6760c5eec4b83069 最初のコミット

The hashes are shown in full, 40 characters each. git log --oneline, which is used often, is a shortcut for --pretty=oneline --abbrev-commit. It shows abbreviated hashes.

console
$ git log --oneline
97cacdb トップ画面を追加
911e92d ログイン画面を追加
e563966 最初のコミット

fuller shows both the author and committer names and dates.

console
$ git log --pretty=fuller -1
commit 97cacdb097facdaea98d397d593669494f3f1ebc
Author:     Neko <neko@example.com>
AuthorDate: Tue Nov 3 09:15:00 2026 +0900
Commit:     Neko <neko@example.com>
CommitDate: Tue Nov 3 09:15:00 2026 +0900

    トップ画面を追加

reference is the format used when one commit refers to another in a commit message. It shows the abbreviated hash, then the subject and date in parentheses.

console
$ git log --pretty=reference
97cacdb (トップ画面を追加, 2026-11-03)
911e92d (ログイン画面を追加, 2026-11-02)
e563966 (最初のコミット, 2026-11-01)

There are also short, which omits the date, and full, which omits the date and adds the committer. The table below summarizes the formats I checked in the test environment.

Name Output for one commit
oneline Full 40-character hash and subject on one line
short Hash, author, and subject
medium (default) Hash, author, date, and full message
full Hash, author, committer, and full message
fuller Same as full, plus the author and committer dates
reference Abbreviated hash, subject, and date on one line

Each format is described in the PRETTY FORMATS section of the git log reference.

Arrange placeholders to define your own format

When the built-in formats are not enough, you can list placeholders that start with % to choose the fields and their order. %h is the abbreviated hash, %an is the author name, and %s is the subject.

console
$ git log --pretty=format:"%h %an %s"
97cacdb Neko トップ画面を追加
911e92d Tama ログイン画面を追加
e563966 Neko 最初のコミット

You can omit format:. When you pass a string containing %, Git treats it as if tformat: were specified. The difference is explained in the next section. From here on, I omit format:.

console
$ git log --pretty="%h %an %s"
97cacdb Neko トップ画面を追加
911e92d Tama ログイン画面を追加
e563966 Neko 最初のコミット

You can put any characters between placeholders. Here I separated fields with | and added %ad (author date) and %ae (author email). With --date=short, %ad is shown as YYYY-MM-DD.

console
$ git log --pretty="%h | %ad | %an <%ae> | %s" --date=short
97cacdb | 2026-11-03 | Neko <neko@example.com> | トップ画面を追加
911e92d | 2026-11-02 | Tama <tama@example.com> | ログイン画面を追加
e563966 | 2026-11-01 | Neko <neko@example.com> | 最初のコミット

To include the time, write the date format after --date=format: using strftime placeholders.

console
$ git log --pretty="%h %ad %s" --date=format:"%Y/%m/%d %H:%M"
97cacdb 2026/11/03 09:15 トップ画面を追加
911e92d 2026/11/02 14:30 ログイン画面を追加
e563966 2026/11/01 10:00 最初のコミット

%ar shows the author date relative to now, such as 9 days ago. This output was produced on November 12.

console
$ git log --pretty="%h %ar %s"
97cacdb 9 days ago トップ画面を追加
911e92d 10 days ago ログイン画面を追加
e563966 11 days ago 最初のコミット

%d shows the names of branches and tags that point to the commit, in parentheses. Nothing is shown for a commit with no names.

console
$ git log --pretty="%h%d %s"
97cacdb (HEAD -> main, tag: v1.0) トップ画面を追加
911e92d ログイン画面を追加
e563966 最初のコミット

The table below summarizes the placeholders used in this article. You can find other placeholders in the list of placeholders in the official reference.

Placeholder Output
%h / %H Abbreviated hash / full 40-character hash
%an / %ae Author name / author email
%ad Author date (follows the --date= option)
%ar Author date relative to now (such as 9 days ago)
%s Subject (first line of the message)
%d Branch and tag names
%n Newline

format: and tformat: differ in the final newline

format: and tformat: differ in whether a newline is added at the end of the output. format: puts a newline between commits, so the last commit has no newline after it. tformat: puts a newline at the end of each commit.

You can see the difference by printing text with echo right after one commit.

console
$ git log --pretty=format:"%h" -1; echo "(ここが次の行)"
97cacdb(ここが次の行)

$ git log --pretty=tformat:"%h" -1; echo "(ここが次の行)"
97cacdb
(ここが次の行)

With format:, the next text continues on the same line as the hash. When passing the output to a script or file that handles the output line by line, use tformat:, which ends the last line with a newline, or omit format:.

Align widths to make a table-like layout

If you place %<(N) before a placeholder, the output of the next placeholder is padded with spaces on the right until it reaches N columns. Here I padded the author name to 6 columns and separated the fields with |.

console
$ git log --pretty="%h %<(6)%an|%s"
97cacdb Neko  |トップ画面を追加
911e92d Tama  |ログイン画面を追加
e563966 Neko  |最初のコミット

You can also align Japanese subjects. I padded the subject to 20 columns. Each Japanese character counted as two columns, and the | positions lined up.

console
$ git log --pretty="%h %<(20)%s|%an"
97cacdb トップ画面を追加    |Neko
911e92d ログイン画面を追加  |Tama
e563966 最初のコミット      |Neko

Adding trunc as in %<(12,trunc) cuts a long subject at 12 columns and replaces the end with ...

console
$ git log --pretty="%h %<(12,trunc)%s|%an"
97cacdb トップ画面..|Neko
911e92d ログイン画..|Tama
e563966 最初のコミ..|Neko

%>(N) adds spaces on the left instead. However, text longer than the given width is not cut, and is printed as is. In this test, all three subjects were longer than 12 columns, so no spaces were added.

console
$ git log --pretty="%h %>(12)%s|%an"
97cacdb トップ画面を追加|Neko
911e92d ログイン画面を追加|Tama
e563966 最初のコミット|Neko

The explanation of %<(<N>) in the official reference warns that characters that take two columns, such as emoji, can extend past the aligned position.

Add colors

Placing %C(color name) adds color to the text that follows. %C(reset) returns to the default color. %C(auto) applies the colors that Git normally uses to items such as branch and tag names in %d.

The image below shows the test environment's terminal (xterm), where I ran a command without color and then a command with color.

Terminal screen showing two git log --pretty outputs stacked vertically. The top one has no color. The bottom one shows the hash in yellow, the branch and tag names in Git's default colors, and the author name in cyan.
Top: no color specified. Bottom: colors added with %C(…).

In the second command, the hash was yellow, HEAD was cyan, main was green, and tag: v1.0 was yellow. The author name appeared in the cyan I specified.

By default, color is used only when the output goes to a terminal. When I piped the output to another command, the %C(...) codes produced no color control characters. I checked the output bytes with od -c. Only with --color=always did the color control characters (033 [ 3 3 m) appear at the start.

console
$ git log --pretty="%C(yellow)%h%C(reset) %s" -1 | od -c | head -3
0000000   9   7   c   a   c   d   b     343 203 210 343 203 203 343 203
0000020 227 347 224 273 351 235 242 343 202 222 350 277 275 345 212 240
0000040  \n

$ git log --pretty="%C(yellow)%h%C(reset) %s" -1 --color=always | od -c | head -3
0000000 033   [   3   3   m   9   7   c   a   c   d   b 033   [   m    
0000020 343 203 210 343 203 203 343 203 227 347 224 273 351 235 242 343
0000040 202 222 350 277 275 345 212 240  \n

Save a format under a name and reuse it

To avoid typing a long string every time, you can give a format a name. Store it under pretty.<name> with git config, then call it with --pretty=<name>. Here I named it neko.

console
$ git config --global pretty.neko "%h %ad %an %s"

$ git log --pretty=neko --date=short
97cacdb 2026-11-03 Neko トップ画面を追加
911e92d 2026-11-02 Tama ログイン画面を追加
e563966 2026-11-01 Neko 最初のコミット

According to the description of pretty.<name> in the git config reference, if you use the same name as a built-in format such as oneline, the setting is silently ignored. Choose names that do not overlap with the built-in formats.

You can also set format.pretty to a name, so that git log without --pretty uses that format.

console
$ git config --global format.pretty neko

$ git log --date=short
97cacdb 2026-11-03 Neko トップ画面を追加
911e92d 2026-11-02 Tama ログイン画面を追加
e563966 2026-11-01 Neko 最初のコミット

Even with this setting, --pretty=medium still gave the original format for that command. After I removed the setting, git log went back to the default medium output.

console
$ git config --global --unset format.pretty

$ git log -1
commit 97cacdb097facdaea98d397d593669494f3f1ebc
Author: Neko <neko@example.com>
Date:   Tue Nov 3 09:15:00 2026 +0900

    トップ画面を追加

​Posted by 86