2 .\" Title: git-interpret-trailers
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.46.0.421.g159f2d50e7
10 .TH "GIT\-INTERPRET\-TRAILERS" "1" "2024-08-26" "Git 2\&.46\&.0\&.421\&.g159f2d" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-interpret-trailers \- Add or parse structured information in commit messages
35 \fIgit interpret\-trailers\fR [\-\-in\-place] [\-\-trim\-empty]
36 [(\-\-trailer (<key>|<key\-alias>)[(=|:)<value>])\&...\:]
37 [\-\-parse] [<file>\&...\:]
41 Add or parse \fItrailer\fR lines that look similar to RFC 822 e\-mail headers, at the end of the otherwise free\-form part of a commit message\&. For example, in the following commit message
49 Lorem ipsum dolor sit amet, consectetur adipiscing elit\&.
51 Signed\-off\-by: Alice <alice@example\&.com>
52 Signed\-off\-by: Bob <bob@example\&.com>
58 the last two lines starting with "Signed\-off\-by" are trailers\&.
60 This command reads commit messages from either the <file> arguments or the standard input if no <file> is specified\&. If \fB\-\-parse\fR is specified, the output consists of the parsed trailers coming from the input, without influencing them with any command line options or configuration variables\&.
62 Otherwise, this command applies \fBtrailer\&.*\fR configuration variables (which could potentially add new trailers, as well as reposition them), as well as any command line arguments that can override configuration variables (such as \fB\-\-trailer=\&.\&.\&.\fR which could also add new trailers), to each input file\&. The result is emitted on the standard output\&.
64 This command can also operate on the output of \fBgit-format-patch\fR(1), which is more elaborate than a plain commit message\&. Namely, such output includes a commit message (as above), a "\-\-\-" divider line, and a patch part\&. For these inputs, the divider and patch parts are not modified by this command and are emitted as is on the output, unless \fB\-\-no\-divider\fR is specified\&.
66 Some configuration variables control the way the \fB\-\-trailer\fR arguments are applied to each input and the way any existing trailer in the input is changed\&. They also make it possible to automatically add some trailers\&.
68 By default, a \fI<key>=<value>\fR or \fI<key>:<value>\fR argument given using \fB\-\-trailer\fR will be appended after the existing trailers only if the last trailer has a different (<key>, <value>) pair (or if there is no existing trailer)\&. The <key> and <value> parts will be trimmed to remove starting and trailing whitespace, and the resulting trimmed <key> and <value> will appear in the output like this:
80 This means that the trimmed <key> and <value> will be separated by \fB\*(Aq: \*(Aq\fR (one colon followed by one space)\&.
82 For convenience, a <key\-alias> can be configured to make using \fB\-\-trailer\fR shorter to type on the command line\&. This can be configured using the \fItrailer\&.<key\-alias>\&.key\fR configuration variable\&. The <keyAlias> must be a prefix of the full <key> string, although case sensitivity does not matter\&. For example, if you have
88 trailer\&.sign\&.key "Signed\-off\-by: "
94 in your configuration, you only need to specify \fB\-\-trailer="sign: foo"\fR on the command line instead of \fB\-\-trailer="Signed\-off\-by: foo"\fR\&.
96 By default the new trailer will appear at the end of all the existing trailers\&. If there is no existing trailer, the new trailer will appear at the end of the input\&. A blank line will be added before the new trailer if there isn\(cqt one already\&.
98 Existing trailers are extracted from the input by looking for a group of one or more lines that (i) is all trailers, or (ii) contains at least one Git\-generated or user\-configured trailer and consists of at least 25% trailers\&. The group must be preceded by one or more empty (or whitespace\-only) lines\&. The group must either be at the end of the input or be the last non\-whitespace lines before a line that starts with \fI\-\-\-\fR (followed by a space or the end of the line)\&.
100 When reading trailers, there can be no whitespace before or inside the <key>, but any number of regular space and tab characters are allowed between the <key> and the separator\&. There can be whitespaces before, inside or after the <value>\&. The <value> may be split over multiple lines with each subsequent line starting with at least one whitespace, like the "folding" in RFC 822\&. Example:
106 key: This is a very long value, with spaces and
113 Note that trailers do not follow (nor are they intended to follow) many of the rules for RFC 822 headers\&. For example they do not follow the encoding rule\&.
118 Edit the files in place\&.
123 If the <value> part of any trailer contains only whitespace, the whole trailer will be removed from the output\&. This applies to existing trailers as well as new trailers\&.
126 \-\-trailer <key>[(=|:)<value>]
128 Specify a (<key>, <value>) pair that should be applied as a trailer to the inputs\&. See the description of this command\&.
131 \-\-where <placement>, \-\-no\-where
133 Specify where all new trailers will be added\&. A setting provided with
136 \fBtrailer\&.where\fR
138 \fBtrailer\&.<keyAlias>\&.where\fR
139 configuration variables and applies to all
141 options until the next occurrence of
144 \fI\-\-no\-where\fR\&. Upon encountering
145 \fI\-\-no\-where\fR, clear the effect of any previous use of
146 \fI\-\-where\fR, such that the relevant configuration variables are no longer overridden\&. Possible placements are
154 \-\-if\-exists <action>, \-\-no\-if\-exists
156 Specify what action will be performed when there is already at least one trailer with the same <key> in the input\&. A setting provided with
159 \fBtrailer\&.ifExists\fR
161 \fBtrailer\&.<keyAlias>\&.ifExists\fR
162 configuration variables and applies to all
164 options until the next occurrence of
167 \fI\-\-no\-if\-exists\fR\&. Upon encountering \*(Aq\-\-no\-if\-exists, clear the effect of any previous use of \*(Aq\-\-if\-exists, such that the relevant configuration variables are no longer overridden\&. Possible actions are
168 \fBaddIfDifferent\fR,
169 \fBaddIfDifferentNeighbor\fR,
176 \-\-if\-missing <action>, \-\-no\-if\-missing
178 Specify what action will be performed when there is no other trailer with the same <key> in the input\&. A setting provided with
179 \fI\-\-if\-missing\fR
181 \fBtrailer\&.ifMissing\fR
183 \fBtrailer\&.<keyAlias>\&.ifMissing\fR
184 configuration variables and applies to all
186 options until the next occurrence of
187 \fI\-\-if\-missing\fR
189 \fI\-\-no\-if\-missing\fR\&. Upon encountering \*(Aq\-\-no\-if\-missing, clear the effect of any previous use of \*(Aq\-\-if\-missing, such that the relevant configuration variables are no longer overridden\&. Possible actions are
197 Output only the trailers, not any other parts of the input\&.
202 Output only trailers that exist in the input; do not add any from the command\-line or by applying
204 configuration variables\&.
209 If a trailer has a value that runs over multiple lines (aka "folded"), reformat the value into a single line\&.
214 A convenience alias for
215 \fB\-\-only\-trailers \-\-only\-input \-\-unfold\fR\&. This makes it easier to only see the trailers coming from the input without influencing them with any command line options or configuration variables, while also making the output machine\-friendly with \-\-unfold\&.
222 as the end of the commit message\&. Use this when you know your input contains just the commit message itself (and not an email or the output of
223 \fBgit format\-patch\fR)\&.
225 .SH "CONFIGURATION VARIABLES"
229 This option tells which characters are recognized as trailer separators\&. By default only
231 is recognized as a trailer separator, except that
233 is always accepted on the command line for compatibility with other git commands\&.
235 The first character given by this option will be the default character used when another separator is not specified in the config for this trailer\&.
237 For example, if the value for this option is "%=$", then only lines using the format
238 \fI<key><sep><value>\fR
239 with <sep> containing
244 and then spaces will be considered trailers\&. And
246 will be the default separator used, so by default trailers will appear like:
248 (one percent sign and one space will appear between the key and the value)\&.
253 This option tells where a new trailer will be added\&.
256 \fBend\fR, which is the default,
263 \fBend\fR, then each new trailer will appear at the end of the existing trailers\&.
266 \fBstart\fR, then each new trailer will appear at the start, instead of the end, of the existing trailers\&.
269 \fBafter\fR, then each new trailer will appear just after the last trailer with the same <key>\&.
272 \fBbefore\fR, then each new trailer will appear just before the first trailer with the same <key>\&.
277 This option makes it possible to choose what action will be performed when there is already at least one trailer with the same <key> in the input\&.
279 The valid values for this option are:
280 \fBaddIfDifferentNeighbor\fR
281 (this is the default),
282 \fBaddIfDifferent\fR,
289 \fBaddIfDifferentNeighbor\fR, a new trailer will be added only if no trailer with the same (<key>, <value>) pair is above or below the line where the new trailer will be added\&.
292 \fBaddIfDifferent\fR, a new trailer will be added only if no trailer with the same (<key>, <value>) pair is already in the input\&.
295 \fBadd\fR, a new trailer will be added, even if some trailers with the same (<key>, <value>) pair are already in the input\&.
298 \fBreplace\fR, an existing trailer with the same <key> will be deleted and the new trailer will be added\&. The deleted trailer will be the closest one (with the same <key>) to the place where the new one will be added\&.
301 \fBdoNothing\fR, nothing will be done; that is no new trailer will be added if there is already one with the same <key> in the input\&.
306 This option makes it possible to choose what action will be performed when there is not yet any trailer with the same <key> in the input\&.
308 The valid values for this option are:
310 (this is the default) and
314 \fBadd\fR, a new trailer will be added\&.
317 \fBdoNothing\fR, nothing will be done\&.
320 trailer\&.<keyAlias>\&.key
322 Defines a <keyAlias> for the <key>\&. The <keyAlias> must be a prefix (case does not matter) of the <key>\&. For example, in
323 \fBgit config trailer\&.ack\&.key "Acked\-by"\fR
324 the "Acked\-by" is the <key> and the "ack" is the <keyAlias>\&. This configuration allows the shorter
325 \fB\-\-trailer "ack:\&.\&.\&."\fR
326 invocation on the command line using the "ack" <keyAlias> instead of the longer
327 \fB\-\-trailer "Acked\-by:\&.\&.\&."\fR\&.
329 At the end of the <key>, a separator can appear and then some space characters\&. By default the only valid separator is
330 \fI:\fR, but this can be changed using the
331 \fBtrailer\&.separators\fR
334 If there is a separator in the key, then it overrides the default separator when adding the trailer\&.
337 trailer\&.<keyAlias>\&.where
339 This option takes the same values as the
340 \fItrailer\&.where\fR
341 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
344 trailer\&.<keyAlias>\&.ifexists
346 This option takes the same values as the
347 \fItrailer\&.ifexists\fR
348 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
351 trailer\&.<keyAlias>\&.ifmissing
353 This option takes the same values as the
354 \fItrailer\&.ifmissing\fR
355 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
358 trailer\&.<keyAlias>\&.command
360 Deprecated in favor of
361 \fItrailer\&.<keyAlias>\&.cmd\fR\&. This option behaves in the same way as
362 \fItrailer\&.<keyAlias>\&.cmd\fR, except that it doesn\(cqt pass anything as argument to the specified command\&. Instead the first occurrence of substring $ARG is replaced by the <value> that would be passed as argument\&.
364 Note that $ARG in the user\(cqs command is only replaced once and that the original way of replacing $ARG is not safe\&.
367 \fItrailer\&.<keyAlias>\&.cmd\fR
369 \fItrailer\&.<keyAlias>\&.command\fR
370 are given for the same <keyAlias>,
371 \fItrailer\&.<keyAlias>\&.cmd\fR
373 \fItrailer\&.<keyAlias>\&.command\fR
377 trailer\&.<keyAlias>\&.cmd
379 This option can be used to specify a shell command that will be called once to automatically add a trailer with the specified <keyAlias>, and then called each time a
380 \fI\-\-trailer <keyAlias>=<value>\fR
381 argument is specified to modify the <value> of the trailer that this option would produce\&.
383 When the specified command is first called to add a trailer with the specified <keyAlias>, the behavior is as if a special
384 \fI\-\-trailer <keyAlias>=<value>\fR
385 argument was added at the beginning of the "git interpret\-trailers" command, where <value> is taken to be the standard output of the command with any leading and trailing whitespace trimmed off\&.
388 \fI\-\-trailer <keyAlias>=<value>\fR
389 arguments are also passed on the command line, the command is called again once for each of these arguments with the same <keyAlias>\&. And the <value> part of these arguments, if any, will be passed to the command as its first argument\&. This way the command can produce a <value> computed from the <value> passed in the
390 \fI\-\-trailer <keyAlias>=<value>\fR
406 \fISigned\-off\-by\fR
407 key, and then add two of these trailers to a commit message file:
413 $ git config trailer\&.sign\&.key "Signed\-off\-by"
418 $ git interpret\-trailers \-\-trailer \*(Aqsign: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(Aqsign: Bob <bob@example\&.com>\*(Aq <msg\&.txt
423 Signed\-off\-by: Alice <alice@example\&.com>
424 Signed\-off\-by: Bob <bob@example\&.com>
441 option to edit a commit message file in place:
452 Signed\-off\-by: Bob <bob@example\&.com>
453 $ git interpret\-trailers \-\-trailer \*(AqAcked\-by: Alice <alice@example\&.com>\*(Aq \-\-in\-place msg\&.txt
459 Signed\-off\-by: Bob <bob@example\&.com>
460 Acked\-by: Alice <alice@example\&.com>
475 Extract the last commit as a patch, and add a
485 $ git format\-patch \-1
487 $ git interpret\-trailers \-\-trailer \*(AqCc: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(AqReviewed\-by: Bob <bob@example\&.com>\*(Aq 0001\-foo\&.patch >0001\-bar\&.patch
504 trailer with a command to automatically add a \*(AqSigned\-off\-by: \*(Aq with the author information only if there is no \*(AqSigned\-off\-by: \*(Aq already, and show how it works:
514 $ git config trailer\&.sign\&.key "Signed\-off\-by: "
515 $ git config trailer\&.sign\&.ifmissing add
516 $ git config trailer\&.sign\&.ifexists doNothing
517 $ git config trailer\&.sign\&.cmd \*(Aqecho "$(git config user\&.name) <$(git config user\&.email)>"\*(Aq
518 $ git interpret\-trailers \-\-trailer sign <msg1\&.txt
523 Signed\-off\-by: Bob <bob@example\&.com>
529 Signed\-off\-by: Alice <alice@example\&.com>
530 $ git interpret\-trailers \-\-trailer sign <msg2\&.txt
535 Signed\-off\-by: Alice <alice@example\&.com>
552 trailer with a key that contains a
554 and no space after this character, and show how it works:
560 $ git config trailer\&.separators ":#"
561 $ git config trailer\&.fix\&.key "Fix #"
562 $ echo "subject" | git interpret\-trailers \-\-trailer fix=42
582 trailer with a cmd use a script
583 \fBglog\-find\-author\fR
584 which search specified author identity from git log in git repository and show how it works:
590 $ cat ~/bin/glog\-find\-author
592 test \-n "$1" && git log \-\-author="$1" \-\-pretty="%an <%ae>" \-1 || true
597 $ git config trailer\&.help\&.key "Helped\-by: "
598 $ git config trailer\&.help\&.ifExists "addIfDifferentNeighbor"
599 $ git config trailer\&.help\&.cmd "~/bin/glog\-find\-author"
600 $ git interpret\-trailers \-\-trailer="help:Junio" \-\-trailer="help:Couder" <msg\&.txt
605 Helped\-by: Junio C Hamano <gitster@pobox\&.com>
606 Helped\-by: Christian Couder <christian\&.couder@gmail\&.com>
623 trailer with a cmd use a script
625 to grep last relevant commit from git log in the git repository and show how it works:
631 $ cat ~/bin/glog\-grep
633 test \-n "$1" && git log \-\-grep "$1" \-\-pretty=reference \-1 || true
638 $ git config trailer\&.ref\&.key "Reference\-to: "
639 $ git config trailer\&.ref\&.ifExists "replace"
640 $ git config trailer\&.ref\&.cmd "~/bin/glog\-grep"
641 $ git interpret\-trailers \-\-trailer="ref:Add copyright notices\&." <msg\&.txt
646 Reference\-to: 8bc9a0c769 (Add copyright notices\&., 2005\-04\-07)
663 trailer with a command to show the subject of a commit that is related, and show how it works:
675 $ cat ~/bin/glog\-ref
677 git log \-1 \-\-oneline \-\-format="%h (%s)" \-\-abbrev\-commit \-\-abbrev=14
678 $ git config trailer\&.see\&.key "See\-also: "
679 $ git config trailer\&.see\&.ifExists "replace"
680 $ git config trailer\&.see\&.ifMissing "doNothing"
681 $ git config trailer\&.see\&.cmd "glog\-ref"
682 $ git interpret\-trailers \-\-trailer=see <msg\&.txt
687 See\-also: fe3187489d69c4 (subject of related commit)
702 Configure a commit template with some trailers with empty values (using sed to show and keep the trailing spaces at the end of the trailers), then configure a commit\-msg hook that uses
703 \fIgit interpret\-trailers\fR
704 to remove trailers with empty values and to add a
721 $ sed \-e \*(Aqs/ Z$/ /\*(Aq temp\&.txt > commit_template\&.txt
722 $ git config commit\&.template commit_template\&.txt
723 $ cat \&.git/hooks/commit\-msg
725 git interpret\-trailers \-\-trim\-empty \-\-trailer "git\-version: \e$(git describe)" "\e$1" > "\e$1\&.new"
726 mv "\e$1\&.new" "\e$1"
727 $ chmod +x \&.git/hooks/commit\-msg
735 \fBgit-commit\fR(1), \fBgit-format-patch\fR(1), \fBgit-config\fR(1)
738 Part of the \fBgit\fR(1) suite