1GIT-INTERPRET-TRAILERS(1)         Git Manual         GIT-INTERPRET-TRAILERS(1)
2
3
4

NAME

6       git-interpret-trailers - Add or parse structured information in commit
7       messages
8

SYNOPSIS

10       git interpret-trailers [--in-place] [--trim-empty]
11                               [(--trailer (<key>|<keyAlias>)[(=|:)<value>])...]
12                               [--parse] [<file>...]
13

DESCRIPTION

15       Add or parse trailer lines that look similar to RFC 822 e-mail headers,
16       at the end of the otherwise free-form part of a commit message. For
17       example, in the following commit message
18
19           subject
20
21           Lorem ipsum dolor sit amet, consectetur adipiscing elit.
22
23           Signed-off-by: Alice <alice@example.com>
24           Signed-off-by: Bob <bob@example.com>
25
26       the last two lines starting with "Signed-off-by" are trailers.
27
28       This command reads commit messages from either the <file> arguments or
29       the standard input if no <file> is specified. If --parse is specified,
30       the output consists of the parsed trailers coming from the input,
31       without influencing them with any command line options or configuration
32       variables.
33
34       Otherwise, this command applies trailer.* configuration variables
35       (which could potentially add new trailers, as well as reposition them),
36       as well as any command line arguments that can override configuration
37       variables (such as --trailer=... which could also add new trailers), to
38       each input file. The result is emitted on the standard output.
39
40       This command can also operate on the output of git-format-patch(1),
41       which is more elaborate than a plain commit message. Namely, such
42       output includes a commit message (as above), a "---" divider line, and
43       a patch part. For these inputs, the divider and patch parts are not
44       modified by this command and are emitted as is on the output, unless
45       --no-divider is specified.
46
47       Some configuration variables control the way the --trailer arguments
48       are applied to each input and the way any existing trailer in the input
49       is changed. They also make it possible to automatically add some
50       trailers.
51
52       By default, a <key>=<value> or <key>:<value> argument given using
53       --trailer will be appended after the existing trailers only if the last
54       trailer has a different (<key>, <value>) pair (or if there is no
55       existing trailer). The <key> and <value> parts will be trimmed to
56       remove starting and trailing whitespace, and the resulting trimmed
57       <key> and <value> will appear in the output like this:
58
59           key: value
60
61       This means that the trimmed <key> and <value> will be separated by ': '
62       (one colon followed by one space).
63
64       For convenience, a <keyAlias> can be configured to make using --trailer
65       shorter to type on the command line. This can be configured using the
66       trailer.<keyAlias>.key configuration variable. The <keyAlias> must be a
67       prefix of the full <key> string, although case sensitivity does not
68       matter. For example, if you have
69
70           trailer.sign.key "Signed-off-by: "
71
72       in your configuration, you only need to specify --trailer="sign: foo"
73       on the command line instead of --trailer="Signed-off-by: foo".
74
75       By default the new trailer will appear at the end of all the existing
76       trailers. If there is no existing trailer, the new trailer will appear
77       at the end of the input. A blank line will be added before the new
78       trailer if there isn’t one already.
79
80       Existing trailers are extracted from the input by looking for a group
81       of one or more lines that (i) is all trailers, or (ii) contains at
82       least one Git-generated or user-configured trailer and consists of at
83       least 25% trailers. The group must be preceded by one or more empty (or
84       whitespace-only) lines. The group must either be at the end of the
85       input or be the last non-whitespace lines before a line that starts
86       with --- (followed by a space or the end of the line).
87
88       When reading trailers, there can be no whitespace before or inside the
89       <key>, but any number of regular space and tab characters are allowed
90       between the <key> and the separator. There can be whitespaces before,
91       inside or after the <value>. The <value> may be split over multiple
92       lines with each subsequent line starting with at least one whitespace,
93       like the "folding" in RFC 822. Example:
94
95           key: This is a very long value, with spaces and
96             newlines in it.
97
98       Note that trailers do not follow (nor are they intended to follow) many
99       of the rules for RFC 822 headers. For example they do not follow the
100       encoding rule.
101

OPTIONS

