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 [--in-place] [--trim-empty]
11                               [(--trailer <token>[(=|:)<value>])...]
12                               [--parse] [<file>...]
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       This means that the trimmed <token> and <value> will be separated by ':
42       ' (one colon followed by one space).
43
44       By default the new trailer will appear at the end of all the existing
45       trailers. If there is no existing trailer, the new trailer will appear
46       after the commit message part of the output, and, if there is no line
47       with only spaces at the end of the commit message part, one blank line
48       will be added before the new trailer.
49
50       Existing trailers are extracted from the input message by looking for a
51       group of one or more lines that (i) is all trailers, or (ii) contains
52       at least one Git-generated or user-configured trailer and consists of
53       at least 25% trailers. The group must be preceded by one or more empty
54       (or whitespace-only) lines. The group must either be at the end of the
55       message or be the last non-whitespace lines before a line that starts
56       with --- (followed by a space or the end of the line). Such three minus
57       signs start the patch part of the message. See also --no-divider below.
58
59       When reading trailers, there can be no whitespace before or inside the
60       token, but any number of regular space and tab characters are allowed
61       between the token and the separator. There can be whitespaces before,
62       inside or after the value. The value may be split over multiple lines
63       with each subsequent line starting with at least one whitespace, like
64       the "folding" in RFC 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 behaves in the same way as trailer.<token>.cmd, except
223           that it doesn’t pass anything as argument to the specified command.
224           Instead the first occurrence of substring $ARG is replaced by the
225           value that would be passed as argument.
226
227           The trailer.<token>.command option has been deprecated in favor of
228           trailer.<token>.cmd due to the fact that $ARG in the user’s command
229           is only replaced once and that the original way of replacing $ARG
230           is not safe.
231
232           When both trailer.<token>.cmd and trailer.<token>.command are given
233           for the same <token>, trailer.<token>.cmd is used and
234           trailer.<token>.command is ignored.
235
236       trailer.<token>.cmd
237           This option can be used to specify a shell command that will be
238           called: once to automatically add a trailer with the specified
239           <token>, and then each time a --trailer <token>=<value> argument to
240           modify the <value> of the trailer that this option would produce.
241
242           When the specified command is first called to add a trailer with
243           the specified <token>, the behavior is as if a special --trailer
244           <token>=<value> argument was added at the beginning of the "git
245           interpret-trailers" command, where <value> is taken to be the
246           standard output of the command with any leading and trailing
247           whitespace trimmed off.
248
249           If some --trailer <token>=<value> arguments are also passed on the
250           command line, the command is called again once for each of these
251           arguments with the same <token>. And the <value> part of these
252           arguments, if any, will be passed to the command as its first
253           argument. This way the command can produce a <value> computed from
254           the <value> passed in the --trailer <token>=<value> argument.
255

EXAMPLES

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

SEE ALSO

415       git-commit(1), git-format-patch(1), git-config(1)
416

GIT

418       Part of the git(1) suite
419
420
421
422Git 2.39.1                        2023-01-13             GIT-INTERPRET-TRAI(1)
Impressum