1GIT-INTERPRET-TRAI(1) Git Manual GIT-INTERPRET-TRAI(1)
2
3
4
6 git-interpret-trailers - add or parse structured information in commit
7 messages
8
10 git interpret-trailers [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...]
11 git interpret-trailers [<options>] [--parse] [<file>...]
12
13
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 ---. Such three minus signs start the patch part of the message.
58
59 When reading trailers, there can be whitespaces after the token, the
60 separator and the value. There can also be whitespaces inside the token
61 and the value. The value may be split over multiple lines with each
62 subsequent line starting with whitespace, like the "folding" in RFC
63 822.
64
65 Note that trailers do not follow and are not intended to follow many
66 rules for RFC 822 headers. For example they do not follow the encoding
67 rules and probably many other rules.
68
70 --in-place
71 Edit the files in place.
72
73 --trim-empty
74 If the <value> part of any trailer contains only whitespace, the
75 whole trailer will be removed from the resulting message. This
76 applies to existing trailers as well as new trailers.
77
78 --trailer <token>[(=|:)<value>]
79 Specify a (<token>, <value>) pair that should be applied as a
80 trailer to the input messages. See the description of this command.
81
82 --where <placement>, --no-where
83 Specify where all new trailers will be added. A setting provided
84 with --where overrides all configuration variables and applies to
85 all --trailer options until the next occurrence of --where or
86 --no-where.
87
88 --if-exists <action>, --no-if-exists
89 Specify what action will be performed when there is already at
90 least one trailer with the same <token> in the message. A setting
91 provided with --if-exists overrides all configuration variables and
92 applies to all --trailer options until the next occurrence of
93 --if-exists or --no-if-exists.
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.
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
117 trailer.separators
118 This option tells which characters are recognized as trailer
119 separators. By default only : is recognized as a trailer separator,
120 except that = is always accepted on the command line for
121 compatibility with other git commands.
122
123 The first character given by this option will be the default
124 character used when another separator is not specified in the
125 config for this trailer.
126
127 For example, if the value for this option is "%=$", then only lines
128 using the format <token><sep><value> with <sep> containing %, = or
129 $ and then spaces will be considered trailers. And % will be the
130 default separator used, so by default trailers will appear like:
131 <token>% <value> (one percent sign and one space will appear
132 between the token and the value).
133
134 trailer.where
135 This option tells where a new trailer will be added.
136
137 This can be end, which is the default, start, after or before.
138
139 If it is end, then each new trailer will appear at the end of the
140 existing trailers.
141
142 If it is start, then each new trailer will appear at the start,
143 instead of the end, of the existing trailers.
144
145 If it is after, then each new trailer will appear just after the
146 last trailer with the same <token>.
147
148 If it is before, then each new trailer will appear just before the
149 first trailer with the same <token>.
150
151 trailer.ifexists
152 This option makes it possible to choose what action will be
153 performed when there is already at least one trailer with the same
154 <token> in the message.
155
156 The valid values for this option are: addIfDifferentNeighbor (this
157 is the default), addIfDifferent, add, replace or doNothing.
158
159 With addIfDifferentNeighbor, a new trailer will be added only if no
160 trailer with the same (<token>, <value>) pair is above or below the
161 line where the new trailer will be added.
162
163 With addIfDifferent, a new trailer will be added only if no trailer
164 with the same (<token>, <value>) pair is already in the message.
165
166 With add, a new trailer will be added, even if some trailers with
167 the same (<token>, <value>) pair are already in the message.
168
169 With replace, an existing trailer with the same <token> will be
170 deleted and the new trailer will be added. The deleted trailer will
171 be the closest one (with the same <token>) to the place where the
172 new one will be added.
173
174 With doNothing, nothing will be done; that is no new trailer will
175 be added if there is already one with the same <token> in the
176 message.
177
178 trailer.ifmissing
179 This option makes it possible to choose what action will be
180 performed when there is not yet any trailer with the same <token>
181 in the message.
182
183 The valid values for this option are: add (this is the default) and
184 doNothing.
185
186 With add, a new trailer will be added.
187
188 With doNothing, nothing will be done.
189
190 trailer.<token>.key
191 This key will be used instead of <token> in the trailer. At the end
192 of this key, a separator can appear and then some space characters.
193 By default the only valid separator is :, but this can be changed
194 using the trailer.separators config variable.
195
196 If there is a separator, then the key will be used instead of both
197 the <token> and the default separator when adding the trailer.
198
199 trailer.<token>.where
200 This option takes the same values as the trailer.where
201 configuration variable and it overrides what is specified by that
202 option for trailers with the specified <token>.
203
204 trailer.<token>.ifexists
205 This option takes the same values as the trailer.ifexists
206 configuration variable and it overrides what is specified by that
207 option for trailers with the specified <token>.
208
209 trailer.<token>.ifmissing
210 This option takes the same values as the trailer.ifmissing
211 configuration variable and it overrides what is specified by that
212 option for trailers with the specified <token>.
213
214 trailer.<token>.command
215 This option can be used to specify a shell command that will be
216 called to automatically add or modify a trailer with the specified
217 <token>.
218
219 When this option is specified, the behavior is as if a special
220 <token>=<value> argument were added at the beginning of the command
221 line, where <value> is taken to be the standard output of the
222 specified command with any leading and trailing whitespace trimmed
223 off.
224
225 If the command contains the $ARG string, this string will be
226 replaced with the <value> part of an existing trailer with the same
227 <token>, if any, before the command is launched.
228
229 If some <token>=<value> arguments are also passed on the command
230 line, when a trailer.<token>.command is configured, the command
231 will also be executed for each of these arguments. And the <value>
232 part of these arguments, if any, will be used to replace the $ARG
233 string in the command.
234
236 · Configure a sign trailer with a Signed-off-by key, and then add two
237 of these trailers to a message:
238
239 $ git config trailer.sign.key "Signed-off-by"
240 $ cat msg.txt
241 subject
242
243 message
244 $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
245 subject
246
247 message
248
249 Signed-off-by: Alice <alice@example.com>
250 Signed-off-by: Bob <bob@example.com>
251
252
253 · Use the --in-place option to edit a message file in place:
254
255 $ cat msg.txt
256 subject
257
258 message
259
260 Signed-off-by: Bob <bob@example.com>
261 $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
262 $ cat msg.txt
263 subject
264
265 message
266
267 Signed-off-by: Bob <bob@example.com>
268 Acked-by: Alice <alice@example.com>
269
270
271 · Extract the last commit as a patch, and add a Cc and a Reviewed-by
272 trailer to it:
273
274 $ git format-patch -1
275 0001-foo.patch
276 $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
277
278
279 · Configure a sign trailer with a command to automatically add a
280 'Signed-off-by: ' with the author information only if there is no
281 'Signed-off-by: ' already, and show how it works:
282
283 $ git config trailer.sign.key "Signed-off-by: "
284 $ git config trailer.sign.ifmissing add
285 $ git config trailer.sign.ifexists doNothing
286 $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
287 $ git interpret-trailers <<EOF
288 > EOF
289
290 Signed-off-by: Bob <bob@example.com>
291 $ git interpret-trailers <<EOF
292 > Signed-off-by: Alice <alice@example.com>
293 > EOF
294
295 Signed-off-by: Alice <alice@example.com>
296
297
298 · Configure a fix trailer with a key that contains a # and no space
299 after this character, and show how it works:
300
301 $ git config trailer.separators ":#"
302 $ git config trailer.fix.key "Fix #"
303 $ echo "subject" | git interpret-trailers --trailer fix=42
304 subject
305
306 Fix #42
307
308
309 · Configure a see trailer with a command to show the subject of a
310 commit that is related, and show how it works:
311
312 $ git config trailer.see.key "See-also: "
313 $ git config trailer.see.ifExists "replace"
314 $ git config trailer.see.ifMissing "doNothing"
315 $ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
316 $ git interpret-trailers <<EOF
317 > subject
318 >
319 > message
320 >
321 > see: HEAD~2
322 > EOF
323 subject
324
325 message
326
327 See-also: fe3187489d69c4 (subject of related commit)
328
329
330 · Configure a commit template with some trailers with empty values
331 (using sed to show and keep the trailing spaces at the end of the
332 trailers), then configure a commit-msg hook that uses git
333 interpret-trailers to remove trailers with empty values and to add
334 a git-version trailer:
335
336 $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
337 > ***subject***
338 >
339 > ***message***
340 >
341 > Fixes: Z
342 > Cc: Z
343 > Reviewed-by: Z
344 > Signed-off-by: Z
345 > EOF
346 $ git config commit.template commit_template.txt
347 $ cat >.git/hooks/commit-msg <<EOF
348 > #!/bin/sh
349 > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
350 > mv "\$1.new" "\$1"
351 > EOF
352 $ chmod +x .git/hooks/commit-msg
353
354
356 git-commit(1), git-format-patch(1), git-config(1)
357
359 Part of the git(1) suite
360
361
362
363Git 2.18.1 05/14/2019 GIT-INTERPRET-TRAI(1)