]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-interpret-trailers.txt
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / Documentation / git-interpret-trailers.txt
CommitLineData
dfd66ddf
CC
1git-interpret-trailers(1)
2=========================
3
4NAME
5----
a34dca24 6git-interpret-trailers - Add or parse structured information in commit messages
dfd66ddf
CC
7
8SYNOPSIS
9--------
10[verse]
de613050
RD
11'git interpret-trailers' [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...]
12'git interpret-trailers' [<options>] [--parse] [<file>...]
dfd66ddf
CC
13
14DESCRIPTION
15-----------
99e09daf 16Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
dfd66ddf
CC
17headers, at the end of the otherwise free-form part of a commit
18message.
19
20This command reads some patches or commit messages from either the
99e09daf
JK
21<file> arguments or the standard input if no <file> is specified. If
22`--parse` is specified, the output consists of the parsed trailers.
23
5a0d0c03 24Otherwise, this command applies the arguments passed using the
99e09daf
JK
25`--trailer` option, if any, to the commit message part of each input
26file. The result is emitted on the standard output.
dfd66ddf
CC
27
28Some configuration variables control the way the `--trailer` arguments
29are applied to each commit message and the way any existing trailer in
30the commit message is changed. They also make it possible to
31automatically add some trailers.
32
33By default, a '<token>=<value>' or '<token>:<value>' argument given
34using `--trailer` will be appended after the existing trailers only if
35the last trailer has a different (<token>, <value>) pair (or if there
36is no existing trailer). The <token> and <value> parts will be trimmed
37to remove starting and trailing whitespace, and the resulting trimmed
38<token> and <value> will appear in the message like this:
39
40------------------------------------------------
41token: value
42------------------------------------------------
43
44This means that the trimmed <token> and <value> will be separated by
45`': '` (one colon followed by one space).
46
47By default the new trailer will appear at the end of all the existing
48trailers. If there is no existing trailer, the new trailer will appear
f745acb0 49after the commit message part of the output, and, if there is no line
dfd66ddf
CC
50with only spaces at the end of the commit message part, one blank line
51will be added before the new trailer.
52
53Existing trailers are extracted from the input message by looking for
760f1ad1 54a group of one or more lines that (i) is all trailers, or (ii) contains at
df616b19
JT
55least one Git-generated or user-configured trailer and consists of at
56least 25% trailers.
14624506 57The group must be preceded by one or more empty (or whitespace-only) lines.
dfd66ddf 58The group must either be at the end of the message or be the last
c188668e
JK
59non-whitespace lines before a line that starts with '---' (followed by a
60space or the end of the line). Such three minus signs start the patch
1688c9a4 61part of the message. See also `--no-divider` below.
dfd66ddf 62
b46dd172
CC
63When reading trailers, there can be no whitespace before or inside the
64token, but any number of regular space and tab characters are allowed
65between the token and the separator. There can be whitespaces before,
66inside or after the value. The value may be split over multiple lines
67with each subsequent line starting with at least one whitespace, like
68the "folding" in RFC 822.
dfd66ddf
CC
69
70Note that 'trailers' do not follow and are not intended to follow many
60ef86a1
JT
71rules for RFC 822 headers. For example they do not follow
72the encoding rules and probably many other rules.
dfd66ddf
CC
73
74OPTIONS
75-------
e1f89863
TK
76--in-place::
77 Edit the files in place.
78
dfd66ddf
CC
79--trim-empty::
80 If the <value> part of any trailer contains only whitespace,
81 the whole trailer will be removed from the resulting message.
a43eb67e 82 This applies to existing trailers as well as new trailers.
dfd66ddf
CC
83
84--trailer <token>[(=|:)<value>]::
85 Specify a (<token>, <value>) pair that should be applied as a
86 trailer to the input messages. See the description of this
87 command.
88
0ea5292e
PB
89--where <placement>::
90--no-where::
91 Specify where all new trailers will be added. A setting
92 provided with '--where' overrides all configuration variables
93 and applies to all '--trailer' options until the next occurrence of
1e83b9bf
SB
94 '--where' or '--no-where'. Possible values are `after`, `before`,
95 `end` or `start`.
0ea5292e
PB
96
97--if-exists <action>::
98--no-if-exists::
99 Specify what action will be performed when there is already at
100 least one trailer with the same <token> in the message. A setting
101 provided with '--if-exists' overrides all configuration variables
102 and applies to all '--trailer' options until the next occurrence of
1e83b9bf
SB
103 '--if-exists' or '--no-if-exists'. Possible actions are `addIfDifferent`,
104 `addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
0ea5292e
PB
105
106--if-missing <action>::
107--no-if-missing::
108 Specify what action will be performed when there is no other
109 trailer with the same <token> in the message. A setting
110 provided with '--if-missing' overrides all configuration variables
111 and applies to all '--trailer' options until the next occurrence of
1e83b9bf
SB
112 '--if-missing' or '--no-if-missing'. Possible actions are `doNothing`
113 or `add`.
0ea5292e 114
56c493ed
JK
115--only-trailers::
116 Output only the trailers, not any other parts of the input.
117
fdbdb64f
JK
118--only-input::
119 Output only trailers that exist in the input; do not add any
120 from the command-line or by following configured `trailer.*`
121 rules.
122
00002396
JK
123--unfold::
124 Remove any whitespace-continuation in trailers, so that each
125 trailer appears on a line by itself with its full content.
126
99e09daf
JK
127--parse::
128 A convenience alias for `--only-trailers --only-input
129 --unfold`.
130
1688c9a4
JK
131--no-divider::
132 Do not treat `---` as the end of the commit message. Use this
133 when you know your input contains just the commit message itself
134 (and not an email or the output of `git format-patch`).
135
dfd66ddf
CC
136CONFIGURATION VARIABLES
137-----------------------
138
139trailer.separators::
140 This option tells which characters are recognized as trailer
141 separators. By default only ':' is recognized as a trailer
142 separator, except that '=' is always accepted on the command
143 line for compatibility with other git commands.
144+
145The first character given by this option will be the default character
146used when another separator is not specified in the config for this
147trailer.
148+
149For example, if the value for this option is "%=$", then only lines
150using the format '<token><sep><value>' with <sep> containing '%', '='
151or '$' and then spaces will be considered trailers. And '%' will be
152the default separator used, so by default trailers will appear like:
153'<token>% <value>' (one percent sign and one space will appear between
154the token and the value).
155
156trailer.where::
157 This option tells where a new trailer will be added.
158+
159This can be `end`, which is the default, `start`, `after` or `before`.
160+
161If it is `end`, then each new trailer will appear at the end of the
162existing trailers.
163+
164If it is `start`, then each new trailer will appear at the start,
165instead of the end, of the existing trailers.
166+
167If it is `after`, then each new trailer will appear just after the
168last trailer with the same <token>.
169+
170If it is `before`, then each new trailer will appear just before the
171first trailer with the same <token>.
172
173trailer.ifexists::
174 This option makes it possible to choose what action will be
175 performed when there is already at least one trailer with the
176 same <token> in the message.
177+
178The valid values for this option are: `addIfDifferentNeighbor` (this
b275da81 179is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
dfd66ddf
CC
180+
181With `addIfDifferentNeighbor`, a new trailer will be added only if no
182trailer with the same (<token>, <value>) pair is above or below the line
183where the new trailer will be added.
184+
185With `addIfDifferent`, a new trailer will be added only if no trailer
186with the same (<token>, <value>) pair is already in the message.
187+
188With `add`, a new trailer will be added, even if some trailers with
189the same (<token>, <value>) pair are already in the message.
190+
191With `replace`, an existing trailer with the same <token> will be
192deleted and the new trailer will be added. The deleted trailer will be
193the closest one (with the same <token>) to the place where the new one
194will be added.
195+
196With `doNothing`, nothing will be done; that is no new trailer will be
197added if there is already one with the same <token> in the message.
198
199trailer.ifmissing::
200 This option makes it possible to choose what action will be
201 performed when there is not yet any trailer with the same
202 <token> in the message.
203+
204The valid values for this option are: `add` (this is the default) and
205`doNothing`.
206+
207With `add`, a new trailer will be added.
208+
209With `doNothing`, nothing will be done.
210
211trailer.<token>.key::
212 This `key` will be used instead of <token> in the trailer. At
213 the end of this key, a separator can appear and then some
214 space characters. By default the only valid separator is ':',
215 but this can be changed using the `trailer.separators` config
216 variable.
217+
218If there is a separator, then the key will be used instead of both the
219<token> and the default separator when adding the trailer.
220
221trailer.<token>.where::
222 This option takes the same values as the 'trailer.where'
223 configuration variable and it overrides what is specified by
224 that option for trailers with the specified <token>.
225
c88bf543
PB
226trailer.<token>.ifexists::
227 This option takes the same values as the 'trailer.ifexists'
dfd66ddf
CC
228 configuration variable and it overrides what is specified by
229 that option for trailers with the specified <token>.
230
231trailer.<token>.ifmissing::
232 This option takes the same values as the 'trailer.ifmissing'
233 configuration variable and it overrides what is specified by
234 that option for trailers with the specified <token>.
235
236trailer.<token>.command::
c364b7ef
ZH
237 This option behaves in the same way as 'trailer.<token>.cmd', except
238 that it doesn't pass anything as argument to the specified command.
239 Instead the first occurrence of substring $ARG is replaced by the
240 value that would be passed as argument.
241+
242The 'trailer.<token>.command' option has been deprecated in favor of
243'trailer.<token>.cmd' due to the fact that $ARG in the user's command is
244only replaced once and that the original way of replacing $ARG is not safe.
245+
246When both 'trailer.<token>.cmd' and 'trailer.<token>.command' are given
247for the same <token>, 'trailer.<token>.cmd' is used and
248'trailer.<token>.command' is ignored.
249
250trailer.<token>.cmd::
57dcb657
ZH
251 This option can be used to specify a shell command that will be called:
252 once to automatically add a trailer with the specified <token>, and then
253 each time a '--trailer <token>=<value>' argument to modify the <value> of
254 the trailer that this option would produce.
dfd66ddf 255+
57dcb657
ZH
256When the specified command is first called to add a trailer
257with the specified <token>, the behavior is as if a special
258'--trailer <token>=<value>' argument was added at the beginning
259of the "git interpret-trailers" command, where <value>
260is taken to be the standard output of the command with any
261leading and trailing whitespace trimmed off.
dfd66ddf 262+
57dcb657
ZH
263If some '--trailer <token>=<value>' arguments are also passed
264on the command line, the command is called again once for each
265of these arguments with the same <token>. And the <value> part
c364b7ef
ZH
266of these arguments, if any, will be passed to the command as its
267first argument. This way the command can produce a <value> computed
268from the <value> passed in the '--trailer <token>=<value>' argument.
dfd66ddf
CC
269
270EXAMPLES
271--------
272
273* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
274 add two of these trailers to a message:
275+
276------------
277$ git config trailer.sign.key "Signed-off-by"
278$ cat msg.txt
279subject
280
281message
282$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
283subject
284
285message
286
287Signed-off-by: Alice <alice@example.com>
288Signed-off-by: Bob <bob@example.com>
289------------
290
bcf9626a 291* Use the `--in-place` option to edit a message file in place:
e1f89863
TK
292+
293------------
294$ cat msg.txt
295subject
296
297message
298
299Signed-off-by: Bob <bob@example.com>
300$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
301$ cat msg.txt
302subject
303
304message
305
306Signed-off-by: Bob <bob@example.com>
307Acked-by: Alice <alice@example.com>
308------------
309
dfd66ddf
CC
310* Extract the last commit as a patch, and add a 'Cc' and a
311 'Reviewed-by' trailer to it:
312+
313------------
314$ git format-patch -1
3150001-foo.patch
316$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
317------------
318
319* Configure a 'sign' trailer with a command to automatically add a
320 'Signed-off-by: ' with the author information only if there is no
321 'Signed-off-by: ' already, and show how it works:
322+
323------------
324$ git config trailer.sign.key "Signed-off-by: "
325$ git config trailer.sign.ifmissing add
326$ git config trailer.sign.ifexists doNothing
327$ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
328$ git interpret-trailers <<EOF
329> EOF
330
331Signed-off-by: Bob <bob@example.com>
332$ git interpret-trailers <<EOF
333> Signed-off-by: Alice <alice@example.com>
334> EOF
335
336Signed-off-by: Alice <alice@example.com>
337------------
338
339* Configure a 'fix' trailer with a key that contains a '#' and no
340 space after this character, and show how it works:
341+
342------------
343$ git config trailer.separators ":#"
344$ git config trailer.fix.key "Fix #"
345$ echo "subject" | git interpret-trailers --trailer fix=42
346subject
347
348Fix #42
349------------
350
c364b7ef
ZH
351* Configure a 'help' trailer with a cmd use a script `glog-find-author`
352 which search specified author identity from git log in git repository
353 and show how it works:
354+
355------------
356$ cat ~/bin/glog-find-author
357#!/bin/sh
358test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
359$ git config trailer.help.key "Helped-by: "
360$ git config trailer.help.ifExists "addIfDifferentNeighbor"
361$ git config trailer.help.cmd "~/bin/glog-find-author"
362$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <<EOF
363> subject
364>
365> message
366>
367> EOF
368subject
369
370message
371
372Helped-by: Junio C Hamano <gitster@pobox.com>
373Helped-by: Christian Couder <christian.couder@gmail.com>
374------------
375
376* Configure a 'ref' trailer with a cmd use a script `glog-grep`
377 to grep last relevant commit from git log in the git repository
378 and show how it works:
379+
380------------
381$ cat ~/bin/glog-grep
382#!/bin/sh
383test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
384$ git config trailer.ref.key "Reference-to: "
385$ git config trailer.ref.ifExists "replace"
386$ git config trailer.ref.cmd "~/bin/glog-grep"
387$ git interpret-trailers --trailer="ref:Add copyright notices." <<EOF
388> subject
389>
390> message
391>
392> EOF
393subject
394
395message
396
397Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
398------------
399
dfd66ddf
CC
400* Configure a 'see' trailer with a command to show the subject of a
401 commit that is related, and show how it works:
402+
403------------
404$ git config trailer.see.key "See-also: "
405$ git config trailer.see.ifExists "replace"
406$ git config trailer.see.ifMissing "doNothing"
407$ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
408$ git interpret-trailers <<EOF
409> subject
410>
411> message
412>
413> see: HEAD~2
414> EOF
415subject
416
417message
418
419See-also: fe3187489d69c4 (subject of related commit)
420------------
421
422* Configure a commit template with some trailers with empty values
423 (using sed to show and keep the trailing spaces at the end of the
424 trailers), then configure a commit-msg hook that uses
425 'git interpret-trailers' to remove trailers with empty values and
426 to add a 'git-version' trailer:
427+
428------------
429$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
430> ***subject***
431>
432> ***message***
433>
434> Fixes: Z
435> Cc: Z
436> Reviewed-by: Z
437> Signed-off-by: Z
438> EOF
439$ git config commit.template commit_template.txt
440$ cat >.git/hooks/commit-msg <<EOF
441> #!/bin/sh
442> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
443> mv "\$1.new" "\$1"
444> EOF
445$ chmod +x .git/hooks/commit-msg
446------------
447
448SEE ALSO
449--------
450linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
451
452GIT
453---
454Part of the linkgit:git[1] suite