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