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