103       --in-place
104           Edit the files in place.
105
106       --trim-empty
107           If the <value> part of any trailer contains only whitespace, the
108           whole trailer will be removed from the output. This applies to
109           existing trailers as well as new trailers.
110
111       --trailer <key>[(=|:)<value>]
112           Specify a (<key>, <value>) pair that should be applied as a trailer
113           to the inputs. See the description of this command.
114
115       --where <placement>, --no-where
116           Specify where all new trailers will be added. A setting provided
117           with --where overrides the trailer.where and any applicable
118           trailer.<keyAlias>.where configuration variables and applies to all
119           --trailer options until the next occurrence of --where or
120           --no-where. Upon encountering --no-where, clear the effect of any
121           previous use of --where, such that the relevant configuration
122           variables are no longer overridden. Possible placements are after,
123           before, end or start.
124
125       --if-exists <action>, --no-if-exists
126           Specify what action will be performed when there is already at
127           least one trailer with the same <key> in the input. A setting
128           provided with --if-exists overrides the trailer.ifExists and any
129           applicable trailer.<keyAlias>.ifExists configuration variables and
130           applies to all --trailer options until the next occurrence of
131           --if-exists or --no-if-exists. Upon encountering '--no-if-exists,
132           clear the effect of any previous use of '--if-exists, such that the
133           relevant configuration variables are no longer overridden. Possible
134           actions are addIfDifferent, addIfDifferentNeighbor, add, replace
135           and doNothing.
136
137       --if-missing <action>, --no-if-missing
138           Specify what action will be performed when there is no other
139           trailer with the same <key> in the input. A setting provided with
140           --if-missing overrides the trailer.ifMissing and any applicable
141           trailer.<keyAlias>.ifMissing configuration variables and applies to
142           all --trailer options until the next occurrence of --if-missing or
143           --no-if-missing. Upon encountering '--no-if-missing, clear the
144           effect of any previous use of '--if-missing, such that the relevant
145           configuration variables are no longer overridden. Possible actions
146           are doNothing or add.
147
148       --only-trailers
149           Output only the trailers, not any other parts of the input.
150
151       --only-input
152           Output only trailers that exist in the input; do not add any from
153           the command-line or by applying trailer.*  configuration variables.
154
155       --unfold
156           If a trailer has a value that runs over multiple lines (aka
157           "folded"), reformat the value into a single line.
158
159       --parse
160           A convenience alias for --only-trailers --only-input --unfold. This
161           makes it easier to only see the trailers coming from the input
162           without influencing them with any command line options or
163           configuration variables, while also making the output
164           machine-friendly with --unfold.
165
166       --no-divider
167           Do not treat --- as the end of the commit message. Use this when
168           you know your input contains just the commit message itself (and
169           not an email or the output of git format-patch).
170

CONFIGURATION VARIABLES

