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

NAME

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

SYNOPSIS

10       git interpret-trailers [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...]
11       git interpret-trailers [<options>] [--parse] [<file>...]
12

DESCRIPTION

14       Help parsing or adding trailers lines, that look similar to RFC 822
15       e-mail headers, at the end of the otherwise free-form part of a commit
16       message.
17
18       This command reads some patches or commit messages from either the
19       <file> arguments or the standard input if no <file> is specified. If
20       --parse is specified, the output consists of the parsed trailers.
21
22       Otherwise, this command applies the arguments passed using the
23       --trailer option, if any, to the commit message part of each input
24       file. The result is emitted on the standard output.
25
26       Some configuration variables control the way the --trailer arguments
27       are applied to each commit message and the way any existing trailer in
28       the commit message is changed. They also make it possible to
29       automatically add some trailers.
30
31       By default, a <token>=<value> or <token>:<value> argument given using
32       --trailer will be appended after the existing trailers only if the last
33       trailer has a different (<token>, <value>) pair (or if there is no
34       existing trailer). The <token> and <value> parts will be trimmed to
35       remove starting and trailing whitespace, and the resulting trimmed
36       <token> and <value> will appear in the message like this:
37
38           token: value
39
40       This means that the trimmed <token> and <value> will be separated by ':
41       ' (one colon followed by one space).
42
43       By default the new trailer will appear at the end of all the existing
44       trailers. If there is no existing trailer, the new trailer will appear
45       after the commit message part of the output, and, if there is no line
46       with only spaces at the end of the commit message part, one blank line
47       will be added before the new trailer.
48
49       Existing trailers are extracted from the input message by looking for a
50       group of one or more lines that (i) is all trailers, or (ii) contains
51       at least one Git-generated or user-configured trailer and consists of
52       at least 25% trailers. The group must be preceded by one or more empty
53       (or whitespace-only) lines. The group must either be at the end of the
54       message or be the last non-whitespace lines before a line that starts
55       with --- (followed by a space or the end of the line). Such three minus
56       signs start the patch part of the message. See also --no-divider below.
57
58       When reading trailers, there can be whitespaces after the token, the
59       separator and the value. There can also be whitespaces inside the token
60       and the value. The value may be split over multiple lines with each
61       subsequent line starting with whitespace, like the "folding" in RFC
62       822.
63
64       Note that trailers do not follow and are not intended to follow many
65       rules for RFC 822 headers. For example they do not follow the encoding
66       rules and probably many other rules.
67

OPTIONS

69       --in-place
70           Edit the files in place.
71
72       --trim-empty
73           If the <value> part of any trailer contains only whitespace, the
74           whole trailer will be removed from the resulting message. This
75           applies to existing trailers as well as new trailers.
76
77       --trailer <token>[(=|:)<value>]
78           Specify a (<token>, <value>) pair that should be applied as a
79           trailer to the input messages. See the description of this command.
80
81       --where <placement>, --no-where
82           Specify where all new trailers will be added. A setting provided
83           with --where overrides all configuration variables and applies to
84           all --trailer options until the next occurrence of --where or
85           --no-where. Possible values are after, before, end or start.
86
87       --if-exists <action>, --no-if-exists
88           Specify what action will be performed when there is already at
89           least one trailer with the same <token> in the message. A setting
90           provided with --if-exists overrides all configuration variables and
91           applies to all --trailer options until the next occurrence of
92           --if-exists or --no-if-exists. Possible actions are addIfDifferent,
93           addIfDifferentNeighbor, add, replace and doNothing.
94
95       --if-missing <action>, --no-if-missing
96           Specify what action will be performed when there is no other
97           trailer with the same <token> in the message. A setting provided
98           with --if-missing overrides all configuration variables and applies
99           to all --trailer options until the next occurrence of --if-missing
100           or --no-if-missing. Possible actions are doNothing or add.
101
102       --only-trailers
103           Output only the trailers, not any other parts of the input.
104
105       --only-input
106           Output only trailers that exist in the input; do not add any from
107           the command-line or by following configured trailer.*  rules.
108
109       --unfold
110           Remove any whitespace-continuation in trailers, so that each
111           trailer appears on a line by itself with its full content.
112
113       --parse
114           A convenience alias for --only-trailers --only-input --unfold.
115
116       --no-divider
117           Do not treat --- as the end of the commit message. Use this when
118           you know your input contains just the commit message itself (and
119           not an email or the output of git format-patch).
120

CONFIGURATION VARIABLES

