]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-interpret-trailers.txt
rebase: allow overriding the maximal length of the generated labels
[thirdparty/git.git] / Documentation / git-interpret-trailers.txt
1 git-interpret-trailers(1)
2 =========================
3
4 NAME
5 ----
6 git-interpret-trailers - Add or parse structured information in commit messages
7
8 SYNOPSIS
9 --------
10 [verse]
11 'git interpret-trailers' [--in-place] [--trim-empty]
12 [(--trailer <token>[(=|:)<value>])...]
13 [--parse] [<file>...]
14
15 DESCRIPTION
16 -----------
17 Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
18 headers, at the end of the otherwise free-form part of a commit
19 message.
20
21 This command reads some patches or commit messages from either the
22 <file> arguments or the standard input if no <file> is specified. If
23 `--parse` is specified, the output consists of the parsed trailers.
24
25 Otherwise, this command applies the arguments passed using the
26 `--trailer` option, if any, to the commit message part of each input
27 file. The result is emitted on the standard output.
28
29 Some configuration variables control the way the `--trailer` arguments
30 are applied to each commit message and the way any existing trailer in
31 the commit message is changed. They also make it possible to
32 automatically add some trailers.
33
34 By default, a '<token>=<value>' or '<token>:<value>' argument given
35 using `--trailer` will be appended after the existing trailers only if
36 the last trailer has a different (<token>, <value>) pair (or if there
37 is no existing trailer). The <token> and <value> parts will be trimmed
38 to remove starting and trailing whitespace, and the resulting trimmed
39 <token> and <value> will appear in the message like this:
40
41 ------------------------------------------------
42 token: value
43 ------------------------------------------------
44
45 This means that the trimmed <token> and <value> will be separated by
46 `': '` (one colon followed by one space).
47
48 By default the new trailer will appear at the end of all the existing
49 trailers. If there is no existing trailer, the new trailer will appear
50 after the commit message part of the output, and, if there is no line
51 with only spaces at the end of the commit message part, one blank line
52 will be added before the new trailer.
53
54 Existing trailers are extracted from the input message by looking for
55 a group of one or more lines that (i) is all trailers, or (ii) contains at
56 least one Git-generated or user-configured trailer and consists of at
57 least 25% trailers.
58 The group must be preceded by one or more empty (or whitespace-only) lines.
59 The group must either be at the end of the message or be the last
60 non-whitespace lines before a line that starts with '---' (followed by a
61 space or the end of the line). Such three minus signs start the patch
62 part of the message. See also `--no-divider` below.
63
64 When reading trailers, there can be no whitespace before or inside the
65 token, but any number of regular space and tab characters are allowed
66 between the token and the separator. There can be whitespaces before,
67 inside or after the value. The value may be split over multiple lines
68 with each subsequent line starting with at least one whitespace, like
69 the "folding" in RFC 822.
70
71 Note that 'trailers' do not follow and are not intended to follow many
72 rules for RFC 822 headers. For example they do not follow
73 the encoding rules and probably many other rules.
74
75 OPTIONS
76 -------
77 --in-place::
78 Edit the files in place.
79
80 --trim-empty::
81 If the <value> part of any trailer contains only whitespace,
82 the whole trailer will be removed from the resulting message.
83 This applies to existing trailers as well as new trailers.
84
85 --trailer <token>[(=|:)<value>]::
86 Specify a (<token>, <value>) pair that should be applied as a
87 trailer to the input messages. See the description of this
88 command.
89
90 --where <placement>::
91 --no-where::
92 Specify where all new trailers will be added. A setting
93 provided with '--where' overrides all configuration variables
94 and applies to all '--trailer' options until the next occurrence of
95 '--where' or '--no-where'. Possible values are `after`, `before`,
96 `end` or `start`.
97
98 --if-exists <action>::
99 --no-if-exists::
100 Specify what action will be performed when there is already at
101 least one trailer with the same <token> in the message. A setting
102 provided with '--if-exists' overrides all configuration variables
103 and applies to all '--trailer' options until the next occurrence of
104 '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
105 `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
106
107 --if-missing <action>::
108 --no-if-missing::
109 Specify what action will be performed when there is no other
110 trailer with the same <token> in the message. A setting
111 provided with '--if-missing' overrides all configuration variables
112 and applies to all '--trailer' options until the next occurrence of
113 '--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
114 or `add`.
115
116 --only-trailers::
117 Output only the trailers, not any other parts of the input.
118
119 --only-input::
120 Output only trailers that exist in the input; do not add any
121 from the command-line or by following configured `trailer.*`
122 rules.
123
124 --unfold::
125 Remove any whitespace-continuation in trailers, so that each
126 trailer appears on a line by itself with its full content.
127
128 --parse::
129 A convenience alias for `--only-trailers --only-input
130 --unfold`.
131
132 --no-divider::
133 Do not treat `---` as the end of the commit message. Use this
134 when you know your input contains just the commit message itself
135 (and not an email or the output of `git format-patch`).
136
137 CONFIGURATION VARIABLES
138 -----------------------
139
140 trailer.separators::
141 This option tells which characters are recognized as trailer
142 separators. By default only ':' is recognized as a trailer
143 separator, except that '=' is always accepted on the command
144 line for compatibility with other git commands.
145 +
146 The first character given by this option will be the default character
147 used when another separator is not specified in the config for this
148 trailer.
149 +
150 For example, if the value for this option is "%=$", then only lines
151 using the format '<token><sep><value>' with <sep> containing '%', '='
152 or '$' and then spaces will be considered trailers. And '%' will be
153 the default separator used, so by default trailers will appear like:
154 '<token>% <value>' (one percent sign and one space will appear between
155 the token and the value).
156
157 trailer.where::
158 This option tells where a new trailer will be added.
159 +
160 This can be `end`, which is the default, `start`, `after` or `before`.
161 +
162 If it is `end`, then each new trailer will appear at the end of the
163 existing trailers.
164 +
165 If it is `start`, then each new trailer will appear at the start,
166 instead of the end, of the existing trailers.
167 +
168 If it is `after`, then each new trailer will appear just after the
169 last trailer with the same <token>.
170 +
171 If it is `before`, then each new trailer will appear just before the
172 first trailer with the same <token>.
173
174 trailer.ifexists::
175 This option makes it possible to choose what action will be
176 performed when there is already at least one trailer with the
177 same <token> in the message.
178 +
179 The valid values for this option are: `addIfDifferentNeighbor` (this
180 is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
181 +
182 With `addIfDifferentNeighbor`, a new trailer will be added only if no
183 trailer with the same (<token>, <value>) pair is above or below the line
184 where the new trailer will be added.
185 +
186 With `addIfDifferent`, a new trailer will be added only if no trailer
187 with the same (<token>, <value>) pair is already in the message.
188 +
189 With `add`, a new trailer will be added, even if some trailers with
190 the same (<token>, <value>) pair are already in the message.
191 +
192 With `replace`, an existing trailer with the same <token> will be
193 deleted and the new trailer will be added. The deleted trailer will be
194 the closest one (with the same <token>) to the place where the new one
195 will be added.
196 +
197 With `doNothing`, nothing will be done; that is no new trailer will be
198 added if there is already one with the same <token> in the message.
199
200 trailer.ifmissing::
201 This option makes it possible to choose what action will be
202 performed when there is not yet any trailer with the same
203 <token> in the message.
204 +
205 The valid values for this option are: `add` (this is the default) and
206 `doNothing`.
207 +
208 With `add`, a new trailer will be added.
209 +
210 With `doNothing`, nothing will be done.
211
212 trailer.<token>.key::
213 This `key` will be used instead of <token> in the trailer. At
214 the end of this key, a separator can appear and then some
215 space characters. By default the only valid separator is ':',
216 but this can be changed using the `trailer.separators` config
217 variable.
218 +
219 If there is a separator, then the key will be used instead of both the
220 <token> and the default separator when adding the trailer.
221
222 trailer.<token>.where::
223 This option takes the same values as the 'trailer.where'
224 configuration variable and it overrides what is specified by
225 that option for trailers with the specified <token>.
226
227 trailer.<token>.ifexists::
228 This option takes the same values as the 'trailer.ifexists'
229 configuration variable and it overrides what is specified by
230 that option for trailers with the specified <token>.
231
232 trailer.<token>.ifmissing::
233 This option takes the same values as the 'trailer.ifmissing'
234 configuration variable and it overrides what is specified by
235 that option for trailers with the specified <token>.
236
237 trailer.<token>.command::
238 This option behaves in the same way as 'trailer.<token>.cmd', except
239 that it doesn't pass anything as argument to the specified command.
240 Instead the first occurrence of substring $ARG is replaced by the
241 value that would be passed as argument.
242 +
243 The 'trailer.<token>.command' option has been deprecated in favor of
244 'trailer.<token>.cmd' due to the fact that $ARG in the user's command is
245 only replaced once and that the original way of replacing $ARG is not safe.
246 +
247 When both 'trailer.<token>.cmd' and 'trailer.<token>.command' are given
248 for the same <token>, 'trailer.<token>.cmd' is used and
249 'trailer.<token>.command' is ignored.
250
251 trailer.<token>.cmd::
252 This option can be used to specify a shell command that will be called:
253 once to automatically add a trailer with the specified <token>, and then
254 each time a '--trailer <token>=<value>' argument to modify the <value> of
255 the trailer that this option would produce.
256 +
257 When the specified command is first called to add a trailer
258 with the specified <token>, the behavior is as if a special
259 '--trailer <token>=<value>' argument was added at the beginning
260 of the "git interpret-trailers" command, where <value>
261 is taken to be the standard output of the command with any
262 leading and trailing whitespace trimmed off.
263 +
264 If some '--trailer <token>=<value>' arguments are also passed
265 on the command line, the command is called again once for each
266 of these arguments with the same <token>. And the <value> part
267 of these arguments, if any, will be passed to the command as its
268 first argument. This way the command can produce a <value> computed
269 from the <value> passed in the '--trailer <token>=<value>' argument.
270
271 EXAMPLES
272 --------
273
274 * Configure a 'sign' trailer with a 'Signed-off-by' key, and then
275 add two of these trailers to a message:
276 +
277 ------------
278 $ git config trailer.sign.key "Signed-off-by"
279 $ cat msg.txt
280 subject
281
282 message
283 $ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
284 subject
285
286 message
287
288 Signed-off-by: Alice <alice@example.com>
289 Signed-off-by: Bob <bob@example.com>
290 ------------
291
292 * Use the `--in-place` option to edit a message file in place:
293 +
294 ------------
295 $ cat msg.txt
296 subject
297
298 message
299
300 Signed-off-by: Bob <bob@example.com>
301 $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
302 $ cat msg.txt
303 subject
304
305 message
306
307 Signed-off-by: Bob <bob@example.com>
308 Acked-by: Alice <alice@example.com>
309 ------------
310
311 * Extract the last commit as a patch, and add a 'Cc' and a
312 'Reviewed-by' trailer to it:
313 +
314 ------------
315 $ git format-patch -1
316 0001-foo.patch
317 $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
318 ------------
319
320 * Configure a 'sign' trailer with a command to automatically add a
321 'Signed-off-by: ' with the author information only if there is no
322 'Signed-off-by: ' already, and show how it works:
323 +
324 ------------
325 $ cat msg1.txt
326 subject
327
328 message
329 $ git config trailer.sign.key "Signed-off-by: "
330 $ git config trailer.sign.ifmissing add
331 $ git config trailer.sign.ifexists doNothing
332 $ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"'
333 $ git interpret-trailers --trailer sign <msg1.txt
334 subject
335
336 message
337
338 Signed-off-by: Bob <bob@example.com>
339 $ cat msg2.txt
340 subject
341
342 message
343
344 Signed-off-by: Alice <alice@example.com>
345 $ git interpret-trailers --trailer sign <msg2.txt
346 subject
347
348 message
349
350 Signed-off-by: Alice <alice@example.com>
351 ------------
352
353 * Configure a 'fix' trailer with a key that contains a '#' and no
354 space after this character, and show how it works:
355 +
356 ------------
357 $ git config trailer.separators ":#"
358 $ git config trailer.fix.key "Fix #"
359 $ echo "subject" | git interpret-trailers --trailer fix=42
360 subject
361
362 Fix #42
363 ------------
364
365 * Configure a 'help' trailer with a cmd use a script `glog-find-author`
366 which search specified author identity from git log in git repository
367 and show how it works:
368 +
369 ------------
370 $ cat ~/bin/glog-find-author
371 #!/bin/sh
372 test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
373 $ cat msg.txt
374 subject
375
376 message
377 $ git config trailer.help.key "Helped-by: "
378 $ git config trailer.help.ifExists "addIfDifferentNeighbor"
379 $ git config trailer.help.cmd "~/bin/glog-find-author"
380 $ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
381 subject
382
383 message
384
385 Helped-by: Junio C Hamano <gitster@pobox.com>
386 Helped-by: Christian Couder <christian.couder@gmail.com>
387 ------------
388
389 * Configure a 'ref' trailer with a cmd use a script `glog-grep`
390 to grep last relevant commit from git log in the git repository
391 and show how it works:
392 +
393 ------------
394 $ cat ~/bin/glog-grep
395 #!/bin/sh
396 test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
397 $ cat msg.txt
398 subject
399
400 message
401 $ git config trailer.ref.key "Reference-to: "
402 $ git config trailer.ref.ifExists "replace"
403 $ git config trailer.ref.cmd "~/bin/glog-grep"
404 $ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
405 subject
406
407 message
408
409 Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
410 ------------
411
412 * Configure a 'see' trailer with a command to show the subject of a
413 commit that is related, and show how it works:
414 +
415 ------------
416 $ cat msg.txt
417 subject
418
419 message
420
421 see: HEAD~2
422 $ cat ~/bin/glog-ref
423 #!/bin/sh
424 git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
425 $ git config trailer.see.key "See-also: "
426 $ git config trailer.see.ifExists "replace"
427 $ git config trailer.see.ifMissing "doNothing"
428 $ git config trailer.see.cmd "glog-ref"
429 $ git interpret-trailers --trailer=see <msg.txt
430 subject
431
432 message
433
434 See-also: fe3187489d69c4 (subject of related commit)
435 ------------
436
437 * Configure a commit template with some trailers with empty values
438 (using sed to show and keep the trailing spaces at the end of the
439 trailers), then configure a commit-msg hook that uses
440 'git interpret-trailers' to remove trailers with empty values and
441 to add a 'git-version' trailer:
442 +
443 ------------
444 $ cat temp.txt
445 ***subject***
446
447 ***message***
448
449 Fixes: Z
450 Cc: Z
451 Reviewed-by: Z
452 Signed-off-by: Z
453 $ sed -e 's/ Z$/ /' temp.txt > commit_template.txt
454 $ git config commit.template commit_template.txt
455 $ cat .git/hooks/commit-msg
456 #!/bin/sh
457 git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
458 mv "\$1.new" "\$1"
459 $ chmod +x .git/hooks/commit-msg
460 ------------
461
462 SEE ALSO
463 --------
464 linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
465
466 GIT
467 ---
468 Part of the linkgit:git[1] suite