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
13

DESCRIPTION

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

OPTIONS

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

CONFIGURATION VARIABLES

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

EXAMPLES

243       ·   Configure a sign trailer with a Signed-off-by key, and then add two
244           of these trailers to a message:
245
246               $ git config trailer.sign.key "Signed-off-by"
247               $ cat msg.txt
248               subject
249
250               message
251               $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
252               subject
253
254               message
255
256               Signed-off-by: Alice <alice@example.com>
257               Signed-off-by: Bob <bob@example.com>
258
259
260       ·   Use the --in-place option to edit a message file in place:
261
262               $ cat msg.txt
263               subject
264
265               message
266
267               Signed-off-by: Bob <bob@example.com>
268               $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
269               $ cat msg.txt
270               subject
271
272               message
273
274               Signed-off-by: Bob <bob@example.com>
275               Acked-by: Alice <alice@example.com>
276
277
278       ·   Extract the last commit as a patch, and add a Cc and a Reviewed-by
279           trailer to it:
280
281               $ git format-patch -1
282               0001-foo.patch
283               $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
284
285
286       ·   Configure a sign trailer with a command to automatically add a
287           'Signed-off-by: ' with the author information only if there is no
288           'Signed-off-by: ' already, and show how it works:
289
290               $ git config trailer.sign.key "Signed-off-by: "
291               $ git config trailer.sign.ifmissing add
292               $ git config trailer.sign.ifexists doNothing
293               $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
294               $ git interpret-trailers <<EOF
295               > EOF
296
297               Signed-off-by: Bob <bob@example.com>
298               $ git interpret-trailers <<EOF
299               > Signed-off-by: Alice <alice@example.com>
300               > EOF
301
302               Signed-off-by: Alice <alice@example.com>
303
304
305       ·   Configure a fix trailer with a key that contains a # and no space
306           after this character, and show how it works:
307
308               $ git config trailer.separators ":#"
309               $ git config trailer.fix.key "Fix #"
310               $ echo "subject" | git interpret-trailers --trailer fix=42
311               subject
312
313               Fix #42
314
315
316       ·   Configure a see trailer with a command to show the subject of a
317           commit that is related, and show how it works:
318
319               $ git config trailer.see.key "See-also: "
320               $ git config trailer.see.ifExists "replace"
321               $ git config trailer.see.ifMissing "doNothing"
322               $ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
323               $ git interpret-trailers <<EOF
324               > subject
325               >
326               > message
327               >
328               > see: HEAD~2
329               > EOF
330               subject
331
332               message
333
334               See-also: fe3187489d69c4 (subject of related commit)
335
336
337       ·   Configure a commit template with some trailers with empty values
338           (using sed to show and keep the trailing spaces at the end of the
339           trailers), then configure a commit-msg hook that uses git
340           interpret-trailers to remove trailers with empty values and to add
341           a git-version trailer:
342
343               $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
344               > ***subject***
345               >
346               > ***message***
347               >
348               > Fixes: Z
349               > Cc: Z
350               > Reviewed-by: Z
351               > Signed-off-by: Z
352               > EOF
353               $ git config commit.template commit_template.txt
354               $ cat >.git/hooks/commit-msg <<EOF
355               > #!/bin/sh
356               > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
357               > mv "\$1.new" "\$1"
358               > EOF
359               $ chmod +x .git/hooks/commit-msg
360
361

SEE ALSO

363       git-commit(1), git-format-patch(1), git-config(1)
364

GIT

366       Part of the git(1) suite
367
368
369
370Git 2.24.1                        12/10/2019             GIT-INTERPRET-TRAI(1)
Impressum