2 .\" Title: git-interpret-trailers
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.44.0.rc1
10 .TH "GIT\-INTERPRET\-TRAILERS" "1" "2024\-02\-13" "Git 2\&.44\&.0\&.rc1" "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>|<keyAlias>)[(=|:)<value>])\&...]
37 [\-\-parse] [<file>\&...]
42 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
50 Lorem ipsum dolor sit amet, consectetur adipiscing elit\&.
52 Signed\-off\-by: Alice <alice@example\&.com>
53 Signed\-off\-by: Bob <bob@example\&.com>
60 the last two lines starting with "Signed\-off\-by" are trailers\&.
62 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\&.
64 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\&.
66 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\&.
68 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\&.
70 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:
83 This means that the trimmed <key> and <value> will be separated by \fB\*(Aq: \*(Aq\fR (one colon followed by one space)\&.
85 For convenience, a <keyAlias> can be configured to make using \fB\-\-trailer\fR shorter to type on the command line\&. This can be configured using the \fItrailer\&.<keyAlias>\&.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
91 trailer\&.sign\&.key "Signed\-off\-by: "
98 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\&.
100 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\&.
102 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)\&.
104 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:
110 key: This is a very long value, with spaces and
118 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\&.
123 Edit the files in place\&.
128 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\&.
131 \-\-trailer <key>[(=|:)<value>]
133 Specify a (<key>, <value>) pair that should be applied as a trailer to the inputs\&. See the description of this command\&.
136 \-\-where <placement>, \-\-no\-where
138 Specify where all new trailers will be added\&. A setting provided with
141 \fBtrailer\&.where\fR
143 \fBtrailer\&.<keyAlias>\&.where\fR
144 configuration variables and applies to all
146 options until the next occurrence of
149 \fI\-\-no\-where\fR\&. Upon encountering
150 \fI\-\-no\-where\fR, clear the effect of any previous use of
151 \fI\-\-where\fR, such that the relevant configuration variables are no longer overridden\&. Possible placements are
159 \-\-if\-exists <action>, \-\-no\-if\-exists
161 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
164 \fBtrailer\&.ifExists\fR
166 \fBtrailer\&.<keyAlias>\&.ifExists\fR
167 configuration variables and applies to all
169 options until the next occurrence of
172 \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
173 \fBaddIfDifferent\fR,
174 \fBaddIfDifferentNeighbor\fR,
181 \-\-if\-missing <action>, \-\-no\-if\-missing
183 Specify what action will be performed when there is no other trailer with the same <key> in the input\&. A setting provided with
184 \fI\-\-if\-missing\fR
186 \fBtrailer\&.ifMissing\fR
188 \fBtrailer\&.<keyAlias>\&.ifMissing\fR
189 configuration variables and applies to all
191 options until the next occurrence of
192 \fI\-\-if\-missing\fR
194 \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
202 Output only the trailers, not any other parts of the input\&.
207 Output only trailers that exist in the input; do not add any from the command\-line or by applying
209 configuration variables\&.
214 If a trailer has a value that runs over multiple lines (aka "folded"), reformat the value into a single line\&.
219 A convenience alias for
220 \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\&.
227 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
228 \fBgit format\-patch\fR)\&.
230 .SH "CONFIGURATION VARIABLES"
234 This option tells which characters are recognized as trailer separators\&. By default only
236 is recognized as a trailer separator, except that
238 is always accepted on the command line for compatibility with other git commands\&.
240 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\&.
242 For example, if the value for this option is "%=$", then only lines using the format
243 \fI<key><sep><value>\fR
244 with <sep> containing
249 and then spaces will be considered trailers\&. And
251 will be the default separator used, so by default trailers will appear like:
253 (one percent sign and one space will appear between the key and the value)\&.
258 This option tells where a new trailer will be added\&.
261 \fBend\fR, which is the default,
268 \fBend\fR, then each new trailer will appear at the end of the existing trailers\&.
271 \fBstart\fR, then each new trailer will appear at the start, instead of the end, of the existing trailers\&.
274 \fBafter\fR, then each new trailer will appear just after the last trailer with the same <key>\&.
277 \fBbefore\fR, then each new trailer will appear just before the first trailer with the same <key>\&.
282 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\&.
284 The valid values for this option are:
285 \fBaddIfDifferentNeighbor\fR
286 (this is the default),
287 \fBaddIfDifferent\fR,
294 \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\&.
297 \fBaddIfDifferent\fR, a new trailer will be added only if no trailer with the same (<key>, <value>) pair is already in the input\&.
300 \fBadd\fR, a new trailer will be added, even if some trailers with the same (<key>, <value>) pair are already in the input\&.
303 \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\&.
306 \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\&.
311 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\&.
313 The valid values for this option are:
315 (this is the default) and
319 \fBadd\fR, a new trailer will be added\&.
322 \fBdoNothing\fR, nothing will be done\&.
325 trailer\&.<keyAlias>\&.key
327 Defines a <keyAlias> for the <key>\&. The <keyAlias> must be a prefix (case does not matter) of the <key>\&. For example, in
328 \fBgit config trailer\&.ack\&.key "Acked\-by"\fR
329 the "Acked\-by" is the <key> and the "ack" is the <keyAlias>\&. This configuration allows the shorter
330 \fB\-\-trailer "ack:\&.\&.\&."\fR
331 invocation on the command line using the "ack" <keyAlias> instead of the longer
332 \fB\-\-trailer "Acked\-by:\&.\&.\&."\fR\&.
334 At the end of the <key>, a separator can appear and then some space characters\&. By default the only valid separator is
335 \fI:\fR, but this can be changed using the
336 \fBtrailer\&.separators\fR
339 If there is a separator in the key, then it overrides the default separator when adding the trailer\&.
342 trailer\&.<keyAlias>\&.where
344 This option takes the same values as the
345 \fItrailer\&.where\fR
346 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
349 trailer\&.<keyAlias>\&.ifexists
351 This option takes the same values as the
352 \fItrailer\&.ifexists\fR
353 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
356 trailer\&.<keyAlias>\&.ifmissing
358 This option takes the same values as the
359 \fItrailer\&.ifmissing\fR
360 configuration variable and it overrides what is specified by that option for trailers with the specified <keyAlias>\&.
363 trailer\&.<keyAlias>\&.command
365 Deprecated in favor of
366 \fItrailer\&.<keyAlias>\&.cmd\fR\&. This option behaves in the same way as
367 \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\&.
369 Note that $ARG in the user\(cqs command is only replaced once and that the original way of replacing $ARG is not safe\&.
372 \fItrailer\&.<keyAlias>\&.cmd\fR
374 \fItrailer\&.<keyAlias>\&.command\fR
375 are given for the same <keyAlias>,
376 \fItrailer\&.<keyAlias>\&.cmd\fR
378 \fItrailer\&.<keyAlias>\&.command\fR
382 trailer\&.<keyAlias>\&.cmd
384 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
385 \fI\-\-trailer <keyAlias>=<value>\fR
386 argument is specified to modify the <value> of the trailer that this option would produce\&.
388 When the specified command is first called to add a trailer with the specified <keyAlias>, the behavior is as if a special
389 \fI\-\-trailer <keyAlias>=<value>\fR
390 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\&.
393 \fI\-\-trailer <keyAlias>=<value>\fR
394 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
395 \fI\-\-trailer <keyAlias>=<value>\fR
411 \fISigned\-off\-by\fR
412 key, and then add two of these trailers to a commit message file:
418 $ git config trailer\&.sign\&.key "Signed\-off\-by"
423 $ git interpret\-trailers \-\-trailer \*(Aqsign: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(Aqsign: Bob <bob@example\&.com>\*(Aq <msg\&.txt
428 Signed\-off\-by: Alice <alice@example\&.com>
429 Signed\-off\-by: Bob <bob@example\&.com>
447 option to edit a commit message file in place:
458 Signed\-off\-by: Bob <bob@example\&.com>
459 $ git interpret\-trailers \-\-trailer \*(AqAcked\-by: Alice <alice@example\&.com>\*(Aq \-\-in\-place msg\&.txt
465 Signed\-off\-by: Bob <bob@example\&.com>
466 Acked\-by: Alice <alice@example\&.com>
482 Extract the last commit as a patch, and add a
492 $ git format\-patch \-1
494 $ git interpret\-trailers \-\-trailer \*(AqCc: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(AqReviewed\-by: Bob <bob@example\&.com>\*(Aq 0001\-foo\&.patch >0001\-bar\&.patch
512 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:
522 $ git config trailer\&.sign\&.key "Signed\-off\-by: "
523 $ git config trailer\&.sign\&.ifmissing add
524 $ git config trailer\&.sign\&.ifexists doNothing
525 $ git config trailer\&.sign\&.cmd \*(Aqecho "$(git config user\&.name) <$(git config user\&.email)>"\*(Aq
526 $ git interpret\-trailers \-\-trailer sign <msg1\&.txt
531 Signed\-off\-by: Bob <bob@example\&.com>
537 Signed\-off\-by: Alice <alice@example\&.com>
538 $ git interpret\-trailers \-\-trailer sign <msg2\&.txt
543 Signed\-off\-by: Alice <alice@example\&.com>
561 trailer with a key that contains a
563 and no space after this character, and show how it works:
569 $ git config trailer\&.separators ":#"
570 $ git config trailer\&.fix\&.key "Fix #"
571 $ echo "subject" | git interpret\-trailers \-\-trailer fix=42
592 trailer with a cmd use a script
593 \fBglog\-find\-author\fR
594 which search specified author identity from git log in git repository and show how it works:
600 $ cat ~/bin/glog\-find\-author
602 test \-n "$1" && git log \-\-author="$1" \-\-pretty="%an <%ae>" \-1 || true
607 $ git config trailer\&.help\&.key "Helped\-by: "
608 $ git config trailer\&.help\&.ifExists "addIfDifferentNeighbor"
609 $ git config trailer\&.help\&.cmd "~/bin/glog\-find\-author"
610 $ git interpret\-trailers \-\-trailer="help:Junio" \-\-trailer="help:Couder" <msg\&.txt
615 Helped\-by: Junio C Hamano <gitster@pobox\&.com>
616 Helped\-by: Christian Couder <christian\&.couder@gmail\&.com>
634 trailer with a cmd use a script
636 to grep last relevant commit from git log in the git repository and show how it works:
642 $ cat ~/bin/glog\-grep
644 test \-n "$1" && git log \-\-grep "$1" \-\-pretty=reference \-1 || true
649 $ git config trailer\&.ref\&.key "Reference\-to: "
650 $ git config trailer\&.ref\&.ifExists "replace"
651 $ git config trailer\&.ref\&.cmd "~/bin/glog\-grep"
652 $ git interpret\-trailers \-\-trailer="ref:Add copyright notices\&." <msg\&.txt
657 Reference\-to: 8bc9a0c769 (Add copyright notices\&., 2005\-04\-07)
675 trailer with a command to show the subject of a commit that is related, and show how it works:
687 $ cat ~/bin/glog\-ref
689 git log \-1 \-\-oneline \-\-format="%h (%s)" \-\-abbrev\-commit \-\-abbrev=14
690 $ git config trailer\&.see\&.key "See\-also: "
691 $ git config trailer\&.see\&.ifExists "replace"
692 $ git config trailer\&.see\&.ifMissing "doNothing"
693 $ git config trailer\&.see\&.cmd "glog\-ref"
694 $ git interpret\-trailers \-\-trailer=see <msg\&.txt
699 See\-also: fe3187489d69c4 (subject of related commit)
715 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
716 \fIgit interpret\-trailers\fR
717 to remove trailers with empty values and to add a
734 $ sed \-e \*(Aqs/ Z$/ /\*(Aq temp\&.txt > commit_template\&.txt
735 $ git config commit\&.template commit_template\&.txt
736 $ cat \&.git/hooks/commit\-msg
738 git interpret\-trailers \-\-trim\-empty \-\-trailer "git\-version: \e$(git describe)" "\e$1" > "\e$1\&.new"
739 mv "\e$1\&.new" "\e$1"
740 $ chmod +x \&.git/hooks/commit\-msg
749 \fBgit-commit\fR(1), \fBgit-format-patch\fR(1), \fBgit-config\fR(1)
752 Part of the \fBgit\fR(1) suite