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.47.0.336.g6ea2d9d271
10 .TH "GIT\-INTERPRET\-TRAILERS" "1" "2024-11-25" "Git 2\&.47\&.0\&.336\&.g6ea2d9" "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 \*(Aq: \*(Aq (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=\fR"sign: \fBfoo\fR" on the command line instead of \fB\-\-trailer=\fR"Signed\-off\-by: \fBfoo\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\&.\fR\fI<keyAlias>\fR\fB\&.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\&.\fR\fI<keyAlias>\fR\fB\&.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\&.\fR\fI<keyAlias>\fR\fB\&.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
203 \fBtrailer\&.\fR* configuration variables\&.
208 If a trailer has a value that runs over multiple lines (aka "folded"), reformat the value into a single line\&.
213 A convenience alias for
214 \fB\-\-only\-trailers\fR
215 \fB\-\-only\-input\fR
216 \fB\-\-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\&.
223 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
225 \fBformat\-patch\fR)\&.
227 .SH "CONFIGURATION VARIABLES"
231 This option tells which characters are recognized as trailer separators\&. By default only
233 is recognized as a trailer separator, except that
235 is always accepted on the command line for compatibility with other git commands\&.
237 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\&.
239 For example, if the value for this option is "%=$", then only lines using the format
240 \fI<key><sep><value>\fR
241 with <sep> containing
246 and then spaces will be considered trailers\&. And
248 will be the default separator used, so by default trailers will appear like:
250 (one percent sign and one space will appear between the key and the value)\&.
255 This option tells where a new trailer will be added\&.
258 \fBend\fR, which is the default,
265 \fBend\fR, then each new trailer will appear at the end of the existing trailers\&.
268 \fBstart\fR, then each new trailer will appear at the start, instead of the end, of the existing trailers\&.
271 \fBafter\fR, then each new trailer will appear just after the last trailer with the same <key>\&.
274 \fBbefore\fR, then each new trailer will appear just before the first trailer with the same <key>\&.
279 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\&.
281 The valid values for this option are:
282 \fBaddIfDifferentNeighbor\fR
283 (this is the default),
284 \fBaddIfDifferent\fR,
291 \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\&.
294 \fBaddIfDifferent\fR, a new trailer will be added only if no trailer with the same (<key>, <value>) pair is already in the input\&.
297 \fBadd\fR, a new trailer will be added, even if some trailers with the same (<key>, <value>) pair are already in the input\&.
300 \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\&.
303 \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\&.
308 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\&.
310 The valid values for this option are:
312 (this is the default) and
316 \fBadd\fR, a new trailer will be added\&.
319 \fBdoNothing\fR, nothing will be done\&.
322 trailer\&.<keyAlias>\&.key
324 Defines a <keyAlias> for the <key>\&. The <keyAlias> must be a prefix (case does not matter) of the <key>\&. For example, in
327 \fBtrailer\&.ack\&.key\fR
328 "Acked\-by" the "Acked\-by" is the <key> and the "ack" is the <keyAlias>\&. This configuration allows the shorter
330 "ack:\fB\&.\&.\&.\fR" invocation on the command line using the "ack" <keyAlias> instead of the longer
332 "Acked\-by:\fB\&.\&.\&.\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>
446 option to edit a commit message file in place:
457 Signed\-off\-by: Bob <bob@example\&.com>
458 $ git interpret\-trailers \-\-trailer \*(AqAcked\-by: Alice <alice@example\&.com>\*(Aq \-\-in\-place msg\&.txt
464 Signed\-off\-by: Bob <bob@example\&.com>
465 Acked\-by: Alice <alice@example\&.com>
480 Extract the last commit as a patch, and add a
490 $ git format\-patch \-1
492 $ git interpret\-trailers \-\-trailer \*(AqCc: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(AqReviewed\-by: Bob <bob@example\&.com>\*(Aq 0001\-foo\&.patch >0001\-bar\&.patch
509 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:
519 $ git config trailer\&.sign\&.key "Signed\-off\-by: "
520 $ git config trailer\&.sign\&.ifmissing add
521 $ git config trailer\&.sign\&.ifexists doNothing
522 $ git config trailer\&.sign\&.cmd \*(Aqecho "$(git config user\&.name) <$(git config user\&.email)>"\*(Aq
523 $ git interpret\-trailers \-\-trailer sign <msg1\&.txt
528 Signed\-off\-by: Bob <bob@example\&.com>
534 Signed\-off\-by: Alice <alice@example\&.com>
535 $ git interpret\-trailers \-\-trailer sign <msg2\&.txt
540 Signed\-off\-by: Alice <alice@example\&.com>
557 trailer with a key that contains a
559 and no space after this character, and show how it works:
565 $ git config trailer\&.separators ":#"
566 $ git config trailer\&.fix\&.key "Fix #"
567 $ echo "subject" | git interpret\-trailers \-\-trailer fix=42
587 trailer with a cmd use a script
588 \fBglog\-find\-author\fR
589 which search specified author identity from git log in git repository and show how it works:
595 $ cat ~/bin/glog\-find\-author
597 test \-n "$1" && git log \-\-author="$1" \-\-pretty="%an <%ae>" \-1 || true
602 $ git config trailer\&.help\&.key "Helped\-by: "
603 $ git config trailer\&.help\&.ifExists "addIfDifferentNeighbor"
604 $ git config trailer\&.help\&.cmd "~/bin/glog\-find\-author"
605 $ git interpret\-trailers \-\-trailer="help:Junio" \-\-trailer="help:Couder" <msg\&.txt
610 Helped\-by: Junio C Hamano <gitster@pobox\&.com>
611 Helped\-by: Christian Couder <christian\&.couder@gmail\&.com>
628 trailer with a cmd use a script
630 to grep last relevant commit from git log in the git repository and show how it works:
636 $ cat ~/bin/glog\-grep
638 test \-n "$1" && git log \-\-grep "$1" \-\-pretty=reference \-1 || true
643 $ git config trailer\&.ref\&.key "Reference\-to: "
644 $ git config trailer\&.ref\&.ifExists "replace"
645 $ git config trailer\&.ref\&.cmd "~/bin/glog\-grep"
646 $ git interpret\-trailers \-\-trailer="ref:Add copyright notices\&." <msg\&.txt
651 Reference\-to: 8bc9a0c769 (Add copyright notices\&., 2005\-04\-07)
668 trailer with a command to show the subject of a commit that is related, and show how it works:
680 $ cat ~/bin/glog\-ref
682 git log \-1 \-\-oneline \-\-format="%h (%s)" \-\-abbrev\-commit \-\-abbrev=14
683 $ git config trailer\&.see\&.key "See\-also: "
684 $ git config trailer\&.see\&.ifExists "replace"
685 $ git config trailer\&.see\&.ifMissing "doNothing"
686 $ git config trailer\&.see\&.cmd "glog\-ref"
687 $ git interpret\-trailers \-\-trailer=see <msg\&.txt
692 See\-also: fe3187489d69c4 (subject of related commit)
707 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
708 \fIgit interpret\-trailers\fR
709 to remove trailers with empty values and to add a
726 $ sed \-e \*(Aqs/ Z$/ /\*(Aq temp\&.txt > commit_template\&.txt
727 $ git config commit\&.template commit_template\&.txt
728 $ cat \&.git/hooks/commit\-msg
730 git interpret\-trailers \-\-trim\-empty \-\-trailer "git\-version: \e$(git describe)" "\e$1" > "\e$1\&.new"
731 mv "\e$1\&.new" "\e$1"
732 $ chmod +x \&.git/hooks/commit\-msg
740 \fBgit-commit\fR(1), \fBgit-format-patch\fR(1), \fBgit-config\fR(1)
743 Part of the \fBgit\fR(1) suite