172       trailer.separators
173           This option tells which characters are recognized as trailer
174           separators. By default only : is recognized as a trailer separator,
175           except that = is always accepted on the command line for
176           compatibility with other git commands.
177
178           The first character given by this option will be the default
179           character used when another separator is not specified in the
180           config for this trailer.
181
182           For example, if the value for this option is "%=$", then only lines
183           using the format <key><sep><value> with <sep> containing %, = or $
184           and then spaces will be considered trailers. And % will be the
185           default separator used, so by default trailers will appear like:
186           <key>% <value> (one percent sign and one space will appear between
187           the key and the value).
188
189       trailer.where
190           This option tells where a new trailer will be added.
191
192           This can be end, which is the default, start, after or before.
193
194           If it is end, then each new trailer will appear at the end of the
195           existing trailers.
196
197           If it is start, then each new trailer will appear at the start,
198           instead of the end, of the existing trailers.
199
200           If it is after, then each new trailer will appear just after the
201           last trailer with the same <key>.
202
203           If it is before, then each new trailer will appear just before the
204           first trailer with the same <key>.
205
206       trailer.ifexists
207           This option makes it possible to choose what action will be
208           performed when there is already at least one trailer with the same
209           <key> in the input.
210
211           The valid values for this option are: addIfDifferentNeighbor (this
212           is the default), addIfDifferent, add, replace or doNothing.
213
214           With addIfDifferentNeighbor, a new trailer will be added only if no
215           trailer with the same (<key>, <value>) pair is above or below the
216           line where the new trailer will be added.
217
218           With addIfDifferent, a new trailer will be added only if no trailer
219           with the same (<key>, <value>) pair is already in the input.
220
221           With add, a new trailer will be added, even if some trailers with
222           the same (<key>, <value>) pair are already in the input.
223
224           With replace, an existing trailer with the same <key> will be
225           deleted and the new trailer will be added. The deleted trailer will
226           be the closest one (with the same <key>) to the place where the new
227           one will be added.
228
229           With doNothing, nothing will be done; that is no new trailer will
230           be added if there is already one with the same <key> in the input.
231
232       trailer.ifmissing
233           This option makes it possible to choose what action will be
234           performed when there is not yet any trailer with the same <key> in
235           the input.
236
237           The valid values for this option are: add (this is the default) and
238           doNothing.
239
240           With add, a new trailer will be added.
241
242           With doNothing, nothing will be done.
243
244       trailer.<keyAlias>.key
245           Defines a <keyAlias> for the <key>. The <keyAlias> must be a prefix
246           (case does not matter) of the <key>. For example, in git config
247           trailer.ack.key "Acked-by" the "Acked-by" is the <key> and the
248           "ack" is the <keyAlias>. This configuration allows the shorter
249           --trailer "ack:..."  invocation on the command line using the "ack"
250           <keyAlias> instead of the longer --trailer "Acked-by:...".
251
252           At the end of the <key>, a separator can appear and then some space
253           characters. By default the only valid separator is :, but this can
254           be changed using the trailer.separators config variable.
255
256           If there is a separator in the key, then it overrides the default
257           separator when adding the trailer.
258
259       trailer.<keyAlias>.where
260           This option takes the same values as the trailer.where
261           configuration variable and it overrides what is specified by that
262           option for trailers with the specified <keyAlias>.
263
264       trailer.<keyAlias>.ifexists
265           This option takes the same values as the trailer.ifexists
266           configuration variable and it overrides what is specified by that
267           option for trailers with the specified <keyAlias>.
268
269       trailer.<keyAlias>.ifmissing
270           This option takes the same values as the trailer.ifmissing
271           configuration variable and it overrides what is specified by that
272           option for trailers with the specified <keyAlias>.
273
274       trailer.<keyAlias>.command
275           Deprecated in favor of trailer.<keyAlias>.cmd. This option behaves
276           in the same way as trailer.<keyAlias>.cmd, except that it doesn’t
277           pass anything as argument to the specified command. Instead the
278           first occurrence of substring $ARG is replaced by the <value> that
279           would be passed as argument.
280
281           Note that $ARG in the user’s command is only replaced once and that
282           the original way of replacing $ARG is not safe.
283
284           When both trailer.<keyAlias>.cmd and trailer.<keyAlias>.command are
285           given for the same <keyAlias>, trailer.<keyAlias>.cmd is used and
286           trailer.<keyAlias>.command is ignored.
287
288       trailer.<keyAlias>.cmd
289           This option can be used to specify a shell command that will be
290           called once to automatically add a trailer with the specified
291           <keyAlias>, and then called each time a --trailer
292           <keyAlias>=<value> argument is specified to modify the <value> of
293           the trailer that this option would produce.
294
295           When the specified command is first called to add a trailer with
296           the specified <keyAlias>, the behavior is as if a special --trailer
297           <keyAlias>=<value> argument was added at the beginning of the "git
298           interpret-trailers" command, where <value> is taken to be the
299           standard output of the command with any leading and trailing
300           whitespace trimmed off.
301
302           If some --trailer <keyAlias>=<value> arguments are also passed on
303           the command line, the command is called again once for each of
304           these arguments with the same <keyAlias>. And the <value> part of
305           these arguments, if any, will be passed to the command as its first
306           argument. This way the command can produce a <value> computed from
307           the <value> passed in the --trailer <keyAlias>=<value> argument.
308

EXAMPLES