122       trailer.separators
123           This option tells which characters are recognized as trailer
124           separators. By default only : is recognized as a trailer separator,
125           except that = is always accepted on the command line for
126           compatibility with other git commands.
127
128           The first character given by this option will be the default
129           character used when another separator is not specified in the
130           config for this trailer.
131
132           For example, if the value for this option is "%=$", then only lines
133           using the format <token><sep><value> with <sep> containing %, = or
134           $ and then spaces will be considered trailers. And % will be the
135           default separator used, so by default trailers will appear like:
136           <token>% <value> (one percent sign and one space will appear
137           between the token and the value).
138
139       trailer.where
140           This option tells where a new trailer will be added.
141
142           This can be end, which is the default, start, after or before.
143
144           If it is end, then each new trailer will appear at the end of the
145           existing trailers.
146
147           If it is start, then each new trailer will appear at the start,
148           instead of the end, of the existing trailers.
149
150           If it is after, then each new trailer will appear just after the
151           last trailer with the same <token>.
152
153           If it is before, then each new trailer will appear just before the
154           first trailer with the same <token>.
155
156       trailer.ifexists
157           This option makes it possible to choose what action will be
158           performed when there is already at least one trailer with the same
159           <token> in the message.
160
161           The valid values for this option are: addIfDifferentNeighbor (this
162           is the default), addIfDifferent, add, replace or doNothing.
163
164           With addIfDifferentNeighbor, a new trailer will be added only if no
165           trailer with the same (<token>, <value>) pair is above or below the
166           line where the new trailer will be added.
167
168           With addIfDifferent, a new trailer will be added only if no trailer
169           with the same (<token>, <value>) pair is already in the message.
170
171           With add, a new trailer will be added, even if some trailers with
172           the same (<token>, <value>) pair are already in the message.
173
174           With replace, an existing trailer with the same <token> will be
175           deleted and the new trailer will be added. The deleted trailer will
176           be the closest one (with the same <token>) to the place where the
177           new one will be added.
178
179           With doNothing, nothing will be done; that is no new trailer will
180           be added if there is already one with the same <token> in the
181           message.
182
183       trailer.ifmissing
184           This option makes it possible to choose what action will be
185           performed when there is not yet any trailer with the same <token>
186           in the message.
187
188           The valid values for this option are: add (this is the default) and
189           doNothing.
190
191           With add, a new trailer will be added.
192
193           With doNothing, nothing will be done.
194
195       trailer.<token>.key
196           This key will be used instead of <token> in the trailer. At the end
197           of this key, a separator can appear and then some space characters.
198           By default the only valid separator is :, but this can be changed
199           using the trailer.separators config variable.
200
201           If there is a separator, then the key will be used instead of both
202           the <token> and the default separator when adding the trailer.
203
204       trailer.<token>.where
205           This option takes the same values as the trailer.where
206           configuration variable and it overrides what is specified by that
207           option for trailers with the specified <token>.
208
209       trailer.<token>.ifexists
210           This option takes the same values as the trailer.ifexists
211           configuration variable and it overrides what is specified by that
212           option for trailers with the specified <token>.
213
214       trailer.<token>.ifmissing
215           This option takes the same values as the trailer.ifmissing
216           configuration variable and it overrides what is specified by that
217           option for trailers with the specified <token>.
218
219       trailer.<token>.command
220           This option behaves in the same way as trailer.<token>.cmd, except
221           that it doesn’t pass anything as argument to the specified command.
222           Instead the first occurrence of substring $ARG is replaced by the
223           value that would be passed as argument.
224
225           The trailer.<token>.command option has been deprecated in favor of
226           trailer.<token>.cmd due to the fact that $ARG in the user’s command
227           is only replaced once and that the original way of replacing $ARG
228           is not safe.
229
230           When both trailer.<token>.cmd and trailer.<token>.command are given
231           for the same <token>, trailer.<token>.cmd is used and
232           trailer.<token>.command is ignored.
233
234       trailer.<token>.cmd
235           This option can be used to specify a shell command that will be
236           called: once to automatically add a trailer with the specified
237           <token>, and then each time a --trailer <token>=<value> argument to
238           modify the <value> of the trailer that this option would produce.
239
240           When the specified command is first called to add a trailer with
241           the specified <token>, the behavior is as if a special --trailer
242           <token>=<value> argument was added at the beginning of the "git
243           interpret-trailers" command, where <value> is taken to be the
244           standard output of the command with any leading and trailing
245           whitespace trimmed off.
246
247           If some --trailer <token>=<value> arguments are also passed on the
248           command line, the command is called again once for each of these
249           arguments with the same <token>. And the <value> part of these
250           arguments, if any, will be passed to the command as its first
251           argument. This way the command can produce a <value> computed from
252           the <value> passed in the --trailer <token>=<value> argument.
253

EXAMPLES

