Placeholders
Placeholders start with a percent sign
%
(in the same sprit as also used in the
printf
family). The following simple format prints the log's
subjects (
%s
).
git log --pretty=%s
If placeholders are separated by spaces, the format must be put into (single or double) quotes:
git log --pretty='%s %H'
In the following tables, the percent sign is not shown for readability.
Hash related placeholders
long | abbreviated | |
H | h | commit hash |
T | t | tree hash |
P | p | parent hash |
The long hash is represented with 40 characters, the abbreviated hash with 7 characters.
Related to author (%a…, %c…)
Placeholders that are related to a commit's author start with %a
, those related to a committer with %c
.
So, %an
is the name of the author, %cn
the name of the committer.
| Respecting .mailmap | |
n | N | Name |
e | E | eMail |
l | L | The email's portion left of the at (@ ) sign (local part) |
The following formats relate to the commit dates. Again, they're prefixed with %a
or %c
.
| | Example |
d | Date, respects --date= option | |
D | Date in RFC 2822 format | Mon, 25 Apr 2022 23:53:09 +0200 |
r | Relative format | 15 hours ago , 9 days ago or 3 weeks ago etc. |
t | In Unix time | 1653998153 (seconds since 1970-01-01) |
i | In ISO 8601 format | 2022-05-02 15:49:11 +0200 |
I | In strict ISO 8601 format | 2022-05-02T15:49:11+02:00 |
s | Short format | 2022-05-12 |
h | Human format | |
git log --date=format:'%Y-%m-%d %H:%M:%S' --pretty='%ad %<(20)%ar %s'
Ref names
Compare with the --decorate
option of git log
d | |
D | without the ", wrapping |
...
s | subject (aka title). %s vs %f[Compare with %f \ |
b | body |
B | raw body (unwrapped subject and body) |
N | commit notes |
f | sanitized subject line, compare with %s |
e | encoding |
Related to reflog
gD | reflog selector |
gd | shortened reflog selector (refs/heads/master becomes master ) |
gs | reflog subject |
gn | reflog identity name |
gN | reflog identity name (respecting .mailmap ) |
ge | reflog identity email |
gE | reflog identity email (respecting .mailmap ) |
Related to signed commits
GG | raw verification message from GPG for a signed commit |
G? | Reports «quality» of signed message: G = good; B = bad; U = good with unknown validity; X = good, but expired; Y = good signature made by expired key; R = good signature made be revoked key; E = signature cannot be checked (because of missing key?); N = no signature |
GS | Name of signer |
GK | Key used for signing |
GF | Fingerprint of key |
GP | Fingreprint of primary key whose subkey was used sign a signed commit |
GT | Trust level of key |
Insert a character
n | New line |
% | A percent sign |
xnn | The byte represented by the hexadecimal value nn |
Aligning/padding output
<(w) | Pad next token to at least w characters |
<(w,trunc) | Pad next token to w characters, trunctate exceeding characters (There is also ltrunc and mtrunc ). |
<|(w) | |
>(w) etc. | Similar to <(w) etc, but padding on left side |
><(w) | centering text |
>>(w) | |
git log --pretty='%<(50,trunc) %s %H'
Colors
%C…
affects the colors of the placeholders following the instruction.
Three color names are recognized: red
, green
and blue
.
An RGB value can be specified with %C(#rrggbb)
. The following command prints the subject (%s) in orange and the commit hash (
%H`) in a blue-ish color:
git log --pretty='%C(#ff7f00) %s %C(#6090e0) %h %Creset'
Others
m | A left (< ), right (> ) or boundary (- ) mark. |
TODO
Line wrapping mode (compare git shortlog -w…
)
git log --pretty='%w(40,6,7) %s %H bla'
Human readable format (like git describe
)
git log --pretty='%(describe)'
ref name given on the command line by which the commit was reached (like git log --source
)
git log --pretty='%S'
git log --pretty='%(trailers[:options])'
%s vs %f
%f
sees to replace adjacent spaces, colons, apostrophes, slashes etc. with one hyphen:
$ ~/linux git log -1 --format=%s ; git log -1 --format=%f
Merge tag 'gpio-fixes-for-v6.7-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Merge-tag-gpio-fixes-for-v6.7-rc8-of-git-git.kernel.org-pub-scm-linux-kernel-git-brgl-linux