]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-interpret-trailers.txt
Merge branch 'js/update-urls-in-doc-and-comment' into maint-2.43
[thirdparty/git.git] / Documentation / git-interpret-trailers.txt
CommitLineData
dfd66ddf
CC
1git-interpret-trailers(1)
2=========================
3
4NAME
5----
a34dca24 6git-interpret-trailers - Add or parse structured information in commit messages
dfd66ddf
CC
7
8SYNOPSIS
9--------
10[verse]
d9054a19 11'git interpret-trailers' [--in-place] [--trim-empty]
6ccbc667 12 [(--trailer (<key>|<keyAlias>)[(=|:)<value>])...]
d9054a19 13 [--parse] [<file>...]
dfd66ddf
CC
14
15DESCRIPTION
16-----------
00432a36 17Add or parse 'trailer' lines that look similar to RFC 822 e-mail
dfd66ddf 18headers, at the end of the otherwise free-form part of a commit
d57fa7fc
LA
19message. For example, in the following commit message
20
21------------------------------------------------
22subject
23
24Lorem ipsum dolor sit amet, consectetur adipiscing elit.
25
26Signed-off-by: Alice <alice@example.com>
27Signed-off-by: Bob <bob@example.com>
28------------------------------------------------
29
30the last two lines starting with "Signed-off-by" are trailers.
dfd66ddf 31
94f15fe5
LA
32This command reads commit messages from either the
33<file> arguments or the standard input if no <file> is specified.
cb088cbe
LA
34If `--parse` is specified, the output consists of the parsed trailers
35coming from the input, without influencing them with any command line
36options or configuration variables.
db972961
LA
37
38Otherwise, this command applies `trailer.*` configuration variables
39(which could potentially add new trailers, as well as reposition them),
40as well as any command line arguments that can override configuration
41variables (such as `--trailer=...` which could also add new trailers),
42to each input file. The result is emitted on the standard output.
94f15fe5
LA
43
44This command can also operate on the output of linkgit:git-format-patch[1],
45which is more elaborate than a plain commit message. Namely, such output
46includes a commit message (as above), a "---" divider line, and a patch part.
47For these inputs, the divider and patch parts are not modified by
48this command and are emitted as is on the output, unless
49`--no-divider` is specified.
dfd66ddf
CC
50
51Some configuration variables control the way the `--trailer` arguments
94f15fe5
LA
52are applied to each input and the way any existing trailer in
53the input is changed. They also make it possible to
dfd66ddf
CC
54automatically add some trailers.
55
6ccbc667 56By default, a '<key>=<value>' or '<key>:<value>' argument given
dfd66ddf 57using `--trailer` will be appended after the existing trailers only if
6ccbc667
LA
58the last trailer has a different (<key>, <value>) pair (or if there
59is no existing trailer). The <key> and <value> parts will be trimmed
dfd66ddf 60to remove starting and trailing whitespace, and the resulting trimmed
6ccbc667 61<key> and <value> will appear in the output like this:
dfd66ddf
CC
62
63------------------------------------------------
6ccbc667 64key: value
dfd66ddf
CC
65------------------------------------------------
66
6ccbc667
LA
67This means that the trimmed <key> and <value> will be separated by
68`': '` (one colon followed by one space).
69
70For convenience, a <keyAlias> can be configured to make using `--trailer`
71shorter to type on the command line. This can be configured using the
72'trailer.<keyAlias>.key' configuration variable. The <keyAlias> must be a prefix
73of the full <key> string, although case sensitivity does not matter. For
74example, if you have
75
76------------------------------------------------
77trailer.sign.key "Signed-off-by: "
78------------------------------------------------
79
80in your configuration, you only need to specify `--trailer="sign: foo"`
81on the command line instead of `--trailer="Signed-off-by: foo"`.
dfd66ddf
CC
82
83By default the new trailer will appear at the end of all the existing
84trailers. If there is no existing trailer, the new trailer will appear
94f15fe5
LA
85at the end of the input. A blank line will be added before the new
86trailer if there isn't one already.
dfd66ddf 87
94f15fe5 88Existing trailers are extracted from the input by looking for
760f1ad1 89a group of one or more lines that (i) is all trailers, or (ii) contains at
df616b19
JT
90least one Git-generated or user-configured trailer and consists of at
91least 25% trailers.
14624506 92The group must be preceded by one or more empty (or whitespace-only) lines.
94f15fe5 93The group must either be at the end of the input or be the last
c188668e 94non-whitespace lines before a line that starts with '---' (followed by a
94f15fe5 95space or the end of the line).
dfd66ddf 96
b46dd172 97When reading trailers, there can be no whitespace before or inside the
6ccbc667
LA
98<key>, but any number of regular space and tab characters are allowed
99between the <key> and the separator. There can be whitespaces before,
8e80f291 100inside or after the <value>. The <value> may be split over multiple lines
b46dd172 101with each subsequent line starting with at least one whitespace, like
d57fa7fc
LA
102the "folding" in RFC 822. Example:
103
104------------------------------------------------
6ccbc667 105key: This is a very long value, with spaces and
d57fa7fc
LA
106 newlines in it.
107------------------------------------------------
dfd66ddf 108
74a50fbd
LA
109Note that trailers do not follow (nor are they intended to follow) many of the
110rules for RFC 822 headers. For example they do not follow the encoding rule.
dfd66ddf
CC
111
112OPTIONS
113-------
e1f89863
TK
114--in-place::
115 Edit the files in place.
116
dfd66ddf
CC
117--trim-empty::
118 If the <value> part of any trailer contains only whitespace,
229d6ab6 119 the whole trailer will be removed from the output.
a43eb67e 120 This applies to existing trailers as well as new trailers.
dfd66ddf 121
6ccbc667
LA
122--trailer <key>[(=|:)<value>]::
123 Specify a (<key>, <value>) pair that should be applied as a
229d6ab6 124 trailer to the inputs. See the description of this
dfd66ddf
CC
125 command.
126
0ea5292e
PB
127--where <placement>::
128--no-where::
129 Specify where all new trailers will be added. A setting
f659c56a 130 provided with '--where' overrides the `trailer.where` and any
6ccbc667 131 applicable `trailer.<keyAlias>.where` configuration variables
0ea5292e 132 and applies to all '--trailer' options until the next occurrence of
73574f21
LA
133 '--where' or '--no-where'. Upon encountering '--no-where', clear the
134 effect of any previous use of '--where', such that the relevant configuration
467bb1b9 135 variables are no longer overridden. Possible placements are `after`,
73574f21 136 `before`, `end` or `start`.
0ea5292e
PB
137
138--if-exists <action>::
139--no-if-exists::
140 Specify what action will be performed when there is already at
6ccbc667 141 least one trailer with the same <key> in the input. A setting
f659c56a 142 provided with '--if-exists' overrides the `trailer.ifExists` and any
6ccbc667 143 applicable `trailer.<keyAlias>.ifExists` configuration variables
0ea5292e 144 and applies to all '--trailer' options until the next occurrence of
73574f21
LA
145 '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the
146 effect of any previous use of '--if-exists, such that the relevant configuration
147 variables are no longer overridden. Possible actions are `addIfDifferent`,
1e83b9bf 148 `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
0ea5292e
PB
149
150--if-missing <action>::
151--no-if-missing::
152 Specify what action will be performed when there is no other
6ccbc667 153 trailer with the same <key> in the input. A setting
f659c56a 154 provided with '--if-missing' overrides the `trailer.ifMissing` and any
6ccbc667 155 applicable `trailer.<keyAlias>.ifMissing` configuration variables
0ea5292e 156 and applies to all '--trailer' options until the next occurrence of
73574f21
LA
157 '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing,
158 clear the effect of any previous use of '--if-missing, such that the relevant
159 configuration variables are no longer overridden. Possible actions are `doNothing`
1e83b9bf 160 or `add`.
0ea5292e 161
56c493ed
JK
162--only-trailers::
163 Output only the trailers, not any other parts of the input.
164
fdbdb64f
JK
165--only-input::
166 Output only trailers that exist in the input; do not add any
a6c72e70
LA
167 from the command-line or by applying `trailer.*` configuration
168 variables.
fdbdb64f 169
00002396 170--unfold::
289a0b24
LA
171 If a trailer has a value that runs over multiple lines (aka "folded"),
172 reformat the value into a single line.
00002396 173
99e09daf
JK
174--parse::
175 A convenience alias for `--only-trailers --only-input
cb088cbe
LA
176 --unfold`. This makes it easier to only see the trailers coming from the
177 input without influencing them with any command line options or
178 configuration variables, while also making the output machine-friendly with
179 --unfold.
99e09daf 180
1688c9a4
JK
181--no-divider::
182 Do not treat `---` as the end of the commit message. Use this
183 when you know your input contains just the commit message itself
184 (and not an email or the output of `git format-patch`).
185
dfd66ddf
CC
186CONFIGURATION VARIABLES
187-----------------------
188
189trailer.separators::
190 This option tells which characters are recognized as trailer
191 separators. By default only ':' is recognized as a trailer
192 separator, except that '=' is always accepted on the command
193 line for compatibility with other git commands.
194+
195The first character given by this option will be the default character
196used when another separator is not specified in the config for this
197trailer.
198+
199For example, if the value for this option is "%=$", then only lines
6ccbc667 200using the format '<key><sep><value>' with <sep> containing '%', '='
dfd66ddf
CC
201or '$' and then spaces will be considered trailers. And '%' will be
202the default separator used, so by default trailers will appear like:
6ccbc667
LA
203'<key>% <value>' (one percent sign and one space will appear between
204the key and the value).
dfd66ddf
CC
205
206trailer.where::
207 This option tells where a new trailer will be added.
208+
209This can be `end`, which is the default, `start`, `after` or `before`.
210+
211If it is `end`, then each new trailer will appear at the end of the
212existing trailers.
213+
214If it is `start`, then each new trailer will appear at the start,
215instead of the end, of the existing trailers.
216+
217If it is `after`, then each new trailer will appear just after the
6ccbc667 218last trailer with the same <key>.
dfd66ddf
CC
219+
220If it is `before`, then each new trailer will appear just before the
6ccbc667 221first trailer with the same <key>.
dfd66ddf
CC
222
223trailer.ifexists::
224 This option makes it possible to choose what action will be
225 performed when there is already at least one trailer with the
6ccbc667 226 same <key> in the input.
dfd66ddf
CC
227+
228The valid values for this option are: `addIfDifferentNeighbor` (this
b275da81 229is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
dfd66ddf
CC
230+
231With `addIfDifferentNeighbor`, a new trailer will be added only if no
6ccbc667 232trailer with the same (<key>, <value>) pair is above or below the line
dfd66ddf
CC
233where the new trailer will be added.
234+
235With `addIfDifferent`, a new trailer will be added only if no trailer
6ccbc667 236with the same (<key>, <value>) pair is already in the input.
dfd66ddf
CC
237+
238With `add`, a new trailer will be added, even if some trailers with
6ccbc667 239the same (<key>, <value>) pair are already in the input.
dfd66ddf 240+
6ccbc667 241With `replace`, an existing trailer with the same <key> will be
dfd66ddf 242deleted and the new trailer will be added. The deleted trailer will be
6ccbc667 243the closest one (with the same <key>) to the place where the new one
dfd66ddf
CC
244will be added.
245+
246With `doNothing`, nothing will be done; that is no new trailer will be
6ccbc667 247added if there is already one with the same <key> in the input.
dfd66ddf
CC
248
249trailer.ifmissing::
250 This option makes it possible to choose what action will be
251 performed when there is not yet any trailer with the same
6ccbc667 252 <key> in the input.
dfd66ddf
CC
253+
254The valid values for this option are: `add` (this is the default) and
255`doNothing`.
256+
257With `add`, a new trailer will be added.
258+
259With `doNothing`, nothing will be done.
260
6ccbc667
LA
261trailer.<keyAlias>.key::
262 Defines a <keyAlias> for the <key>. The <keyAlias> must be a
263 prefix (case does not matter) of the <key>. For example, in `git
264 config trailer.ack.key "Acked-by"` the "Acked-by" is the <key> and
265 the "ack" is the <keyAlias>. This configuration allows the shorter
266 `--trailer "ack:..."` invocation on the command line using the "ack"
267 <keyAlias> instead of the longer `--trailer "Acked-by:..."`.
268+
269At the end of the <key>, a separator can appear and then some
270space characters. By default the only valid separator is ':',
271but this can be changed using the `trailer.separators` config
272variable.
dfd66ddf 273+
ab76661f
LA
274If there is a separator in the key, then it overrides the default
275separator when adding the trailer.
dfd66ddf 276
6ccbc667 277trailer.<keyAlias>.where::
dfd66ddf
CC
278 This option takes the same values as the 'trailer.where'
279 configuration variable and it overrides what is specified by
6ccbc667 280 that option for trailers with the specified <keyAlias>.
dfd66ddf 281
6ccbc667 282trailer.<keyAlias>.ifexists::
c88bf543 283 This option takes the same values as the 'trailer.ifexists'
dfd66ddf 284 configuration variable and it overrides what is specified by
6ccbc667 285 that option for trailers with the specified <keyAlias>.
dfd66ddf 286
6ccbc667 287trailer.<keyAlias>.ifmissing::
dfd66ddf
CC
288 This option takes the same values as the 'trailer.ifmissing'
289 configuration variable and it overrides what is specified by
6ccbc667 290 that option for trailers with the specified <keyAlias>.
dfd66ddf 291
6ccbc667
LA
292trailer.<keyAlias>.command::
293 Deprecated in favor of 'trailer.<keyAlias>.cmd'.
294 This option behaves in the same way as 'trailer.<keyAlias>.cmd', except
c364b7ef
ZH
295 that it doesn't pass anything as argument to the specified command.
296 Instead the first occurrence of substring $ARG is replaced by the
8e80f291 297 <value> that would be passed as argument.
c364b7ef 298+
dc8937fb 299Note that $ARG in the user's command is
c364b7ef
ZH
300only replaced once and that the original way of replacing $ARG is not safe.
301+
6ccbc667
LA
302When both 'trailer.<keyAlias>.cmd' and 'trailer.<keyAlias>.command' are given
303for the same <keyAlias>, 'trailer.<keyAlias>.cmd' is used and
304'trailer.<keyAlias>.command' is ignored.
c364b7ef 305
6ccbc667 306trailer.<keyAlias>.cmd::
bfb5f57b 307 This option can be used to specify a shell command that will be called
6ccbc667
LA
308 once to automatically add a trailer with the specified <keyAlias>, and then
309 called each time a '--trailer <keyAlias>=<value>' argument is specified to
bfb5f57b 310 modify the <value> of the trailer that this option would produce.
dfd66ddf 311+
57dcb657 312When the specified command is first called to add a trailer
6ccbc667
LA
313with the specified <keyAlias>, the behavior is as if a special
314'--trailer <keyAlias>=<value>' argument was added at the beginning
57dcb657
ZH
315of the "git interpret-trailers" command, where <value>
316is taken to be the standard output of the command with any
317leading and trailing whitespace trimmed off.
dfd66ddf 318+
6ccbc667 319If some '--trailer <keyAlias>=<value>' arguments are also passed
57dcb657 320on the command line, the command is called again once for each
6ccbc667 321of these arguments with the same <keyAlias>. And the <value> part
c364b7ef
ZH
322of these arguments, if any, will be passed to the command as its
323first argument. This way the command can produce a <value> computed
6ccbc667 324from the <value> passed in the '--trailer <keyAlias>=<value>' argument.
dfd66ddf
CC
325
326EXAMPLES
327--------
328
329* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
229d6ab6 330 add two of these trailers to a commit message file:
dfd66ddf
CC
331+
332------------
333$ git config trailer.sign.key "Signed-off-by"
334$ cat msg.txt
335subject
336
229d6ab6 337body text
b032a2bf 338$ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
dfd66ddf
CC
339subject
340
229d6ab6 341body text
dfd66ddf
CC
342
343Signed-off-by: Alice <alice@example.com>
344Signed-off-by: Bob <bob@example.com>
345------------
346
229d6ab6 347* Use the `--in-place` option to edit a commit message file in place:
e1f89863
TK
348+
349------------
350$ cat msg.txt
351subject
352
229d6ab6 353body text
e1f89863
TK
354
355Signed-off-by: Bob <bob@example.com>
356$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
357$ cat msg.txt
358subject
359
229d6ab6 360body text
e1f89863
TK
361
362Signed-off-by: Bob <bob@example.com>
363Acked-by: Alice <alice@example.com>
364------------
365
dfd66ddf
CC
366* Extract the last commit as a patch, and add a 'Cc' and a
367 'Reviewed-by' trailer to it:
368+
369------------
370$ git format-patch -1
3710001-foo.patch
372$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
373------------
374
375* Configure a 'sign' trailer with a command to automatically add a
376 'Signed-off-by: ' with the author information only if there is no
377 'Signed-off-by: ' already, and show how it works:
378+
379------------
cbb83dae
KH
380$ cat msg1.txt
381subject
382
229d6ab6 383body text
dfd66ddf
CC
384$ git config trailer.sign.key "Signed-off-by: "
385$ git config trailer.sign.ifmissing add
386$ git config trailer.sign.ifexists doNothing
f68c2687 387$ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"'
cbb83dae
KH
388$ git interpret-trailers --trailer sign <msg1.txt
389subject
390
229d6ab6 391body text
dfd66ddf
CC
392
393Signed-off-by: Bob <bob@example.com>
cbb83dae
KH
394$ cat msg2.txt
395subject
396
229d6ab6 397body text
cbb83dae 398
c892bcc9 399Signed-off-by: Alice <alice@example.com>
cbb83dae
KH
400$ git interpret-trailers --trailer sign <msg2.txt
401subject
402
229d6ab6 403body text
dfd66ddf
CC
404
405Signed-off-by: Alice <alice@example.com>
406------------
407
408* Configure a 'fix' trailer with a key that contains a '#' and no
409 space after this character, and show how it works:
410+
411------------
412$ git config trailer.separators ":#"
413$ git config trailer.fix.key "Fix #"
414$ echo "subject" | git interpret-trailers --trailer fix=42
415subject
416
417Fix #42
418------------
419
c364b7ef
ZH
420* Configure a 'help' trailer with a cmd use a script `glog-find-author`
421 which search specified author identity from git log in git repository
422 and show how it works:
423+
424------------
425$ cat ~/bin/glog-find-author
426#!/bin/sh
427test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
c892bcc9
KH
428$ cat msg.txt
429subject
430
229d6ab6 431body text
c364b7ef
ZH
432$ git config trailer.help.key "Helped-by: "
433$ git config trailer.help.ifExists "addIfDifferentNeighbor"
434$ git config trailer.help.cmd "~/bin/glog-find-author"
c892bcc9 435$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
c364b7ef
ZH
436subject
437
229d6ab6 438body text
c364b7ef
ZH
439
440Helped-by: Junio C Hamano <gitster@pobox.com>
441Helped-by: Christian Couder <christian.couder@gmail.com>
442------------
443
444* Configure a 'ref' trailer with a cmd use a script `glog-grep`
445 to grep last relevant commit from git log in the git repository
446 and show how it works:
447+
448------------
449$ cat ~/bin/glog-grep
450#!/bin/sh
451test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
c892bcc9
KH
452$ cat msg.txt
453subject
454
229d6ab6 455body text
c364b7ef
ZH
456$ git config trailer.ref.key "Reference-to: "
457$ git config trailer.ref.ifExists "replace"
458$ git config trailer.ref.cmd "~/bin/glog-grep"
c892bcc9 459$ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
c364b7ef
ZH
460subject
461
229d6ab6 462body text
c364b7ef
ZH
463
464Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
465------------
466
dfd66ddf
CC
467* Configure a 'see' trailer with a command to show the subject of a
468 commit that is related, and show how it works:
469+
470------------
c892bcc9
KH
471$ cat msg.txt
472subject
473
229d6ab6 474body text
c892bcc9
KH
475
476see: HEAD~2
f68c2687
KH
477$ cat ~/bin/glog-ref
478#!/bin/sh
479git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
dfd66ddf
CC
480$ git config trailer.see.key "See-also: "
481$ git config trailer.see.ifExists "replace"
482$ git config trailer.see.ifMissing "doNothing"
f68c2687
KH
483$ git config trailer.see.cmd "glog-ref"
484$ git interpret-trailers --trailer=see <msg.txt
dfd66ddf
CC
485subject
486
229d6ab6 487body text
dfd66ddf
CC
488
489See-also: fe3187489d69c4 (subject of related commit)
490------------
491
492* Configure a commit template with some trailers with empty values
493 (using sed to show and keep the trailing spaces at the end of the
494 trailers), then configure a commit-msg hook that uses
495 'git interpret-trailers' to remove trailers with empty values and
496 to add a 'git-version' trailer:
497+
498------------
c892bcc9
KH
499$ cat temp.txt
500***subject***
501
502***message***
503
504Fixes: Z
505Cc: Z
506Reviewed-by: Z
507Signed-off-by: Z
508$ sed -e 's/ Z$/ /' temp.txt > commit_template.txt
dfd66ddf 509$ git config commit.template commit_template.txt
c892bcc9
KH
510$ cat .git/hooks/commit-msg
511#!/bin/sh
512git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
513mv "\$1.new" "\$1"
dfd66ddf
CC
514$ chmod +x .git/hooks/commit-msg
515------------
516
517SEE ALSO
518--------
519linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
520
521GIT
522---
523Part of the linkgit:git[1] suite