1 git-interpret-trailers(1)
2 =========================
6 git-interpret-trailers - Add or parse structured information in commit messages
11 'git interpret-trailers' [--in-place] [--trim-empty]
12 [(--trailer (<key>|<key-alias>)[(=|:)<value>])...]
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 ------------------------------------------------
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 coming from the input, without influencing them with any command line
36 options or configuration variables.
38 Otherwise, this command applies `trailer.*` configuration variables
39 (which could potentially add new trailers, as well as reposition them),
40 as well as any command line arguments that can override configuration
41 variables (such as `--trailer=...` which could also add new trailers),
42 to each input file. The result is emitted on the standard output.
44 This command can also operate on the output of linkgit:git-format-patch[1],
45 which is more elaborate than a plain commit message. Namely, such output
46 includes a commit message (as above), a "---" divider line, and a patch part.
47 For these inputs, the divider and patch parts are not modified by
48 this command and are emitted as is on the output, unless
49 `--no-divider` is specified.
51 Some configuration variables control the way the `--trailer` arguments
52 are applied to each input and the way any existing trailer in
53 the input is changed. They also make it possible to
54 automatically add some trailers.
56 By default, a '<key>=<value>' or '<key>:<value>' argument given
57 using `--trailer` will be appended after the existing trailers only if
58 the last trailer has a different (<key>, <value>) pair (or if there
59 is no existing trailer). The <key> and <value> parts will be trimmed
60 to remove starting and trailing whitespace, and the resulting trimmed
61 <key> and <value> will appear in the output like this:
63 ------------------------------------------------
65 ------------------------------------------------
67 This means that the trimmed <key> and <value> will be separated by
68 `': '` (one colon followed by one space).
70 For convenience, a <key-alias> can be configured to make using `--trailer`
71 shorter to type on the command line. This can be configured using the
72 'trailer.<key-alias>.key' configuration variable. The <keyAlias> must be a prefix
73 of the full <key> string, although case sensitivity does not matter. For
76 ------------------------------------------------
77 trailer.sign.key "Signed-off-by: "
78 ------------------------------------------------
80 in your configuration, you only need to specify `--trailer="sign: foo"`
81 on the command line instead of `--trailer="Signed-off-by: foo"`.
83 By default the new trailer will appear at the end of all the existing
84 trailers. If there is no existing trailer, the new trailer will appear
85 at the end of the input. A blank line will be added before the new
86 trailer if there isn't one already.
88 Existing trailers are extracted from the input by looking for
89 a group of one or more lines that (i) is all trailers, or (ii) contains at
90 least one Git-generated or user-configured trailer and consists of at
92 The group must be preceded by one or more empty (or whitespace-only) lines.
93 The group must either be at the end of the input or be the last
94 non-whitespace lines before a line that starts with '---' (followed by a
95 space or the end of the line).
97 When reading trailers, there can be no whitespace before or inside the
98 <key>, but any number of regular space and tab characters are allowed
99 between the <key> and the separator. There can be whitespaces before,
100 inside or after the <value>. The <value> may be split over multiple lines
101 with each subsequent line starting with at least one whitespace, like
102 the "folding" in RFC 822. Example:
104 ------------------------------------------------
105 key: This is a very long value, with spaces and
107 ------------------------------------------------
109 Note that trailers do not follow (nor are they intended to follow) many of the
110 rules for RFC 822 headers. For example they do not follow the encoding rule.
115 Edit the files in place.
118 If the <value> part of any trailer contains only whitespace,
119 the whole trailer will be removed from the output.
120 This applies to existing trailers as well as new trailers.
122 --trailer <key>[(=|:)<value>]::
123 Specify a (<key>, <value>) pair that should be applied as a
124 trailer to the inputs. See the description of this
127 --where <placement>::
129 Specify where all new trailers will be added. A setting
130 provided with '--where' overrides the `trailer.where` and any
131 applicable `trailer.<keyAlias>.where` configuration variables
132 and applies to all '--trailer' options until the next occurrence of
133 '--where' or '--no-where'. Upon encountering '--no-where', clear the
134 effect of any previous use of '--where', such that the relevant configuration
135 variables are no longer overridden. Possible placements are `after`,
136 `before`, `end` or `start`.
138 --if-exists <action>::
140 Specify what action will be performed when there is already at
141 least one trailer with the same <key> in the input. A setting
142 provided with '--if-exists' overrides the `trailer.ifExists` and any
143 applicable `trailer.<keyAlias>.ifExists` configuration variables
144 and applies to all '--trailer' options until the next occurrence of
145 '--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the
146 effect of any previous use of '--if-exists, such that the relevant configuration
147 variables are no longer overridden. Possible actions are `addIfDifferent`,
148 `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
150 --if-missing <action>::
152 Specify what action will be performed when there is no other
153 trailer with the same <key> in the input. A setting
154 provided with '--if-missing' overrides the `trailer.ifMissing` and any
155 applicable `trailer.<keyAlias>.ifMissing` configuration variables
156 and applies to all '--trailer' options until the next occurrence of
157 '--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing,
158 clear the effect of any previous use of '--if-missing, such that the relevant
159 configuration variables are no longer overridden. Possible actions are `doNothing`
163 Output only the trailers, not any other parts of the input.
166 Output only trailers that exist in the input; do not add any
167 from the command-line or by applying `trailer.*` configuration
171 If a trailer has a value that runs over multiple lines (aka "folded"),
172 reformat the value into a single line.
175 A convenience alias for `--only-trailers --only-input
176 --unfold`. This makes it easier to only see the trailers coming from the
177 input without influencing them with any command line options or
178 configuration variables, while also making the output machine-friendly with
182 Do not treat `---` as the end of the commit message. Use this
183 when you know your input contains just the commit message itself
184 (and not an email or the output of `git format-patch`).
186 CONFIGURATION VARIABLES
187 -----------------------
190 This option tells which characters are recognized as trailer
191 separators. By default only ':' is recognized as a trailer
192 separator, except that '=' is always accepted on the command
193 line for compatibility with other git commands.
195 The first character given by this option will be the default character
196 used when another separator is not specified in the config for this
199 For example, if the value for this option is "%=$", then only lines
200 using the format '<key><sep><value>' with <sep> containing '%', '='
201 or '$' and then spaces will be considered trailers. And '%' will be
202 the default separator used, so by default trailers will appear like:
203 '<key>% <value>' (one percent sign and one space will appear between
204 the key and the value).
207 This option tells where a new trailer will be added.
209 This can be `end`, which is the default, `start`, `after` or `before`.
211 If it is `end`, then each new trailer will appear at the end of the
214 If it is `start`, then each new trailer will appear at the start,
215 instead of the end, of the existing trailers.
217 If it is `after`, then each new trailer will appear just after the
218 last trailer with the same <key>.
220 If it is `before`, then each new trailer will appear just before the
221 first trailer with the same <key>.
224 This option makes it possible to choose what action will be
225 performed when there is already at least one trailer with the
226 same <key> in the input.
228 The valid values for this option are: `addIfDifferentNeighbor` (this
229 is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
231 With `addIfDifferentNeighbor`, a new trailer will be added only if no
232 trailer with the same (<key>, <value>) pair is above or below the line
233 where the new trailer will be added.
235 With `addIfDifferent`, a new trailer will be added only if no trailer
236 with the same (<key>, <value>) pair is already in the input.
238 With `add`, a new trailer will be added, even if some trailers with
239 the same (<key>, <value>) pair are already in the input.
241 With `replace`, an existing trailer with the same <key> will be
242 deleted and the new trailer will be added. The deleted trailer will be
243 the closest one (with the same <key>) to the place where the new one
246 With `doNothing`, nothing will be done; that is no new trailer will be
247 added if there is already one with the same <key> in the input.
250 This option makes it possible to choose what action will be
251 performed when there is not yet any trailer with the same
254 The valid values for this option are: `add` (this is the default) and
257 With `add`, a new trailer will be added.
259 With `doNothing`, nothing will be done.
261 trailer.<keyAlias>.key::
262 Defines a <keyAlias> for the <key>. The <keyAlias> must be a
263 prefix (case does not matter) of the <key>. For example, in `git
264 config trailer.ack.key "Acked-by"` the "Acked-by" is the <key> and
265 the "ack" is the <keyAlias>. This configuration allows the shorter
266 `--trailer "ack:..."` invocation on the command line using the "ack"
267 <keyAlias> instead of the longer `--trailer "Acked-by:..."`.
269 At the end of the <key>, a separator can appear and then some
270 space characters. By default the only valid separator is ':',
271 but this can be changed using the `trailer.separators` config
274 If there is a separator in the key, then it overrides the default
275 separator when adding the trailer.
277 trailer.<keyAlias>.where::
278 This option takes the same values as the 'trailer.where'
279 configuration variable and it overrides what is specified by
280 that option for trailers with the specified <keyAlias>.
282 trailer.<keyAlias>.ifexists::
283 This option takes the same values as the 'trailer.ifexists'
284 configuration variable and it overrides what is specified by
285 that option for trailers with the specified <keyAlias>.
287 trailer.<keyAlias>.ifmissing::
288 This option takes the same values as the 'trailer.ifmissing'
289 configuration variable and it overrides what is specified by
290 that option for trailers with the specified <keyAlias>.
292 trailer.<keyAlias>.command::
293 Deprecated in favor of 'trailer.<keyAlias>.cmd'.
294 This option behaves in the same way as 'trailer.<keyAlias>.cmd', except
295 that it doesn't pass anything as argument to the specified command.
296 Instead the first occurrence of substring $ARG is replaced by the
297 <value> that would be passed as argument.
299 Note that $ARG in the user's command is
300 only replaced once and that the original way of replacing $ARG is not safe.
302 When both 'trailer.<keyAlias>.cmd' and 'trailer.<keyAlias>.command' are given
303 for the same <keyAlias>, 'trailer.<keyAlias>.cmd' is used and
304 'trailer.<keyAlias>.command' is ignored.
306 trailer.<keyAlias>.cmd::
307 This option can be used to specify a shell command that will be called
308 once to automatically add a trailer with the specified <keyAlias>, and then
309 called each time a '--trailer <keyAlias>=<value>' argument is specified to
310 modify the <value> of the trailer that this option would produce.
312 When the specified command is first called to add a trailer
313 with the specified <keyAlias>, the behavior is as if a special
314 '--trailer <keyAlias>=<value>' argument was added at the beginning
315 of the "git interpret-trailers" command, where <value>
316 is taken to be the standard output of the command with any
317 leading and trailing whitespace trimmed off.
319 If some '--trailer <keyAlias>=<value>' arguments are also passed
320 on the command line, the command is called again once for each
321 of these arguments with the same <keyAlias>. And the <value> part
322 of these arguments, if any, will be passed to the command as its
323 first argument. This way the command can produce a <value> computed
324 from the <value> passed in the '--trailer <keyAlias>=<value>' argument.
329 * Configure a 'sign' trailer with a 'Signed-off-by' key, and then
330 add two of these trailers to a commit message file:
333 $ git config trailer.sign.key "Signed-off-by"
338 $ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
343 Signed-off-by: Alice <alice@example.com>
344 Signed-off-by: Bob <bob@example.com>
347 * Use the `--in-place` option to edit a commit message file in place:
355 Signed-off-by: Bob <bob@example.com>
356 $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
362 Signed-off-by: Bob <bob@example.com>
363 Acked-by: Alice <alice@example.com>
366 * Extract the last commit as a patch, and add a 'Cc' and a
367 'Reviewed-by' trailer to it:
370 $ git format-patch -1
372 $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
375 * Configure a 'sign' trailer with a command to automatically add a
376 'Signed-off-by: ' with the author information only if there is no
377 'Signed-off-by: ' already, and show how it works:
384 $ git config trailer.sign.key "Signed-off-by: "
385 $ git config trailer.sign.ifmissing add
386 $ git config trailer.sign.ifexists doNothing
387 $ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"'
388 $ git interpret-trailers --trailer sign <msg1.txt
393 Signed-off-by: Bob <bob@example.com>
399 Signed-off-by: Alice <alice@example.com>
400 $ git interpret-trailers --trailer sign <msg2.txt
405 Signed-off-by: Alice <alice@example.com>
408 * Configure a 'fix' trailer with a key that contains a '#' and no
409 space after this character, and show how it works:
412 $ git config trailer.separators ":#"
413 $ git config trailer.fix.key "Fix #"
414 $ echo "subject" | git interpret-trailers --trailer fix=42
420 * Configure a 'help' trailer with a cmd use a script `glog-find-author`
421 which search specified author identity from git log in git repository
422 and show how it works:
425 $ cat ~/bin/glog-find-author
427 test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
432 $ git config trailer.help.key "Helped-by: "
433 $ git config trailer.help.ifExists "addIfDifferentNeighbor"
434 $ git config trailer.help.cmd "~/bin/glog-find-author"
435 $ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
440 Helped-by: Junio C Hamano <gitster@pobox.com>
441 Helped-by: Christian Couder <christian.couder@gmail.com>
444 * Configure a 'ref' trailer with a cmd use a script `glog-grep`
445 to grep last relevant commit from git log in the git repository
446 and show how it works:
449 $ cat ~/bin/glog-grep
451 test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
456 $ git config trailer.ref.key "Reference-to: "
457 $ git config trailer.ref.ifExists "replace"
458 $ git config trailer.ref.cmd "~/bin/glog-grep"
459 $ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
464 Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
467 * Configure a 'see' trailer with a command to show the subject of a
468 commit that is related, and show how it works:
479 git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
480 $ git config trailer.see.key "See-also: "
481 $ git config trailer.see.ifExists "replace"
482 $ git config trailer.see.ifMissing "doNothing"
483 $ git config trailer.see.cmd "glog-ref"
484 $ git interpret-trailers --trailer=see <msg.txt
489 See-also: fe3187489d69c4 (subject of related commit)
492 * Configure a commit template with some trailers with empty values
493 (using sed to show and keep the trailing spaces at the end of the
494 trailers), then configure a commit-msg hook that uses
495 'git interpret-trailers' to remove trailers with empty values and
496 to add a 'git-version' trailer:
508 $ sed -e 's/ Z$/ /' temp.txt > commit_template.txt
509 $ git config commit.template commit_template.txt
510 $ cat .git/hooks/commit-msg
512 git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
514 $ chmod +x .git/hooks/commit-msg
519 linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
523 Part of the linkgit:git[1] suite