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
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
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
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 can be used to specify a shell command that will be
221 called to automatically add or modify a trailer with the specified
222 <token>.
223
224 When this option is specified, the behavior is as if a special
225 <token>=<value> argument were added at the beginning of the command
226 line, where <value> is taken to be the standard output of the
227 specified command with any leading and trailing whitespace trimmed
228 off.
229
230 If the command contains the $ARG string, this string will be
231 replaced with the <value> part of an existing trailer with the same
232 <token>, if any, before the command is launched.
233
234 If some <token>=<value> arguments are also passed on the command
235 line, when a trailer.<token>.command is configured, the command
236 will also be executed for each of these arguments. And the <value>
237 part of these arguments, if any, will be used to replace the $ARG
238 string in the command.
239
241 · Configure a sign trailer with a Signed-off-by key, and then add two
242 of these trailers to a message:
243
244 $ git config trailer.sign.key "Signed-off-by"
245 $ cat msg.txt
246 subject
247
248 message
249 $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
250 subject
251
252 message
253
254 Signed-off-by: Alice <alice@example.com>
255 Signed-off-by: Bob <bob@example.com>
256
257 · Use the --in-place option to edit a message file in place:
258
259 $ cat msg.txt
260 subject
261
262 message
263
264 Signed-off-by: Bob <bob@example.com>
265 $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
266 $ cat msg.txt
267 subject
268
269 message
270
271 Signed-off-by: Bob <bob@example.com>
272 Acked-by: Alice <alice@example.com>
273
274 · Extract the last commit as a patch, and add a Cc and a Reviewed-by
275 trailer to it:
276
277 $ git format-patch -1
278 0001-foo.patch
279 $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
280
281 · Configure a sign trailer with a command to automatically add a
282 'Signed-off-by: ' with the author information only if there is no
283 'Signed-off-by: ' already, and show how it works:
284
285 $ git config trailer.sign.key "Signed-off-by: "
286 $ git config trailer.sign.ifmissing add
287 $ git config trailer.sign.ifexists doNothing
288 $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
289 $ git interpret-trailers <<EOF
290 > EOF
291
292 Signed-off-by: Bob <bob@example.com>
293 $ git interpret-trailers <<EOF
294 > Signed-off-by: Alice <alice@example.com>
295 > EOF
296
297 Signed-off-by: Alice <alice@example.com>
298
299 · Configure a fix trailer with a key that contains a # and no space
300 after this character, and show how it works:
301
302 $ git config trailer.separators ":#"
303 $ git config trailer.fix.key "Fix #"
304 $ echo "subject" | git interpret-trailers --trailer fix=42
305 subject
306
307 Fix #42
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 · Configure a commit template with some trailers with empty values
330 (using sed to show and keep the trailing spaces at the end of the
331 trailers), then configure a commit-msg hook that uses git
332 interpret-trailers to remove trailers with empty values and to add
333 a git-version trailer:
334
335 $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
336 > ***subject***
337 >
338 > ***message***
339 >
340 > Fixes: Z
341 > Cc: Z
342 > Reviewed-by: Z
343 > Signed-off-by: Z
344 > EOF
345 $ git config commit.template commit_template.txt
346 $ cat >.git/hooks/commit-msg <<EOF
347 > #!/bin/sh
348 > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
349 > mv "\$1.new" "\$1"
350 > EOF
351 $ chmod +x .git/hooks/commit-msg
352
354 git-commit(1), git-format-patch(1), git-config(1)
355
357 Part of the git(1) suite
358
359
360
361Git 2.26.2 2020-04-20 GIT-INTERPRET-TRAI(1)