]>
Commit | Line | Data |
---|---|---|
dfd66ddf CC |
1 | git-interpret-trailers(1) |
2 | ========================= | |
3 | ||
4 | NAME | |
5 | ---- | |
99e09daf | 6 | git-interpret-trailers - add or parse structured information in commit messages |
dfd66ddf CC |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
10 | [verse] | |
de613050 RD |
11 | 'git interpret-trailers' [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...] |
12 | 'git interpret-trailers' [<options>] [--parse] [<file>...] | |
dfd66ddf CC |
13 | |
14 | DESCRIPTION | |
15 | ----------- | |
99e09daf | 16 | Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail |
dfd66ddf CC |
17 | headers, at the end of the otherwise free-form part of a commit |
18 | message. | |
19 | ||
20 | This 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 | 24 | Otherwise, this command applies the arguments passed using the |
99e09daf JK |
25 | `--trailer` option, if any, to the commit message part of each input |
26 | file. The result is emitted on the standard output. | |
dfd66ddf CC |
27 | |
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. | |
32 | ||
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: | |
39 | ||
40 | ------------------------------------------------ | |
41 | token: value | |
42 | ------------------------------------------------ | |
43 | ||
44 | This means that the trimmed <token> and <value> will be separated by | |
45 | `': '` (one colon followed by one space). | |
46 | ||
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 | |
f745acb0 | 49 | after the commit message part of the output, and, if there is no line |
dfd66ddf CC |
50 | with only spaces at the end of the commit message part, one blank line |
51 | will be added before the new trailer. | |
52 | ||
53 | Existing trailers are extracted from the input message by looking for | |
760f1ad1 | 54 | a group of one or more lines that (i) is all trailers, or (ii) contains at |
df616b19 JT |
55 | least one Git-generated or user-configured trailer and consists of at |
56 | least 25% trailers. | |
14624506 | 57 | The group must be preceded by one or more empty (or whitespace-only) lines. |
dfd66ddf | 58 | The group must either be at the end of the message or be the last |
c188668e JK |
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 | |
1688c9a4 | 61 | part of the message. See also `--no-divider` below. |
dfd66ddf | 62 | |
c463a6b2 | 63 | When reading trailers, there can be whitespaces after the |
dfd66ddf | 64 | token, the separator and the value. There can also be whitespaces |
60ef86a1 JT |
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. | |
dfd66ddf CC |
67 | |
68 | Note that 'trailers' do not follow and are not intended to follow many | |
60ef86a1 JT |
69 | rules for RFC 822 headers. For example they do not follow |
70 | the encoding rules and probably many other rules. | |
dfd66ddf CC |
71 | |
72 | OPTIONS | |
73 | ------- | |
e1f89863 TK |
74 | --in-place:: |
75 | Edit the files in place. | |
76 | ||
dfd66ddf CC |
77 | --trim-empty:: |
78 | If the <value> part of any trailer contains only whitespace, | |
79 | the whole trailer will be removed from the resulting message. | |
a43eb67e | 80 | This applies to existing trailers as well as new trailers. |
dfd66ddf CC |
81 | |
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 | |
85 | command. | |
86 | ||
0ea5292e PB |
87 | --where <placement>:: |
88 | --no-where:: | |
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'. | |
93 | ||
94 | --if-exists <action>:: | |
95 | --no-if-exists:: | |
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'. | |
101 | ||
102 | --if-missing <action>:: | |
103 | --no-if-missing:: | |
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'. | |
109 | ||
56c493ed JK |
110 | --only-trailers:: |
111 | Output only the trailers, not any other parts of the input. | |
112 | ||
fdbdb64f JK |
113 | --only-input:: |
114 | Output only trailers that exist in the input; do not add any | |
115 | from the command-line or by following configured `trailer.*` | |
116 | rules. | |
117 | ||
00002396 JK |
118 | --unfold:: |
119 | Remove any whitespace-continuation in trailers, so that each | |
120 | trailer appears on a line by itself with its full content. | |
121 | ||
99e09daf JK |
122 | --parse:: |
123 | A convenience alias for `--only-trailers --only-input | |
124 | --unfold`. | |
125 | ||
1688c9a4 JK |
126 | --no-divider:: |
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`). | |
130 | ||
dfd66ddf CC |
131 | CONFIGURATION VARIABLES |
132 | ----------------------- | |
133 | ||
134 | trailer.separators:: | |
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. | |
139 | + | |
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 | |
142 | trailer. | |
143 | + | |
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). | |
150 | ||
151 | trailer.where:: | |
152 | This option tells where a new trailer will be added. | |
153 | + | |
154 | This can be `end`, which is the default, `start`, `after` or `before`. | |
155 | + | |
156 | If it is `end`, then each new trailer will appear at the end of the | |
157 | existing trailers. | |
158 | + | |
159 | If it is `start`, then each new trailer will appear at the start, | |
160 | instead of the end, of the existing trailers. | |
161 | + | |
162 | If it is `after`, then each new trailer will appear just after the | |
163 | last trailer with the same <token>. | |
164 | + | |
165 | If it is `before`, then each new trailer will appear just before the | |
166 | first trailer with the same <token>. | |
167 | ||
168 | trailer.ifexists:: | |
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. | |
172 | + | |
173 | The valid values for this option are: `addIfDifferentNeighbor` (this | |
b275da81 | 174 | is the default), `addIfDifferent`, `add`, `replace` or `doNothing`. |
dfd66ddf CC |
175 | + |
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. | |
179 | + | |
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. | |
182 | + | |
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. | |
185 | + | |
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 | |
189 | will be added. | |
190 | + | |
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. | |
193 | ||
194 | trailer.ifmissing:: | |
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. | |
198 | + | |
199 | The valid values for this option are: `add` (this is the default) and | |
200 | `doNothing`. | |
201 | + | |
202 | With `add`, a new trailer will be added. | |
203 | + | |
204 | With `doNothing`, nothing will be done. | |
205 | ||
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 | |
211 | variable. | |
212 | + | |
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. | |
215 | ||
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>. | |
220 | ||
c88bf543 PB |
221 | trailer.<token>.ifexists:: |
222 | This option takes the same values as the 'trailer.ifexists' | |
dfd66ddf CC |
223 | configuration variable and it overrides what is specified by |
224 | that option for trailers with the specified <token>. | |
225 | ||
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>. | |
230 | ||
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 | |
234 | specified <token>. | |
235 | + | |
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 | |
240 | off. | |
241 | + | |
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. | |
245 | + | |
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 | |
250 | the command. | |
251 | ||
252 | EXAMPLES | |
253 | -------- | |
254 | ||
255 | * Configure a 'sign' trailer with a 'Signed-off-by' key, and then | |
256 | add two of these trailers to a message: | |
257 | + | |
258 | ------------ | |
259 | $ git config trailer.sign.key "Signed-off-by" | |
260 | $ cat msg.txt | |
261 | subject | |
262 | ||
263 | message | |
264 | $ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' | |
265 | subject | |
266 | ||
267 | message | |
268 | ||
269 | Signed-off-by: Alice <alice@example.com> | |
270 | Signed-off-by: Bob <bob@example.com> | |
271 | ------------ | |
272 | ||
bcf9626a | 273 | * Use the `--in-place` option to edit a message file in place: |
e1f89863 TK |
274 | + |
275 | ------------ | |
276 | $ cat msg.txt | |
277 | subject | |
278 | ||
279 | message | |
280 | ||
281 | Signed-off-by: Bob <bob@example.com> | |
282 | $ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt | |
283 | $ cat msg.txt | |
284 | subject | |
285 | ||
286 | message | |
287 | ||
288 | Signed-off-by: Bob <bob@example.com> | |
289 | Acked-by: Alice <alice@example.com> | |
290 | ------------ | |
291 | ||
dfd66ddf CC |
292 | * Extract the last commit as a patch, and add a 'Cc' and a |
293 | 'Reviewed-by' trailer to it: | |
294 | + | |
295 | ------------ | |
296 | $ git format-patch -1 | |
297 | 0001-foo.patch | |
298 | $ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch | |
299 | ------------ | |
300 | ||
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: | |
304 | + | |
305 | ------------ | |
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 | |
311 | > EOF | |
312 | ||
313 | Signed-off-by: Bob <bob@example.com> | |
314 | $ git interpret-trailers <<EOF | |
315 | > Signed-off-by: Alice <alice@example.com> | |
316 | > EOF | |
317 | ||
318 | Signed-off-by: Alice <alice@example.com> | |
319 | ------------ | |
320 | ||
321 | * Configure a 'fix' trailer with a key that contains a '#' and no | |
322 | space after this character, and show how it works: | |
323 | + | |
324 | ------------ | |
325 | $ git config trailer.separators ":#" | |
326 | $ git config trailer.fix.key "Fix #" | |
327 | $ echo "subject" | git interpret-trailers --trailer fix=42 | |
328 | subject | |
329 | ||
330 | Fix #42 | |
331 | ------------ | |
332 | ||
333 | * Configure a 'see' trailer with a command to show the subject of a | |
334 | commit that is related, and show how it works: | |
335 | + | |
336 | ------------ | |
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 | |
342 | > subject | |
343 | > | |
344 | > message | |
345 | > | |
346 | > see: HEAD~2 | |
347 | > EOF | |
348 | subject | |
349 | ||
350 | message | |
351 | ||
352 | See-also: fe3187489d69c4 (subject of related commit) | |
353 | ------------ | |
354 | ||
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: | |
360 | + | |
361 | ------------ | |
362 | $ sed -e 's/ Z$/ /' >commit_template.txt <<EOF | |
363 | > ***subject*** | |
364 | > | |
365 | > ***message*** | |
366 | > | |
367 | > Fixes: Z | |
368 | > Cc: Z | |
369 | > Reviewed-by: Z | |
370 | > Signed-off-by: Z | |
371 | > EOF | |
372 | $ git config commit.template commit_template.txt | |
373 | $ cat >.git/hooks/commit-msg <<EOF | |
374 | > #!/bin/sh | |
375 | > git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new" | |
376 | > mv "\$1.new" "\$1" | |
377 | > EOF | |
378 | $ chmod +x .git/hooks/commit-msg | |
379 | ------------ | |
380 | ||
381 | SEE ALSO | |
382 | -------- | |
383 | linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1] | |
384 | ||
385 | GIT | |
386 | --- | |
387 | Part of the linkgit:git[1] suite |