255       •   Configure a sign trailer with a Signed-off-by key, and then add two
256           of these trailers to a message:
257
258               $ git config trailer.sign.key "Signed-off-by"
259               $ cat msg.txt
260               subject
261
262               message
263               $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
264               subject
265
266               message
267
268               Signed-off-by: Alice <alice@example.com>
269               Signed-off-by: Bob <bob@example.com>
270
271       •   Use the --in-place option to edit a message file in place:
272
273               $ cat msg.txt
274               subject
275
276               message
277
278               Signed-off-by: Bob <bob@example.com>
279               $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
280               $ cat msg.txt
281               subject
282
283               message
284
285               Signed-off-by: Bob <bob@example.com>
286               Acked-by: Alice <alice@example.com>
287
288       •   Extract the last commit as a patch, and add a Cc and a Reviewed-by
289           trailer to it:
290
291               $ git format-patch -1
292               0001-foo.patch
293               $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
294
295       •   Configure a sign trailer with a command to automatically add a
296           'Signed-off-by: ' with the author information only if there is no
297           'Signed-off-by: ' already, and show how it works:
298
299               $ git config trailer.sign.key "Signed-off-by: "
300               $ git config trailer.sign.ifmissing add
301               $ git config trailer.sign.ifexists doNothing
302               $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
303               $ git interpret-trailers <<EOF
304               > EOF
305
306               Signed-off-by: Bob <bob@example.com>
307               $ git interpret-trailers <<EOF
308               > Signed-off-by: Alice <alice@example.com>
309               > EOF
310
311               Signed-off-by: Alice <alice@example.com>
312
313       •   Configure a fix trailer with a key that contains a # and no space
314           after this character, and show how it works:
315
316               $ git config trailer.separators ":#"
317               $ git config trailer.fix.key "Fix #"
318               $ echo "subject" | git interpret-trailers --trailer fix=42
319               subject
320
321               Fix #42
322
323       •   Configure a help trailer with a cmd use a script glog-find-author
324           which search specified author identity from git log in git
325           repository and show how it works:
326
327               $ cat ~/bin/glog-find-author
328               #!/bin/sh
329               test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
330               $ git config trailer.help.key "Helped-by: "
331               $ git config trailer.help.ifExists "addIfDifferentNeighbor"
332               $ git config trailer.help.cmd "~/bin/glog-find-author"
333               $ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <<EOF
334               > subject
335               >
336               > message
337               >
338               > EOF
339               subject
340
341               message
342
343               Helped-by: Junio C Hamano <gitster@pobox.com>
344               Helped-by: Christian Couder <christian.couder@gmail.com>
345
346       •   Configure a ref trailer with a cmd use a script glog-grep to grep
347           last relevant commit from git log in the git repository and show
348           how it works:
349
350               $ cat ~/bin/glog-grep
351               #!/bin/sh
352               test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
353               $ git config trailer.ref.key "Reference-to: "
354               $ git config trailer.ref.ifExists "replace"
355               $ git config trailer.ref.cmd "~/bin/glog-grep"
356               $ git interpret-trailers --trailer="ref:Add copyright notices." <<EOF
357               > subject
358               >
359               > message
360               >
361               > EOF
362               subject
363
364               message
365
366               Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
367
368       •   Configure a see trailer with a command to show the subject of a
369           commit that is related, and show how it works:
370
371               $ git config trailer.see.key "See-also: "
372               $ git config trailer.see.ifExists "replace"
373               $ git config trailer.see.ifMissing "doNothing"
374               $ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
375               $ git interpret-trailers <<EOF
376               > subject
377               >
378               > message
379               >
380               > see: HEAD~2
381               > EOF
382               subject
383
384               message
385
386               See-also: fe3187489d69c4 (subject of related commit)
387
388       •   Configure a commit template with some trailers with empty values
389           (using sed to show and keep the trailing spaces at the end of the
390           trailers), then configure a commit-msg hook that uses git
391           interpret-trailers to remove trailers with empty values and to add
392           a git-version trailer:
393
394               $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
395               > ***subject***
396               >
397               > ***message***
398               >
399               > Fixes: Z
400               > Cc: Z
401               > Reviewed-by: Z
402               > Signed-off-by: Z
403               > EOF
404               $ git config commit.template commit_template.txt
405               $ cat >.git/hooks/commit-msg <<EOF
406               > #!/bin/sh
407               > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
408               > mv "\$1.new" "\$1"
409               > EOF
410               $ chmod +x .git/hooks/commit-msg
411

SEE ALSO

413       git-commit(1), git-format-patch(1), git-config(1)
414

GIT

416       Part of the git(1) suite
417
418
419
420Git 2.36.1                        2022-05-05             GIT-INTERPRET-TRAI(1)
Impressum