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/>
10 .TH "GIT\-INTERPRET\-TRAILERS" "1" "2023\-06\-01" "Git 2\&.41\&.0" "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 <token>[(=|:)<value>])\&...]
37 [\-\-parse] [<file>\&...]
42 Help parsing or adding \fItrailers\fR lines, that look similar to RFC 822 e\-mail headers, at the end of the otherwise free\-form part of a commit message\&.
44 This command reads some patches or 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\&.
46 Otherwise, this command applies the arguments passed using the \fB\-\-trailer\fR option, if any, to the commit message part of each input file\&. The result is emitted on the standard output\&.
48 Some configuration variables control the way the \fB\-\-trailer\fR arguments are applied to each commit message and the way any existing trailer in the commit message is changed\&. They also make it possible to automatically add some trailers\&.
50 By default, a \fI<token>=<value>\fR or \fI<token>:<value>\fR argument given using \fB\-\-trailer\fR will be appended after the existing trailers only if the last trailer has a different (<token>, <value>) pair (or if there is no existing trailer)\&. The <token> and <value> parts will be trimmed to remove starting and trailing whitespace, and the resulting trimmed <token> and <value> will appear in the message like this:
63 This means that the trimmed <token> and <value> will be separated by \fB\*(Aq: \*(Aq\fR (one colon followed by one space)\&.
65 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 after the commit message part of the output, and, if there is no line with only spaces at the end of the commit message part, one blank line will be added before the new trailer\&.
67 Existing trailers are extracted from the input message 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 message 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)\&. Such three minus signs start the patch part of the message\&. See also \fB\-\-no\-divider\fR below\&.
69 When reading trailers, there can be no whitespace before or inside the token, but any number of regular space and tab characters are allowed between the token 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\&.
71 Note that \fItrailers\fR do not follow and are not intended to follow many rules for RFC 822 headers\&. For example they do not follow the encoding rules and probably many other rules\&.
76 Edit the files in place\&.
81 If the <value> part of any trailer contains only whitespace, the whole trailer will be removed from the resulting message\&. This applies to existing trailers as well as new trailers\&.
84 \-\-trailer <token>[(=|:)<value>]
86 Specify a (<token>, <value>) pair that should be applied as a trailer to the input messages\&. See the description of this command\&.
89 \-\-where <placement>, \-\-no\-where
91 Specify where all new trailers will be added\&. A setting provided with
93 overrides all configuration variables and applies to all
95 options until the next occurrence of
98 \fI\-\-no\-where\fR\&. Possible values are
106 \-\-if\-exists <action>, \-\-no\-if\-exists
108 Specify what action will be performed when there is already at least one trailer with the same <token> in the message\&. A setting provided with
110 overrides all configuration variables and applies to all
112 options until the next occurrence of
115 \fI\-\-no\-if\-exists\fR\&. Possible actions are
116 \fBaddIfDifferent\fR,
117 \fBaddIfDifferentNeighbor\fR,
124 \-\-if\-missing <action>, \-\-no\-if\-missing
126 Specify what action will be performed when there is no other trailer with the same <token> in the message\&. A setting provided with
127 \fI\-\-if\-missing\fR
128 overrides all configuration variables and applies to all
130 options until the next occurrence of
131 \fI\-\-if\-missing\fR
133 \fI\-\-no\-if\-missing\fR\&. Possible actions are
141 Output only the trailers, not any other parts of the input\&.
146 Output only trailers that exist in the input; do not add any from the command\-line or by following configured
153 Remove any whitespace\-continuation in trailers, so that each trailer appears on a line by itself with its full content\&.
158 A convenience alias for
159 \fB\-\-only\-trailers \-\-only\-input \-\-unfold\fR\&.
166 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
167 \fBgit format\-patch\fR)\&.
169 .SH "CONFIGURATION VARIABLES"
173 This option tells which characters are recognized as trailer separators\&. By default only
175 is recognized as a trailer separator, except that
177 is always accepted on the command line for compatibility with other git commands\&.
179 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\&.
181 For example, if the value for this option is "%=$", then only lines using the format
182 \fI<token><sep><value>\fR
183 with <sep> containing
188 and then spaces will be considered trailers\&. And
190 will be the default separator used, so by default trailers will appear like:
191 \fI<token>% <value>\fR
192 (one percent sign and one space will appear between the token and the value)\&.
197 This option tells where a new trailer will be added\&.
200 \fBend\fR, which is the default,
207 \fBend\fR, then each new trailer will appear at the end of the existing trailers\&.
210 \fBstart\fR, then each new trailer will appear at the start, instead of the end, of the existing trailers\&.
213 \fBafter\fR, then each new trailer will appear just after the last trailer with the same <token>\&.
216 \fBbefore\fR, then each new trailer will appear just before the first trailer with the same <token>\&.
221 This option makes it possible to choose what action will be performed when there is already at least one trailer with the same <token> in the message\&.
223 The valid values for this option are:
224 \fBaddIfDifferentNeighbor\fR
225 (this is the default),
226 \fBaddIfDifferent\fR,
233 \fBaddIfDifferentNeighbor\fR, a new trailer will be added only if no trailer with the same (<token>, <value>) pair is above or below the line where the new trailer will be added\&.
236 \fBaddIfDifferent\fR, a new trailer will be added only if no trailer with the same (<token>, <value>) pair is already in the message\&.
239 \fBadd\fR, a new trailer will be added, even if some trailers with the same (<token>, <value>) pair are already in the message\&.
242 \fBreplace\fR, an existing trailer with the same <token> will be deleted and the new trailer will be added\&. The deleted trailer will be the closest one (with the same <token>) to the place where the new one will be added\&.
245 \fBdoNothing\fR, nothing will be done; that is no new trailer will be added if there is already one with the same <token> in the message\&.
250 This option makes it possible to choose what action will be performed when there is not yet any trailer with the same <token> in the message\&.
252 The valid values for this option are:
254 (this is the default) and
258 \fBadd\fR, a new trailer will be added\&.
261 \fBdoNothing\fR, nothing will be done\&.
264 trailer\&.<token>\&.key
268 will be used instead of <token> in the trailer\&. At the end of this key, a separator can appear and then some space characters\&. By default the only valid separator is
269 \fI:\fR, but this can be changed using the
270 \fBtrailer\&.separators\fR
273 If there is a separator, then the key will be used instead of both the <token> and the default separator when adding the trailer\&.
276 trailer\&.<token>\&.where
278 This option takes the same values as the
279 \fItrailer\&.where\fR
280 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
283 trailer\&.<token>\&.ifexists
285 This option takes the same values as the
286 \fItrailer\&.ifexists\fR
287 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
290 trailer\&.<token>\&.ifmissing
292 This option takes the same values as the
293 \fItrailer\&.ifmissing\fR
294 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
297 trailer\&.<token>\&.command
299 This option behaves in the same way as
300 \fItrailer\&.<token>\&.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\&.
303 \fItrailer\&.<token>\&.command\fR
304 option has been deprecated in favor of
305 \fItrailer\&.<token>\&.cmd\fR
306 due to the fact that $ARG in the user\(cqs command is only replaced once and that the original way of replacing $ARG is not safe\&.
309 \fItrailer\&.<token>\&.cmd\fR
311 \fItrailer\&.<token>\&.command\fR
312 are given for the same <token>,
313 \fItrailer\&.<token>\&.cmd\fR
315 \fItrailer\&.<token>\&.command\fR
319 trailer\&.<token>\&.cmd
321 This option can be used to specify a shell command that will be called: once to automatically add a trailer with the specified <token>, and then each time a
322 \fI\-\-trailer <token>=<value>\fR
323 argument to modify the <value> of the trailer that this option would produce\&.
325 When the specified command is first called to add a trailer with the specified <token>, the behavior is as if a special
326 \fI\-\-trailer <token>=<value>\fR
327 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\&.
330 \fI\-\-trailer <token>=<value>\fR
331 arguments are also passed on the command line, the command is called again once for each of these arguments with the same <token>\&. 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
332 \fI\-\-trailer <token>=<value>\fR
348 \fISigned\-off\-by\fR
349 key, and then add two of these trailers to a message:
355 $ git config trailer\&.sign\&.key "Signed\-off\-by"
360 $ git interpret\-trailers \-\-trailer \*(Aqsign: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(Aqsign: Bob <bob@example\&.com>\*(Aq <msg\&.txt
365 Signed\-off\-by: Alice <alice@example\&.com>
366 Signed\-off\-by: Bob <bob@example\&.com>
384 option to edit a message file in place:
395 Signed\-off\-by: Bob <bob@example\&.com>
396 $ git interpret\-trailers \-\-trailer \*(AqAcked\-by: Alice <alice@example\&.com>\*(Aq \-\-in\-place msg\&.txt
402 Signed\-off\-by: Bob <bob@example\&.com>
403 Acked\-by: Alice <alice@example\&.com>
419 Extract the last commit as a patch, and add a
429 $ git format\-patch \-1
431 $ git interpret\-trailers \-\-trailer \*(AqCc: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(AqReviewed\-by: Bob <bob@example\&.com>\*(Aq 0001\-foo\&.patch >0001\-bar\&.patch
449 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:
459 $ git config trailer\&.sign\&.key "Signed\-off\-by: "
460 $ git config trailer\&.sign\&.ifmissing add
461 $ git config trailer\&.sign\&.ifexists doNothing
462 $ git config trailer\&.sign\&.cmd \*(Aqecho "$(git config user\&.name) <$(git config user\&.email)>"\*(Aq
463 $ git interpret\-trailers \-\-trailer sign <msg1\&.txt
468 Signed\-off\-by: Bob <bob@example\&.com>
474 Signed\-off\-by: Alice <alice@example\&.com>
475 $ git interpret\-trailers \-\-trailer sign <msg2\&.txt
480 Signed\-off\-by: Alice <alice@example\&.com>
498 trailer with a key that contains a
500 and no space after this character, and show how it works:
506 $ git config trailer\&.separators ":#"
507 $ git config trailer\&.fix\&.key "Fix #"
508 $ echo "subject" | git interpret\-trailers \-\-trailer fix=42
529 trailer with a cmd use a script
530 \fBglog\-find\-author\fR
531 which search specified author identity from git log in git repository and show how it works:
537 $ cat ~/bin/glog\-find\-author
539 test \-n "$1" && git log \-\-author="$1" \-\-pretty="%an <%ae>" \-1 || true
544 $ git config trailer\&.help\&.key "Helped\-by: "
545 $ git config trailer\&.help\&.ifExists "addIfDifferentNeighbor"
546 $ git config trailer\&.help\&.cmd "~/bin/glog\-find\-author"
547 $ git interpret\-trailers \-\-trailer="help:Junio" \-\-trailer="help:Couder" <msg\&.txt
552 Helped\-by: Junio C Hamano <gitster@pobox\&.com>
553 Helped\-by: Christian Couder <christian\&.couder@gmail\&.com>
571 trailer with a cmd use a script
573 to grep last relevant commit from git log in the git repository and show how it works:
579 $ cat ~/bin/glog\-grep
581 test \-n "$1" && git log \-\-grep "$1" \-\-pretty=reference \-1 || true
586 $ git config trailer\&.ref\&.key "Reference\-to: "
587 $ git config trailer\&.ref\&.ifExists "replace"
588 $ git config trailer\&.ref\&.cmd "~/bin/glog\-grep"
589 $ git interpret\-trailers \-\-trailer="ref:Add copyright notices\&." <msg\&.txt
594 Reference\-to: 8bc9a0c769 (Add copyright notices\&., 2005\-04\-07)
612 trailer with a command to show the subject of a commit that is related, and show how it works:
624 $ cat ~/bin/glog\-ref
626 git log \-1 \-\-oneline \-\-format="%h (%s)" \-\-abbrev\-commit \-\-abbrev=14
627 $ git config trailer\&.see\&.key "See\-also: "
628 $ git config trailer\&.see\&.ifExists "replace"
629 $ git config trailer\&.see\&.ifMissing "doNothing"
630 $ git config trailer\&.see\&.cmd "glog\-ref"
631 $ git interpret\-trailers \-\-trailer=see <msg\&.txt
636 See\-also: fe3187489d69c4 (subject of related commit)
652 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
653 \fIgit interpret\-trailers\fR
654 to remove trailers with empty values and to add a
671 $ sed \-e \*(Aqs/ Z$/ /\*(Aq temp\&.txt > commit_template\&.txt
672 $ git config commit\&.template commit_template\&.txt
673 $ cat \&.git/hooks/commit\-msg
675 git interpret\-trailers \-\-trim\-empty \-\-trailer "git\-version: \e$(git describe)" "\e$1" > "\e$1\&.new"
676 mv "\e$1\&.new" "\e$1"
677 $ chmod +x \&.git/hooks/commit\-msg
686 \fBgit-commit\fR(1), \fBgit-format-patch\fR(1), \fBgit-config\fR(1)
689 Part of the \fBgit\fR(1) suite