1 git-interpret-trailers(1)
2 =========================
6 git-interpret-trailers - add or parse structured information in commit messages
11 'git interpret-trailers' [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...]
12 'git interpret-trailers' [<options>] [--parse] [<file>...]
16 Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
17 headers, at the end of the otherwise free-form part of a commit
20 This command reads some patches or commit messages from either the
21 <file> arguments or the standard input if no <file> is specified. If
22 `--parse` is specified, the output consists of the parsed trailers.
24 Otherwise, this command applies the arguments passed using the
25 `--trailer` option, if any, to the commit message part of each input
26 file. The result is emitted on the standard output.
28 Some configuration variables control the way the `--trailer` arguments
29 are applied to each commit message and the way any existing trailer in
30 the commit message is changed. They also make it possible to
31 automatically add some trailers.
33 By default, a '<token>=<value>' or '<token>:<value>' argument given
34 using `--trailer` will be appended after the existing trailers only if
35 the last trailer has a different (<token>, <value>) pair (or if there
36 is no existing trailer). The <token> and <value> parts will be trimmed
37 to remove starting and trailing whitespace, and the resulting trimmed
38 <token> and <value> will appear in the message like this:
40 ------------------------------------------------
42 ------------------------------------------------
44 This means that the trimmed <token> and <value> will be separated by
45 `': '` (one colon followed by one space).
47 By default the new trailer will appear at the end of all the existing
48 trailers. If there is no existing trailer, the new trailer will appear
49 after the commit message part of the output, and, if there is no line
50 with only spaces at the end of the commit message part, one blank line
51 will be added before the new trailer.
53 Existing trailers are extracted from the input message by looking for
54 a group of one or more lines that (i) is all trailers, or (ii) contains at
55 least one Git-generated or user-configured trailer and consists of at
57 The group must be preceded by one or more empty (or whitespace-only) lines.
58 The group must either be at the end of the message or be the last
59 non-whitespace lines before a line that starts with '---' (followed by a
60 space or the end of the line). Such three minus signs start the patch
61 part of the message. See also `--no-divider` below.
63 When reading trailers, there can be whitespaces after the
64 token, the separator and the value. There can also be whitespaces
65 inside the token and the value. The value may be split over multiple lines with
66 each subsequent line starting with whitespace, like the "folding" in RFC 822.
68 Note that 'trailers' do not follow and are not intended to follow many
69 rules for RFC 822 headers. For example they do not follow
70 the encoding rules and probably many other rules.
75 Edit the files in place.
78 If the <value> part of any trailer contains only whitespace,
79 the whole trailer will be removed from the resulting message.
80 This applies to existing trailers as well as new trailers.
82 --trailer <token>[(=|:)<value>]::
83 Specify a (<token>, <value>) pair that should be applied as a
84 trailer to the input messages. See the description of this
89 Specify where all new trailers will be added. A setting
90 provided with '--where' overrides all configuration variables
91 and applies to all '--trailer' options until the next occurrence of
92 '--where' or '--no-where'.
94 --if-exists <action>::
96 Specify what action will be performed when there is already at
97 least one trailer with the same <token> in the message. A setting
98 provided with '--if-exists' overrides all configuration variables
99 and applies to all '--trailer' options until the next occurrence of
100 '--if-exists' or '--no-if-exists'.
102 --if-missing <action>::
104 Specify what action will be performed when there is no other
105 trailer with the same <token> in the message. A setting
106 provided with '--if-missing' overrides all configuration variables
107 and applies to all '--trailer' options until the next occurrence of
108 '--if-missing' or '--no-if-missing'.
111 Output only the trailers, not any other parts of the input.
114 Output only trailers that exist in the input; do not add any
115 from the command-line or by following configured `trailer.*`
119 Remove any whitespace-continuation in trailers, so that each
120 trailer appears on a line by itself with its full content.
123 A convenience alias for `--only-trailers --only-input
127 Do not treat `---` as the end of the commit message. Use this
128 when you know your input contains just the commit message itself
129 (and not an email or the output of `git format-patch`).
131 CONFIGURATION VARIABLES
132 -----------------------
135 This option tells which characters are recognized as trailer
136 separators. By default only ':' is recognized as a trailer
137 separator, except that '=' is always accepted on the command
138 line for compatibility with other git commands.
140 The first character given by this option will be the default character
141 used when another separator is not specified in the config for this
144 For example, if the value for this option is "%=$", then only lines
145 using the format '<token><sep><value>' with <sep> containing '%', '='
146 or '$' and then spaces will be considered trailers. And '%' will be
147 the default separator used, so by default trailers will appear like:
148 '<token>% <value>' (one percent sign and one space will appear between
149 the token and the value).
152 This option tells where a new trailer will be added.
154 This can be `end`, which is the default, `start`, `after` or `before`.
156 If it is `end`, then each new trailer will appear at the end of the
159 If it is `start`, then each new trailer will appear at the start,
160 instead of the end, of the existing trailers.
162 If it is `after`, then each new trailer will appear just after the
163 last trailer with the same <token>.
165 If it is `before`, then each new trailer will appear just before the
166 first trailer with the same <token>.
169 This option makes it possible to choose what action will be
170 performed when there is already at least one trailer with the
171 same <token> in the message.
173 The valid values for this option are: `addIfDifferentNeighbor` (this
174 is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
176 With `addIfDifferentNeighbor`, a new trailer will be added only if no
177 trailer with the same (<token>, <value>) pair is above or below the line
178 where the new trailer will be added.
180 With `addIfDifferent`, a new trailer will be added only if no trailer
181 with the same (<token>, <value>) pair is already in the message.
183 With `add`, a new trailer will be added, even if some trailers with
184 the same (<token>, <value>) pair are already in the message.
186 With `replace`, an existing trailer with the same <token> will be
187 deleted and the new trailer will be added. The deleted trailer will be
188 the closest one (with the same <token>) to the place where the new one
191 With `doNothing`, nothing will be done; that is no new trailer will be
192 added if there is already one with the same <token> in the message.
195 This option makes it possible to choose what action will be
196 performed when there is not yet any trailer with the same
197 <token> in the message.
199 The valid values for this option are: `add` (this is the default) and
202 With `add`, a new trailer will be added.
204 With `doNothing`, nothing will be done.
206 trailer.<token>.key::
207 This `key` will be used instead of <token> in the trailer. At
208 the end of this key, a separator can appear and then some
209 space characters. By default the only valid separator is ':',
210 but this can be changed using the `trailer.separators` config
213 If there is a separator, then the key will be used instead of both the
214 <token> and the default separator when adding the trailer.
216 trailer.<token>.where::
217 This option takes the same values as the 'trailer.where'
218 configuration variable and it overrides what is specified by
219 that option for trailers with the specified <token>.
221 trailer.<token>.ifexists::
222 This option takes the same values as the 'trailer.ifexists'
223 configuration variable and it overrides what is specified by
224 that option for trailers with the specified <token>.
226 trailer.<token>.ifmissing::
227 This option takes the same values as the 'trailer.ifmissing'
228 configuration variable and it overrides what is specified by
229 that option for trailers with the specified <token>.
231 trailer.<token>.command::
232 This option can be used to specify a shell command that will
233 be called to automatically add or modify a trailer with the
236 When this option is specified, the behavior is as if a special
237 '<token>=<value>' argument were added at the beginning of the command
238 line, where <value> is taken to be the standard output of the
239 specified command with any leading and trailing whitespace trimmed
242 If the command contains the `$ARG` string, this string will be
243 replaced with the <value> part of an existing trailer with the same
244 <token>, if any, before the command is launched.
246 If some '<token>=<value>' arguments are also passed on the command
247 line, when a 'trailer.<token>.command' is configured, the command will
248 also be executed for each of these arguments. And the <value> part of
249 these arguments, if any, will be used to replace the `$ARG` string in
255 * Configure a 'sign' trailer with a 'Signed-off-by' key, and then
256 add two of these trailers to a message:
259 $ git config trailer.sign.key "Signed-off-by"
264 $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
269 Signed-off-by: Alice <alice@example.com>
270 Signed-off-by: Bob <bob@example.com>
273 * Use the `--in-place` option to edit a message file in place:
281 Signed-off-by: Bob <bob@example.com>
282 $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
288 Signed-off-by: Bob <bob@example.com>
289 Acked-by: Alice <alice@example.com>
292 * Extract the last commit as a patch, and add a 'Cc' and a
293 'Reviewed-by' trailer to it:
296 $ git format-patch -1
298 $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
301 * Configure a 'sign' trailer with a command to automatically add a
302 'Signed-off-by: ' with the author information only if there is no
303 'Signed-off-by: ' already, and show how it works:
306 $ git config trailer.sign.key "Signed-off-by: "
307 $ git config trailer.sign.ifmissing add
308 $ git config trailer.sign.ifexists doNothing
309 $ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
310 $ git interpret-trailers <<EOF
313 Signed-off-by: Bob <bob@example.com>
314 $ git interpret-trailers <<EOF
315 > Signed-off-by: Alice <alice@example.com>
318 Signed-off-by: Alice <alice@example.com>
321 * Configure a 'fix' trailer with a key that contains a '#' and no
322 space after this character, and show how it works:
325 $ git config trailer.separators ":#"
326 $ git config trailer.fix.key "Fix #"
327 $ echo "subject" | git interpret-trailers --trailer fix=42
333 * Configure a 'see' trailer with a command to show the subject of a
334 commit that is related, and show how it works:
337 $ git config trailer.see.key "See-also: "
338 $ git config trailer.see.ifExists "replace"
339 $ git config trailer.see.ifMissing "doNothing"
340 $ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
341 $ git interpret-trailers <<EOF
352 See-also: fe3187489d69c4 (subject of related commit)
355 * Configure a commit template with some trailers with empty values
356 (using sed to show and keep the trailing spaces at the end of the
357 trailers), then configure a commit-msg hook that uses
358 'git interpret-trailers' to remove trailers with empty values and
359 to add a 'git-version' trailer:
362 $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
372 $ git config commit.template commit_template.txt
373 $ cat >.git/hooks/commit-msg <<EOF
375 > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
378 $ chmod +x .git/hooks/commit-msg
383 linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
387 Part of the linkgit:git[1] suite