]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/pretty-formats.txt
pretty tests: give --date/format tests a better description
[thirdparty/git.git] / Documentation / pretty-formats.txt
CommitLineData
331b51d2
JN
1PRETTY FORMATS
2--------------
3
4If the commit is a merge, and if the pretty-format
5is not 'oneline', 'email' or 'raw', an additional line is
6inserted before the 'Author:' line. This line begins with
bae74c9d 7"Merge: " and the hashes of ancestral commits are printed,
331b51d2
JN
8separated by spaces. Note that the listed commits may not
9necessarily be the list of the *direct* parent commits if you
10have limited your view of history: for example, if you are
11only interested in changes related to a certain directory or
12file.
13
8028184e
WP
14There are several built-in formats, and you can define
15additional formats by setting a pretty.<name>
16config option to either another format name, or a
17'format:' string, as described below (see
18linkgit:git-config[1]). Here are the details of the
19built-in formats:
331b51d2
JN
20
21* 'oneline'
5d1faf87 22
bae74c9d 23 <hash> <title line>
5d1faf87
CR
24+
25This is designed to be as compact as possible.
26
331b51d2 27* 'short'
5d1faf87 28
bae74c9d 29 commit <hash>
5d1faf87
CR
30 Author: <author>
31
32 <title line>
33
331b51d2 34* 'medium'
5d1faf87 35
bae74c9d 36 commit <hash>
5d1faf87 37 Author: <author>
ec9f0ea3 38 Date: <author date>
5d1faf87
CR
39
40 <title line>
41
42 <full commit message>
43
331b51d2 44* 'full'
5d1faf87 45
bae74c9d 46 commit <hash>
5d1faf87
CR
47 Author: <author>
48 Commit: <committer>
49
50 <title line>
51
52 <full commit message>
53
331b51d2 54* 'fuller'
5d1faf87 55
bae74c9d 56 commit <hash>
ec9f0ea3 57 Author: <author>
2b2da684 58 AuthorDate: <author date>
ec9f0ea3 59 Commit: <committer>
2b2da684 60 CommitDate: <committer date>
5d1faf87
CR
61
62 <title line>
63
64 <full commit message>
65
1f0fc1db
DL
66* 'reference'
67
68 <abbrev hash> (<title line>, <short author date>)
69+
70This format is used to refer to another commit in a commit message and
71is the same as `--pretty='format:%C(auto)%h (%s, %ad)'`. By default,
72the date is formatted with `--date=short` unless another `--date` option
73is explicitly specified. As with any `format:` with format
74placeholders, its output is not affected by other options like
75`--decorate` and `--walk-reflogs`.
76
331b51d2 77* 'email'
5d1faf87 78
bae74c9d 79 From <hash> <date>
5d1faf87 80 From: <author>
2b2da684 81 Date: <author date>
5d1faf87
CR
82 Subject: [PATCH] <title line>
83
331b51d2 84 <full commit message>
5d1faf87 85
88eaf361
EB
86* 'mboxrd'
87+
88Like 'email', but lines in the commit message starting with "From "
89(preceded by zero or more ">") are quoted with ">" so they aren't
90confused as starting a new commit.
91
331b51d2 92* 'raw'
5d1faf87
CR
93+
94The 'raw' format shows the entire commit exactly as
bae74c9d 95stored in the commit object. Notably, the hashes are
5d1faf87
CR
96displayed in full, regardless of whether --abbrev or
97--no-abbrev are used, and 'parents' information show the
a58088ab 98true parent commits, without taking grafts or history
92de9217
MM
99simplification into account. Note that this format affects the way
100commits are displayed, but not the way the diff is shown e.g. with
101`git log --raw`. To get full object names in a raw diff format,
102use `--no-abbrev`.
7cbcf4d5 103
41e4d69f 104* 'format:<string>'
e52a5de4 105+
41e4d69f 106The 'format:<string>' format allows you to specify which information
e52a5de4
JS
107you want to show. It works a little bit like printf format,
108with the notable exception that you get a newline with '%n'
109instead of '\n'.
331b51d2
JN
110+
111E.g, 'format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"'
e52a5de4 112would show something like this:
331b51d2
JN
113+
114-------
e52a5de4
JS
115The author of fe6e0ee was Junio C Hamano, 23 hours ago
116The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
117
c30c43c0 118-------
331b51d2 119+
e52a5de4
JS
120The placeholders are:
121
42617752
AW
122- Placeholders that expand to a single literal character:
123'%n':: newline
124'%%':: a raw '%'
125'%x00':: print a byte from a hex code
126
127- Placeholders that affect formatting of later placeholders:
128'%Cred':: switch color to red
129'%Cgreen':: switch color to green
130'%Cblue':: switch color to blue
131'%Creset':: reset color
132'%C(...)':: color specification, as described under Values in the
133 "CONFIGURATION FILE" section of linkgit:git-config[1]. By
134 default, colors are shown only when enabled for log output
135 (by `color.diff`, `color.ui`, or `--color`, and respecting
136 the `auto` settings of the former if we are going to a
137 terminal). `%C(auto,...)` is accepted as a historical
138 synonym for the default (e.g., `%C(auto,red)`). Specifying
42977bf5 139 `%C(always,...)` will show the colors even when color is
42617752
AW
140 not otherwise enabled (though consider just using
141 `--color=always` to enable color for the whole output,
142 including this format and anything else git might color).
143 `auto` alone (i.e. `%C(auto)`) will turn on auto coloring
144 on the next placeholders until the color is switched
145 again.
146'%m':: left (`<`), right (`>`) or boundary (`-`) mark
147'%w([<w>[,<i1>[,<i2>]]])':: switch line wrapping, like the -w option of
148 linkgit:git-shortlog[1].
149'%<(<N>[,trunc|ltrunc|mtrunc])':: make the next placeholder take at
150 least N columns, padding spaces on
151 the right if necessary. Optionally
152 truncate at the beginning (ltrunc),
153 the middle (mtrunc) or the end
154 (trunc) if the output is longer than
155 N columns. Note that truncating
156 only works correctly with N >= 2.
157'%<|(<N>)':: make the next placeholder take at least until Nth
158 columns, padding spaces on the right if necessary
159'%>(<N>)', '%>|(<N>)':: similar to '%<(<N>)', '%<|(<N>)' respectively,
160 but padding spaces on the left
161'%>>(<N>)', '%>>|(<N>)':: similar to '%>(<N>)', '%>|(<N>)'
162 respectively, except that if the next
163 placeholder takes more spaces than given and
164 there are spaces on its left, use those
165 spaces
166'%><(<N>)', '%><|(<N>)':: similar to '%<(<N>)', '%<|(<N>)'
167 respectively, but padding both sides
168 (i.e. the text is centered)
169
170- Placeholders that expand to information extracted from the commit:
171'%H':: commit hash
172'%h':: abbreviated commit hash
173'%T':: tree hash
174'%t':: abbreviated tree hash
175'%P':: parent hashes
176'%p':: abbreviated parent hashes
177'%an':: author name
178'%aN':: author name (respecting .mailmap, see linkgit:git-shortlog[1]
179 or linkgit:git-blame[1])
180'%ae':: author email
181'%aE':: author email (respecting .mailmap, see linkgit:git-shortlog[1]
182 or linkgit:git-blame[1])
d8b8217c
PB
183'%al':: author email local-part (the part before the '@' sign)
184'%aL':: author local-part (see '%al') respecting .mailmap, see
185 linkgit:git-shortlog[1] or linkgit:git-blame[1])
42617752
AW
186'%ad':: author date (format respects --date= option)
187'%aD':: author date, RFC2822 style
188'%ar':: author date, relative
189'%at':: author date, UNIX timestamp
190'%ai':: author date, ISO 8601-like format
191'%aI':: author date, strict ISO 8601 format
0df62117 192'%as':: author date, short format (`YYYY-MM-DD`)
42617752
AW
193'%cn':: committer name
194'%cN':: committer name (respecting .mailmap, see
195 linkgit:git-shortlog[1] or linkgit:git-blame[1])
196'%ce':: committer email
197'%cE':: committer email (respecting .mailmap, see
198 linkgit:git-shortlog[1] or linkgit:git-blame[1])
087bf540
MK
199'%cl':: committer email local-part (the part before the '@' sign)
200'%cL':: committer local-part (see '%cl') respecting .mailmap, see
d8b8217c 201 linkgit:git-shortlog[1] or linkgit:git-blame[1])
42617752
AW
202'%cd':: committer date (format respects --date= option)
203'%cD':: committer date, RFC2822 style
204'%cr':: committer date, relative
205'%ct':: committer date, UNIX timestamp
206'%ci':: committer date, ISO 8601-like format
207'%cI':: committer date, strict ISO 8601 format
0df62117 208'%cs':: committer date, short format (`YYYY-MM-DD`)
42617752
AW
209'%d':: ref names, like the --decorate option of linkgit:git-log[1]
210'%D':: ref names without the " (", ")" wrapping.
b081547e
RS
211'%(describe[:options])':: human-readable name, like
212 linkgit:git-describe[1]; empty string for
213 undescribable commits. The `describe` string
214 may be followed by a colon and zero or more
273c9901
RS
215 comma-separated options. Descriptions can be
216 inconsistent when tags are added or removed at
217 the same time.
b081547e
RS
218+
219** 'match=<pattern>': Only consider tags matching the given
220 `glob(7)` pattern, excluding the "refs/tags/" prefix.
221** 'exclude=<pattern>': Do not consider tags matching the given
222 `glob(7)` pattern, excluding the "refs/tags/" prefix.
223
42977bf5
JH
224'%S':: ref name given on the command line by which the commit was reached
225 (like `git log --source`), only works with `git log`
42617752
AW
226'%e':: encoding
227'%s':: subject
228'%f':: sanitized subject line, suitable for a filename
229'%b':: body
230'%B':: raw body (unwrapped subject and body)
2aea7a51 231ifndef::git-rev-list[]
42617752 232'%N':: commit notes
2aea7a51 233endif::git-rev-list[]
42617752
AW
234'%GG':: raw verification message from GPG for a signed commit
235'%G?':: show "G" for a good (valid) signature,
236 "B" for a bad signature,
237 "U" for a good signature with unknown validity,
238 "X" for a good signature that has expired,
239 "Y" for a good signature made by an expired key,
240 "R" for a good signature made by a revoked key,
241 "E" if the signature cannot be checked (e.g. missing key)
242 and "N" for no signature
243'%GS':: show the name of the signer for a signed commit
244'%GK':: show the key used to sign a signed commit
245'%GF':: show the fingerprint of the key used to sign a signed commit
246'%GP':: show the fingerprint of the primary key whose subkey was used
247 to sign a signed commit
54887b46 248'%GT':: show the trust level for the key used to sign a signed commit
42617752 249'%gD':: reflog selector, e.g., `refs/stash@{1}` or `refs/stash@{2
4fd39c76 250 minutes ago}`; the format follows the rules described for the
42617752
AW
251 `-g` option. The portion before the `@` is the refname as
252 given on the command line (so `git log -g refs/heads/master`
253 would yield `refs/heads/master@{0}`).
254'%gd':: shortened reflog selector; same as `%gD`, but the refname
255 portion is shortened for human readability (so
256 `refs/heads/master` becomes just `master`).
257'%gn':: reflog identity name
258'%gN':: reflog identity name (respecting .mailmap, see
259 linkgit:git-shortlog[1] or linkgit:git-blame[1])
260'%ge':: reflog identity email
261'%gE':: reflog identity email (respecting .mailmap, see
262 linkgit:git-shortlog[1] or linkgit:git-blame[1])
263'%gs':: reflog subject
264'%(trailers[:options])':: display the trailers of the body as
265 interpreted by
266 linkgit:git-interpret-trailers[1]. The
267 `trailers` string may be followed by a colon
2762e171
ÆAB
268 and zero or more comma-separated options.
269 If any option is provided multiple times the
270 last occurance wins.
271+
272The boolean options accept an optional value `[=<BOOL>]`. The values
273`true`, `false`, `on`, `off` etc. are all accepted. See the "boolean"
274sub-section in "EXAMPLES" in linkgit:git-config[1]. If a boolean
275option is given with no value, it's enabled.
276+
250bea0c
AW
277** 'key=<K>': only show trailers with specified key. Matching is done
278 case-insensitively and trailing colon is optional. If option is
279 given multiple times trailer lines matching any of the keys are
280 shown. This option automatically enables the `only` option so that
281 non-trailer lines in the trailer block are hidden. If that is not
282 desired it can be disabled with `only=false`. E.g.,
283 `%(trailers:key=Reviewed-by)` shows trailer lines with key
284 `Reviewed-by`.
2762e171
ÆAB
285** 'only[=<BOOL>]': select whether non-trailer lines from the trailer
286 block should be included.
0b691d86
AW
287** 'separator=<SEP>': specify a separator inserted between trailer
288 lines. When this option is not given each trailer line is
289 terminated with a line feed character. The string SEP may contain
290 the literal formatting codes described above. To use comma as
291 separator one must use `%x2C` as it would otherwise be parsed as
2762e171 292 next option. E.g., `%(trailers:key=Ticket,separator=%x2C )`
0b691d86
AW
293 shows all trailer lines whose key is "Ticket" separated by a comma
294 and a space.
2762e171
ÆAB
295** 'unfold[=<BOOL>]': make it behave as if interpret-trailer's `--unfold`
296 option was given. E.g.,
4f732e0f 297 `%(trailers:only,unfold=true)` unfolds and shows all trailer lines.
9d87d5ae
ÆAB
298** 'keyonly[=<BOOL>]': only show the key part of the trailer.
299** 'valueonly[=<BOOL>]': only show the value part of the trailer.
058761f1
ÆAB
300** 'key_value_separator=<SEP>': specify a separator inserted between
301 trailer lines. When this option is not given each trailer key-value
302 pair is separated by ": ". Otherwise it shares the same semantics
303 as 'separator=<SEP>' above.
fa5b4f37 304
8f8f5476
TR
305NOTE: Some placeholders may depend on other options given to the
306revision traversal engine. For example, the `%g*` reflog options will
307insert an empty string unless we are traversing reflog entries (e.g., by
9271095c
HJ
308`git log -g`). The `%d` and `%D` placeholders will use the "short"
309decoration format if `--decorate` was not already provided on the command
310line.
8f8f5476 311
6cf378f0 312If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
9fa708da
JH
313is inserted immediately before the expansion if and only if the
314placeholder expands to a non-empty string.
315
8abc09c0
SG
316If you add a `-` (minus sign) after '%' of a placeholder, all consecutive
317line-feeds immediately preceding the expansion are deleted if and only if the
9fa708da
JH
318placeholder expands to an empty string.
319
7b88176e
MG
320If you add a ` ` (space) after '%' of a placeholder, a space
321is inserted immediately before the expansion if and only if the
322placeholder expands to a non-empty string.
323
fa5b4f37
JK
324* 'tformat:'
325+
326The 'tformat:' format works exactly like 'format:', except that it
327provides "terminator" semantics instead of "separator" semantics. In
328other words, each commit has the message terminator character (usually a
329newline) appended, rather than a separator placed between entries.
330This means that the final entry of a single-line format will be properly
331terminated with a new line, just as the "oneline" format does.
332For example:
333+
334---------------------
335$ git log -2 --pretty=format:%h 4da45bef \
336 | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
3374da45be
3387134973 -- NO NEWLINE
339
340$ git log -2 --pretty=tformat:%h 4da45bef \
341 | perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
3424da45be
3437134973
344---------------------
36407548
NS
345+
346In addition, any unrecognized string that has a `%` in it is interpreted
347as if it has `tformat:` in front of it. For example, these two are
348equivalent:
349+
350---------------------
351$ git log -2 --pretty=tformat:%h 4da45bef
352$ git log -2 --pretty=%h 4da45bef
353---------------------