310       •   Configure a sign trailer with a Signed-off-by key, and then add two
311           of these trailers to a commit message file:
312
313               $ git config trailer.sign.key "Signed-off-by"
314               $ cat msg.txt
315               subject
316
317               body text
318               $ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
319               subject
320
321               body text
322
323               Signed-off-by: Alice <alice@example.com>
324               Signed-off-by: Bob <bob@example.com>
325
326       •   Use the --in-place option to edit a commit message file in place:
327
328               $ cat msg.txt
329               subject
330
331               body text
332
333               Signed-off-by: Bob <bob@example.com>
334               $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
335               $ cat msg.txt
336               subject
337
338               body text
339
340               Signed-off-by: Bob <bob@example.com>
341               Acked-by: Alice <alice@example.com>
342
343       •   Extract the last commit as a patch, and add a Cc and a Reviewed-by
344           trailer to it:
345
346               $ git format-patch -1
347               0001-foo.patch
348               $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
349
350       •   Configure a sign trailer with a command to automatically add a
351           'Signed-off-by: ' with the author information only if there is no
352           'Signed-off-by: ' already, and show how it works:
353
354               $ cat msg1.txt
355               subject
356
357               body text
358               $ git config trailer.sign.key "Signed-off-by: "
359               $ git config trailer.sign.ifmissing add
360               $ git config trailer.sign.ifexists doNothing
361               $ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"'
362               $ git interpret-trailers --trailer sign <msg1.txt
363               subject
364
365               body text
366
367               Signed-off-by: Bob <bob@example.com>
368               $ cat msg2.txt
369               subject
370
371               body text
372
373               Signed-off-by: Alice <alice@example.com>
374               $ git interpret-trailers --trailer sign <msg2.txt
375               subject
376
377               body text
378
379               Signed-off-by: Alice <alice@example.com>
380
381       •   Configure a fix trailer with a key that contains a # and no space
382           after this character, and show how it works:
383
384               $ git config trailer.separators ":#"
385               $ git config trailer.fix.key "Fix #"
386               $ echo "subject" | git interpret-trailers --trailer fix=42
387               subject
388
389               Fix #42
390
391       •   Configure a help trailer with a cmd use a script glog-find-author
392           which search specified author identity from git log in git
393           repository and show how it works:
394
395               $ cat ~/bin/glog-find-author
396               #!/bin/sh
397               test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
398               $ cat msg.txt
399               subject
400
401               body text
402               $ git config trailer.help.key "Helped-by: "
403               $ git config trailer.help.ifExists "addIfDifferentNeighbor"
404               $ git config trailer.help.cmd "~/bin/glog-find-author"
405               $ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
406               subject
407
408               body text
409
410               Helped-by: Junio C Hamano <gitster@pobox.com>
411               Helped-by: Christian Couder <christian.couder@gmail.com>
412
413       •   Configure a ref trailer with a cmd use a script glog-grep to grep
414           last relevant commit from git log in the git repository and show
415           how it works:
416
417               $ cat ~/bin/glog-grep
418               #!/bin/sh
419               test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
420               $ cat msg.txt
421               subject
422
423               body text
424               $ git config trailer.ref.key "Reference-to: "
425               $ git config trailer.ref.ifExists "replace"
426               $ git config trailer.ref.cmd "~/bin/glog-grep"
427               $ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
428               subject
429
430               body text
431
432               Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
433
434       •   Configure a see trailer with a command to show the subject of a
435           commit that is related, and show how it works:
436
437               $ cat msg.txt
438               subject
439
440               body text
441
442               see: HEAD~2
443               $ cat ~/bin/glog-ref
444               #!/bin/sh
445               git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
446               $ git config trailer.see.key "See-also: "
447               $ git config trailer.see.ifExists "replace"
448               $ git config trailer.see.ifMissing "doNothing"
449               $ git config trailer.see.cmd "glog-ref"
450               $ git interpret-trailers --trailer=see <msg.txt
451               subject
452
453               body text
454
455               See-also: fe3187489d69c4 (subject of related commit)
456
457       •   Configure a commit template with some trailers with empty values
458           (using sed to show and keep the trailing spaces at the end of the
459           trailers), then configure a commit-msg hook that uses git
460           interpret-trailers to remove trailers with empty values and to add
461           a git-version trailer:
462
463               $ cat temp.txt
464               ***subject***
465
466               ***message***
467
468               Fixes: Z
469               Cc: Z
470               Reviewed-by: Z
471               Signed-off-by: Z
472               $ sed -e 's/ Z$/ /' temp.txt > commit_template.txt
473               $ git config commit.template commit_template.txt
474               $ cat .git/hooks/commit-msg
475               #!/bin/sh
476               git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
477               mv "\$1.new" "\$1"
478               $ chmod +x .git/hooks/commit-msg
479

SEE ALSO

481       git-commit(1), git-format-patch(1), git-config(1)
482

GIT

484       Part of the git(1) suite
485
486
487
488Git 2.43.0                        11/20/2023         GIT-INTERPRET-TRAILERS(1)
Impressum