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.42.0.176.gd6c51973e4
10 .TH "GIT\-INTERPRET\-TRAILERS" "1" "2023\-09\-13" "Git 2\&.42\&.0\&.176\&.gd6c519" "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 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\&. Otherwise, this command applies the arguments passed using the \fB\-\-trailer\fR option, if any, 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<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 output like this:
81 This means that the trimmed <token> and <value> will be separated by \fB\*(Aq: \*(Aq\fR (one colon followed by one space)\&. For convenience, the <token> can be a shortened string key (e\&.g\&., "sign") instead of the full string which should appear before the separator on the output (e\&.g\&., "Signed\-off\-by")\&. This can be configured using the \fItrailer\&.<token>\&.key\fR configuration variable\&.
83 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\&.
85 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)\&.
87 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\&. Example:
93 token: This is a very long value, with spaces and
101 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\&.
106 Edit the files in place\&.
111 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\&.
114 \-\-trailer <token>[(=|:)<value>]
116 Specify a (<token>, <value>) pair that should be applied as a trailer to the inputs\&. See the description of this command\&.
119 \-\-where <placement>, \-\-no\-where
121 Specify where all new trailers will be added\&. A setting provided with
123 overrides all configuration variables and applies to all
125 options until the next occurrence of
128 \fI\-\-no\-where\fR\&. Possible values are
136 \-\-if\-exists <action>, \-\-no\-if\-exists
138 Specify what action will be performed when there is already at least one trailer with the same <token> in the input\&. A setting provided with
140 overrides all configuration variables and applies to all
142 options until the next occurrence of
145 \fI\-\-no\-if\-exists\fR\&. Possible actions are
146 \fBaddIfDifferent\fR,
147 \fBaddIfDifferentNeighbor\fR,
154 \-\-if\-missing <action>, \-\-no\-if\-missing
156 Specify what action will be performed when there is no other trailer with the same <token> in the input\&. A setting provided with
157 \fI\-\-if\-missing\fR
158 overrides all configuration variables and applies to all
160 options until the next occurrence of
161 \fI\-\-if\-missing\fR
163 \fI\-\-no\-if\-missing\fR\&. Possible actions are
171 Output only the trailers, not any other parts of the input\&.
176 Output only trailers that exist in the input; do not add any from the command\-line or by following configured
183 Remove any whitespace\-continuation in trailers, so that each trailer appears on a line by itself with its full content\&.
188 A convenience alias for
189 \fB\-\-only\-trailers \-\-only\-input \-\-unfold\fR\&.
196 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
197 \fBgit format\-patch\fR)\&.
199 .SH "CONFIGURATION VARIABLES"
203 This option tells which characters are recognized as trailer separators\&. By default only
205 is recognized as a trailer separator, except that
207 is always accepted on the command line for compatibility with other git commands\&.
209 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\&.
211 For example, if the value for this option is "%=$", then only lines using the format
212 \fI<token><sep><value>\fR
213 with <sep> containing
218 and then spaces will be considered trailers\&. And
220 will be the default separator used, so by default trailers will appear like:
221 \fI<token>% <value>\fR
222 (one percent sign and one space will appear between the token and the value)\&.
227 This option tells where a new trailer will be added\&.
230 \fBend\fR, which is the default,
237 \fBend\fR, then each new trailer will appear at the end of the existing trailers\&.
240 \fBstart\fR, then each new trailer will appear at the start, instead of the end, of the existing trailers\&.
243 \fBafter\fR, then each new trailer will appear just after the last trailer with the same <token>\&.
246 \fBbefore\fR, then each new trailer will appear just before the first trailer with the same <token>\&.
251 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 input\&.
253 The valid values for this option are:
254 \fBaddIfDifferentNeighbor\fR
255 (this is the default),
256 \fBaddIfDifferent\fR,
263 \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\&.
266 \fBaddIfDifferent\fR, a new trailer will be added only if no trailer with the same (<token>, <value>) pair is already in the input\&.
269 \fBadd\fR, a new trailer will be added, even if some trailers with the same (<token>, <value>) pair are already in the input\&.
272 \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\&.
275 \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 input\&.
280 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 input\&.
282 The valid values for this option are:
284 (this is the default) and
288 \fBadd\fR, a new trailer will be added\&.
291 \fBdoNothing\fR, nothing will be done\&.
294 trailer\&.<token>\&.key
298 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
299 \fI:\fR, but this can be changed using the
300 \fBtrailer\&.separators\fR
303 If there is a separator, then the key will be used instead of both the <token> and the default separator when adding the trailer\&.
306 trailer\&.<token>\&.where
308 This option takes the same values as the
309 \fItrailer\&.where\fR
310 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
313 trailer\&.<token>\&.ifexists
315 This option takes the same values as the
316 \fItrailer\&.ifexists\fR
317 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
320 trailer\&.<token>\&.ifmissing
322 This option takes the same values as the
323 \fItrailer\&.ifmissing\fR
324 configuration variable and it overrides what is specified by that option for trailers with the specified <token>\&.
327 trailer\&.<token>\&.command
329 Deprecated in favor of
330 \fItrailer\&.<token>\&.cmd\fR\&. This option behaves in the same way as
331 \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\&.
333 Note that $ARG in the user\(cqs command is only replaced once and that the original way of replacing $ARG is not safe\&.
336 \fItrailer\&.<token>\&.cmd\fR
338 \fItrailer\&.<token>\&.command\fR
339 are given for the same <token>,
340 \fItrailer\&.<token>\&.cmd\fR
342 \fItrailer\&.<token>\&.command\fR
346 trailer\&.<token>\&.cmd
348 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 called each time a
349 \fI\-\-trailer <token>=<value>\fR
350 argument is specified to modify the <value> of the trailer that this option would produce\&.
352 When the specified command is first called to add a trailer with the specified <token>, the behavior is as if a special
353 \fI\-\-trailer <token>=<value>\fR
354 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\&.
357 \fI\-\-trailer <token>=<value>\fR
358 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
359 \fI\-\-trailer <token>=<value>\fR
375 \fISigned\-off\-by\fR
376 key, and then add two of these trailers to a commit message file:
382 $ git config trailer\&.sign\&.key "Signed\-off\-by"
387 $ git interpret\-trailers \-\-trailer \*(Aqsign: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(Aqsign: Bob <bob@example\&.com>\*(Aq <msg\&.txt
392 Signed\-off\-by: Alice <alice@example\&.com>
393 Signed\-off\-by: Bob <bob@example\&.com>
411 option to edit a commit message file in place:
422 Signed\-off\-by: Bob <bob@example\&.com>
423 $ git interpret\-trailers \-\-trailer \*(AqAcked\-by: Alice <alice@example\&.com>\*(Aq \-\-in\-place msg\&.txt
429 Signed\-off\-by: Bob <bob@example\&.com>
430 Acked\-by: Alice <alice@example\&.com>
446 Extract the last commit as a patch, and add a
456 $ git format\-patch \-1
458 $ git interpret\-trailers \-\-trailer \*(AqCc: Alice <alice@example\&.com>\*(Aq \-\-trailer \*(AqReviewed\-by: Bob <bob@example\&.com>\*(Aq 0001\-foo\&.patch >0001\-bar\&.patch
476 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:
486 $ git config trailer\&.sign\&.key "Signed\-off\-by: "
487 $ git config trailer\&.sign\&.ifmissing add
488 $ git config trailer\&.sign\&.ifexists doNothing
489 $ git config trailer\&.sign\&.cmd \*(Aqecho "$(git config user\&.name) <$(git config user\&.email)>"\*(Aq
490 $ git interpret\-trailers \-\-trailer sign <msg1\&.txt
495 Signed\-off\-by: Bob <bob@example\&.com>
501 Signed\-off\-by: Alice <alice@example\&.com>
502 $ git interpret\-trailers \-\-trailer sign <msg2\&.txt
507 Signed\-off\-by: Alice <alice@example\&.com>
525 trailer with a key that contains a
527 and no space after this character, and show how it works:
533 $ git config trailer\&.separators ":#"
534 $ git config trailer\&.fix\&.key "Fix #"
535 $ echo "subject" | git interpret\-trailers \-\-trailer fix=42
556 trailer with a cmd use a script
557 \fBglog\-find\-author\fR
558 which search specified author identity from git log in git repository and show how it works:
564 $ cat ~/bin/glog\-find\-author
566 test \-n "$1" && git log \-\-author="$1" \-\-pretty="%an <%ae>" \-1 || true
571 $ git config trailer\&.help\&.key "Helped\-by: "
572 $ git config trailer\&.help\&.ifExists "addIfDifferentNeighbor"
573 $ git config trailer\&.help\&.cmd "~/bin/glog\-find\-author"
574 $ git interpret\-trailers \-\-trailer="help:Junio" \-\-trailer="help:Couder" <msg\&.txt
579 Helped\-by: Junio C Hamano <gitster@pobox\&.com>
580 Helped\-by: Christian Couder <christian\&.couder@gmail\&.com>
598 trailer with a cmd use a script
600 to grep last relevant commit from git log in the git repository and show how it works:
606 $ cat ~/bin/glog\-grep
608 test \-n "$1" && git log \-\-grep "$1" \-\-pretty=reference \-1 || true
613 $ git config trailer\&.ref\&.key "Reference\-to: "
614 $ git config trailer\&.ref\&.ifExists "replace"
615 $ git config trailer\&.ref\&.cmd "~/bin/glog\-grep"
616 $ git interpret\-trailers \-\-trailer="ref:Add copyright notices\&." <msg\&.txt
621 Reference\-to: 8bc9a0c769 (Add copyright notices\&., 2005\-04\-07)
639 trailer with a command to show the subject of a commit that is related, and show how it works:
651 $ cat ~/bin/glog\-ref
653 git log \-1 \-\-oneline \-\-format="%h (%s)" \-\-abbrev\-commit \-\-abbrev=14
654 $ git config trailer\&.see\&.key "See\-also: "
655 $ git config trailer\&.see\&.ifExists "replace"
656 $ git config trailer\&.see\&.ifMissing "doNothing"
657 $ git config trailer\&.see\&.cmd "glog\-ref"
658 $ git interpret\-trailers \-\-trailer=see <msg\&.txt
663 See\-also: fe3187489d69c4 (subject of related commit)
679 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
680 \fIgit interpret\-trailers\fR
681 to remove trailers with empty values and to add a
698 $ sed \-e \*(Aqs/ Z$/ /\*(Aq temp\&.txt > commit_template\&.txt
699 $ git config commit\&.template commit_template\&.txt
700 $ cat \&.git/hooks/commit\-msg
702 git interpret\-trailers \-\-trim\-empty \-\-trailer "git\-version: \e$(git describe)" "\e$1" > "\e$1\&.new"
703 mv "\e$1\&.new" "\e$1"
704 $ chmod +x \&.git/hooks/commit\-msg
713 \fBgit-commit\fR(1), \fBgit-format-patch\fR(1), \fBgit-config\fR(1)
716 Part of the \fBgit\fR(1) suite