blob: d9dfb75fef525f4a8379e0c52a78e2642e843858 [file] [log] [blame]
Junio C Hamano4c43d652014-10-20 21:14:291git-interpret-trailers(1)
2=========================
3
4NAME
5----
Junio C Hamanob5513772019-04-22 03:38:396git-interpret-trailers - Add or parse structured information in commit messages
Junio C Hamano4c43d652014-10-20 21:14:297
8SYNOPSIS
9--------
10[verse]
Junio C Hamanocf9c7732022-10-28 18:56:0611'git interpret-trailers' [--in-place] [--trim-empty]
Junio C Hamano8842ccc2024-03-26 00:26:2312[(--trailer (<key>|<key-alias>)[(=|:)<value>])...]
Junio C Hamanocf9c7732022-10-28 18:56:0613[--parse] [<file>...]
Junio C Hamano4c43d652014-10-20 21:14:2914
15DESCRIPTION
16-----------
Junio C Hamano9469c132023-06-23 20:26:2917Add or parse 'trailer' lines that look similar to RFC 822 e-mail
Junio C Hamano4c43d652014-10-20 21:14:2918headers, at the end of the otherwise free-form part of a commit
Junio C Hamano9469c132023-06-23 20:26:2919message. For example, in the following commit message
Junio C Hamano4c43d652014-10-20 21:14:2920
Junio C Hamano9469c132023-06-23 20:26:2921------------------------------------------------
22subject
Junio C Hamanofb1fdf12017-08-27 06:14:5923
Junio C Hamano9469c132023-06-23 20:26:2924Lorem ipsum dolor sit amet, consectetur adipiscing elit.
25
26Signed-off-by: Alice <alice@example.com>
27Signed-off-by: Bob <bob@example.com>
28------------------------------------------------
29
30the last two lines starting with "Signed-off-by" are trailers.
31
32This command reads commit messages from either the
33<file> arguments or the standard input if no <file> is specified.
Junio C Hamanoc05b7642023-10-13 22:27:2634If `--parse` is specified, the output consists of the parsed trailers
35coming from the input, without influencing them with any command line
36options or configuration variables.
37
38Otherwise, this command applies `trailer.*` configuration variables
39(which could potentially add new trailers, as well as reposition them),
40as well as any command line arguments that can override configuration
41variables (such as `--trailer=...` which could also add new trailers),
42to each input file. The result is emitted on the standard output.
Junio C Hamano9469c132023-06-23 20:26:2943
44This command can also operate on the output of linkgit:git-format-patch[1],
45which is more elaborate than a plain commit message. Namely, such output
46includes a commit message (as above), a "---" divider line, and a patch part.
47For these inputs, the divider and patch parts are not modified by
48this command and are emitted as is on the output, unless
49`--no-divider` is specified.
Junio C Hamano4c43d652014-10-20 21:14:2950
51Some configuration variables control the way the `--trailer` arguments
Junio C Hamano9469c132023-06-23 20:26:2952are applied to each input and the way any existing trailer in
53the input is changed. They also make it possible to
Junio C Hamano4c43d652014-10-20 21:14:2954automatically add some trailers.
55
Junio C Hamanoc05b7642023-10-13 22:27:2656By default, a '<key>=<value>' or '<key>:<value>' argument given
Junio C Hamano4c43d652014-10-20 21:14:2957using `--trailer` will be appended after the existing trailers only if
Junio C Hamanoc05b7642023-10-13 22:27:2658the last trailer has a different (<key>, <value>) pair (or if there
59is no existing trailer). The <key> and <value> parts will be trimmed
Junio C Hamano4c43d652014-10-20 21:14:2960to remove starting and trailing whitespace, and the resulting trimmed
Junio C Hamanoc05b7642023-10-13 22:27:2661<key> and <value> will appear in the output like this:
Junio C Hamano4c43d652014-10-20 21:14:2962
63------------------------------------------------
Junio C Hamanoc05b7642023-10-13 22:27:2664key: value
Junio C Hamano4c43d652014-10-20 21:14:2965------------------------------------------------
66
Junio C Hamanoc05b7642023-10-13 22:27:2667This means that the trimmed <key> and <value> will be separated by
68`': '` (one colon followed by one space).
69
Junio C Hamano8842ccc2024-03-26 00:26:2370For convenience, a <key-alias> can be configured to make using `--trailer`
Junio C Hamanoc05b7642023-10-13 22:27:2671shorter to type on the command line. This can be configured using the
Junio C Hamano8842ccc2024-03-26 00:26:2372'trailer.<key-alias>.key' configuration variable. The <keyAlias> must be a prefix
Junio C Hamanoc05b7642023-10-13 22:27:2673of the full <key> string, although case sensitivity does not matter. For
74example, if you have
75
76------------------------------------------------
77trailer.sign.key "Signed-off-by: "
78------------------------------------------------
79
80in your configuration, you only need to specify `--trailer="sign: foo"`
81on the command line instead of `--trailer="Signed-off-by: foo"`.
Junio C Hamano4c43d652014-10-20 21:14:2982
83By default the new trailer will appear at the end of all the existing
84trailers. If there is no existing trailer, the new trailer will appear
Junio C Hamano9469c132023-06-23 20:26:2985at the end of the input. A blank line will be added before the new
86trailer if there isn't one already.
Junio C Hamano4c43d652014-10-20 21:14:2987
Junio C Hamano9469c132023-06-23 20:26:2988Existing trailers are extracted from the input by looking for
Junio C Hamano615c3b32018-02-28 23:40:2789a group of one or more lines that (i) is all trailers, or (ii) contains at
Junio C Hamanoca785492016-11-23 20:12:3090least one Git-generated or user-configured trailer and consists of at
91least 25% trailers.
Junio C Hamanof2f28b12016-10-31 21:41:5892The group must be preceded by one or more empty (or whitespace-only) lines.
Junio C Hamano9469c132023-06-23 20:26:2993The group must either be at the end of the input or be the last
Junio C Hamano980e61e2018-09-17 22:45:5294non-whitespace lines before a line that starts with '---' (followed by a
Junio C Hamano9469c132023-06-23 20:26:2995space or the end of the line).
Junio C Hamano4c43d652014-10-20 21:14:2996
Junio C Hamano80d588f2022-09-09 22:08:2997When reading trailers, there can be no whitespace before or inside the
Junio C Hamanoc05b7642023-10-13 22:27:2698<key>, but any number of regular space and tab characters are allowed
99between the <key> and the separator. There can be whitespaces before,
Junio C Hamano9469c132023-06-23 20:26:29100inside or after the <value>. The <value> may be split over multiple lines
Junio C Hamano80d588f2022-09-09 22:08:29101with each subsequent line starting with at least one whitespace, like
Junio C Hamano9469c132023-06-23 20:26:29102the "folding" in RFC 822. Example:
Junio C Hamano4c43d652014-10-20 21:14:29103
Junio C Hamano9469c132023-06-23 20:26:29104------------------------------------------------
Junio C Hamanoc05b7642023-10-13 22:27:26105key: This is a very long value, with spaces and
Junio C Hamano9469c132023-06-23 20:26:29106 newlines in it.
107------------------------------------------------
108
109Note that trailers do not follow (nor are they intended to follow) many of the
110rules for RFC 822 headers. For example they do not follow the encoding rule.
Junio C Hamano4c43d652014-10-20 21:14:29111
112OPTIONS
113-------
Junio C Hamano7d098642016-01-30 00:05:21114--in-place::
115Edit the files in place.
116
Junio C Hamano4c43d652014-10-20 21:14:29117--trim-empty::
118If the <value> part of any trailer contains only whitespace,
Junio C Hamano9469c132023-06-23 20:26:29119the whole trailer will be removed from the output.
Junio C Hamanob0a1e832015-10-15 23:08:31120This applies to existing trailers as well as new trailers.
Junio C Hamano4c43d652014-10-20 21:14:29121
Junio C Hamanoc05b7642023-10-13 22:27:26122--trailer <key>[(=|:)<value>]::
123Specify a (<key>, <value>) pair that should be applied as a
Junio C Hamano9469c132023-06-23 20:26:29124trailer to the inputs. See the description of this
Junio C Hamano4c43d652014-10-20 21:14:29125command.
126
Junio C Hamanofb1fdf12017-08-27 06:14:59127--where <placement>::
128--no-where::
129Specify where all new trailers will be added. A setting
Junio C Hamanoc05b7642023-10-13 22:27:26130provided with '--where' overrides the `trailer.where` and any
131applicable `trailer.<keyAlias>.where` configuration variables
Junio C Hamanofb1fdf12017-08-27 06:14:59132and applies to all '--trailer' options until the next occurrence of
Junio C Hamanoc05b7642023-10-13 22:27:26133'--where' or '--no-where'. Upon encountering '--no-where', clear the
134effect of any previous use of '--where', such that the relevant configuration
135variables are no longer overridden. Possible placements are `after`,
136`before`, `end` or `start`.
Junio C Hamanofb1fdf12017-08-27 06:14:59137
138--if-exists <action>::
139--no-if-exists::
140Specify what action will be performed when there is already at
Junio C Hamanoc05b7642023-10-13 22:27:26141least one trailer with the same <key> in the input. A setting
142provided with '--if-exists' overrides the `trailer.ifExists` and any
143applicable `trailer.<keyAlias>.ifExists` configuration variables
Junio C Hamanofb1fdf12017-08-27 06:14:59144and applies to all '--trailer' options until the next occurrence of
Junio C Hamanoc05b7642023-10-13 22:27:26145'--if-exists' or '--no-if-exists'. Upon encountering '--no-if-exists, clear the
146effect of any previous use of '--if-exists, such that the relevant configuration
147variables are no longer overridden. Possible actions are `addIfDifferent`,
Junio C Hamanobfd91f42018-08-17 22:21:16148`addIfDifferentNeighbor`, `add`, `replace` and `doNothing`.
Junio C Hamanofb1fdf12017-08-27 06:14:59149
150--if-missing <action>::
151--no-if-missing::
152Specify what action will be performed when there is no other
Junio C Hamanoc05b7642023-10-13 22:27:26153trailer with the same <key> in the input. A setting
154provided with '--if-missing' overrides the `trailer.ifMissing` and any
155applicable `trailer.<keyAlias>.ifMissing` configuration variables
Junio C Hamanofb1fdf12017-08-27 06:14:59156and applies to all '--trailer' options until the next occurrence of
Junio C Hamanoc05b7642023-10-13 22:27:26157'--if-missing' or '--no-if-missing'. Upon encountering '--no-if-missing,
158clear the effect of any previous use of '--if-missing, such that the relevant
159configuration variables are no longer overridden. Possible actions are `doNothing`
Junio C Hamanobfd91f42018-08-17 22:21:16160or `add`.
Junio C Hamanofb1fdf12017-08-27 06:14:59161
162--only-trailers::
163Output only the trailers, not any other parts of the input.
164
165--only-input::
166Output only trailers that exist in the input; do not add any
Junio C Hamanoc05b7642023-10-13 22:27:26167from the command-line or by applying `trailer.*` configuration
168variables.
Junio C Hamanofb1fdf12017-08-27 06:14:59169
170--unfold::
Junio C Hamanoc05b7642023-10-13 22:27:26171If a trailer has a value that runs over multiple lines (aka "folded"),
172reformat the value into a single line.
Junio C Hamanofb1fdf12017-08-27 06:14:59173
174--parse::
175A convenience alias for `--only-trailers --only-input
Junio C Hamanoc05b7642023-10-13 22:27:26176--unfold`. This makes it easier to only see the trailers coming from the
177input without influencing them with any command line options or
178configuration variables, while also making the output machine-friendly with
179--unfold.
Junio C Hamanofb1fdf12017-08-27 06:14:59180
Junio C Hamano980e61e2018-09-17 22:45:52181--no-divider::
182Do not treat `---` as the end of the commit message. Use this
183when you know your input contains just the commit message itself
184(and not an email or the output of `git format-patch`).
185
Junio C Hamano4c43d652014-10-20 21:14:29186CONFIGURATION VARIABLES
187-----------------------
188
189trailer.separators::
190This option tells which characters are recognized as trailer
191separators. By default only ':' is recognized as a trailer
192separator, except that '=' is always accepted on the command
193line for compatibility with other git commands.
194+
195The first character given by this option will be the default character
196used when another separator is not specified in the config for this
197trailer.
198+
199For example, if the value for this option is "%=$", then only lines
Junio C Hamanoc05b7642023-10-13 22:27:26200using the format '<key><sep><value>' with <sep> containing '%', '='
Junio C Hamano4c43d652014-10-20 21:14:29201or '$' and then spaces will be considered trailers. And '%' will be
202the default separator used, so by default trailers will appear like:
Junio C Hamanoc05b7642023-10-13 22:27:26203'<key>% <value>' (one percent sign and one space will appear between
204the key and the value).
Junio C Hamano4c43d652014-10-20 21:14:29205
206trailer.where::
207This option tells where a new trailer will be added.
208+
209This can be `end`, which is the default, `start`, `after` or `before`.
210+
211If it is `end`, then each new trailer will appear at the end of the
212existing trailers.
213+
214If it is `start`, then each new trailer will appear at the start,
215instead of the end, of the existing trailers.
216+
217If it is `after`, then each new trailer will appear just after the
Junio C Hamanoc05b7642023-10-13 22:27:26218last trailer with the same <key>.
Junio C Hamano4c43d652014-10-20 21:14:29219+
220If it is `before`, then each new trailer will appear just before the
Junio C Hamanoc05b7642023-10-13 22:27:26221first trailer with the same <key>.
Junio C Hamano4c43d652014-10-20 21:14:29222
223trailer.ifexists::
224This option makes it possible to choose what action will be
225performed when there is already at least one trailer with the
Junio C Hamanoc05b7642023-10-13 22:27:26226same <key> in the input.
Junio C Hamano4c43d652014-10-20 21:14:29227+
228The valid values for this option are: `addIfDifferentNeighbor` (this
Junio C Hamano222ed822017-06-02 06:24:06229is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
Junio C Hamano4c43d652014-10-20 21:14:29230+
231With `addIfDifferentNeighbor`, a new trailer will be added only if no
Junio C Hamanoc05b7642023-10-13 22:27:26232trailer with the same (<key>, <value>) pair is above or below the line
Junio C Hamano4c43d652014-10-20 21:14:29233where the new trailer will be added.
234+
235With `addIfDifferent`, a new trailer will be added only if no trailer
Junio C Hamanoc05b7642023-10-13 22:27:26236with the same (<key>, <value>) pair is already in the input.
Junio C Hamano4c43d652014-10-20 21:14:29237+
238With `add`, a new trailer will be added, even if some trailers with
Junio C Hamanoc05b7642023-10-13 22:27:26239the same (<key>, <value>) pair are already in the input.
Junio C Hamano4c43d652014-10-20 21:14:29240+
Junio C Hamanoc05b7642023-10-13 22:27:26241With `replace`, an existing trailer with the same <key> will be
Junio C Hamano4c43d652014-10-20 21:14:29242deleted and the new trailer will be added. The deleted trailer will be
Junio C Hamanoc05b7642023-10-13 22:27:26243the closest one (with the same <key>) to the place where the new one
Junio C Hamano4c43d652014-10-20 21:14:29244will be added.
245+
246With `doNothing`, nothing will be done; that is no new trailer will be
Junio C Hamanoc05b7642023-10-13 22:27:26247added if there is already one with the same <key> in the input.
Junio C Hamano4c43d652014-10-20 21:14:29248
249trailer.ifmissing::
250This option makes it possible to choose what action will be
251performed when there is not yet any trailer with the same
Junio C Hamanoc05b7642023-10-13 22:27:26252<key> in the input.
Junio C Hamano4c43d652014-10-20 21:14:29253+
254The valid values for this option are: `add` (this is the default) and
255`doNothing`.
256+
257With `add`, a new trailer will be added.
258+
259With `doNothing`, nothing will be done.
260
Junio C Hamanoc05b7642023-10-13 22:27:26261trailer.<keyAlias>.key::
262Defines a <keyAlias> for the <key>. The <keyAlias> must be a
263prefix (case does not matter) of the <key>. For example, in `git
264config trailer.ack.key "Acked-by"` the "Acked-by" is the <key> and
265the "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:..."`.
Junio C Hamano4c43d652014-10-20 21:14:29268+
Junio C Hamanoc05b7642023-10-13 22:27:26269At the end of the <key>, a separator can appear and then some
270space characters. By default the only valid separator is ':',
271but this can be changed using the `trailer.separators` config
272variable.
273+
274If there is a separator in the key, then it overrides the default
275separator when adding the trailer.
Junio C Hamano4c43d652014-10-20 21:14:29276
Junio C Hamanoc05b7642023-10-13 22:27:26277trailer.<keyAlias>.where::
Junio C Hamano4c43d652014-10-20 21:14:29278This option takes the same values as the 'trailer.where'
279configuration variable and it overrides what is specified by
Junio C Hamanoc05b7642023-10-13 22:27:26280that option for trailers with the specified <keyAlias>.
Junio C Hamano4c43d652014-10-20 21:14:29281
Junio C Hamanoc05b7642023-10-13 22:27:26282trailer.<keyAlias>.ifexists::
Junio C Hamanofb1fdf12017-08-27 06:14:59283This option takes the same values as the 'trailer.ifexists'
Junio C Hamano4c43d652014-10-20 21:14:29284configuration variable and it overrides what is specified by
Junio C Hamanoc05b7642023-10-13 22:27:26285that option for trailers with the specified <keyAlias>.
Junio C Hamano4c43d652014-10-20 21:14:29286
Junio C Hamanoc05b7642023-10-13 22:27:26287trailer.<keyAlias>.ifmissing::
Junio C Hamano4c43d652014-10-20 21:14:29288This option takes the same values as the 'trailer.ifmissing'
289configuration variable and it overrides what is specified by
Junio C Hamanoc05b7642023-10-13 22:27:26290that option for trailers with the specified <keyAlias>.
Junio C Hamano4c43d652014-10-20 21:14:29291
Junio C Hamanoc05b7642023-10-13 22:27:26292trailer.<keyAlias>.command::
293Deprecated in favor of 'trailer.<keyAlias>.cmd'.
294This option behaves in the same way as 'trailer.<keyAlias>.cmd', except
Junio C Hamano51a55bc2021-05-12 05:22:19295that it doesn't pass anything as argument to the specified command.
296Instead the first occurrence of substring $ARG is replaced by the
Junio C Hamano9469c132023-06-23 20:26:29297<value> that would be passed as argument.
Junio C Hamano4c43d652014-10-20 21:14:29298+
Junio C Hamano9469c132023-06-23 20:26:29299Note that $ARG in the user's command is
Junio C Hamano51a55bc2021-05-12 05:22:19300only replaced once and that the original way of replacing $ARG is not safe.
Junio C Hamano4c43d652014-10-20 21:14:29301+
Junio C Hamanoc05b7642023-10-13 22:27:26302When both 'trailer.<keyAlias>.cmd' and 'trailer.<keyAlias>.command' are given
303for the same <keyAlias>, 'trailer.<keyAlias>.cmd' is used and
304'trailer.<keyAlias>.command' is ignored.
Junio C Hamano51a55bc2021-05-12 05:22:19305
Junio C Hamanoc05b7642023-10-13 22:27:26306trailer.<keyAlias>.cmd::
Junio C Hamano9469c132023-06-23 20:26:29307This option can be used to specify a shell command that will be called
Junio C Hamanoc05b7642023-10-13 22:27:26308once to automatically add a trailer with the specified <keyAlias>, and then
309called each time a '--trailer <keyAlias>=<value>' argument is specified to
Junio C Hamano9469c132023-06-23 20:26:29310modify the <value> of the trailer that this option would produce.
Junio C Hamano4c43d652014-10-20 21:14:29311+
Junio C Hamano51a55bc2021-05-12 05:22:19312When the specified command is first called to add a trailer
Junio C Hamanoc05b7642023-10-13 22:27:26313with the specified <keyAlias>, the behavior is as if a special
314'--trailer <keyAlias>=<value>' argument was added at the beginning
Junio C Hamano51a55bc2021-05-12 05:22:19315of the "git interpret-trailers" command, where <value>
316is taken to be the standard output of the command with any
317leading and trailing whitespace trimmed off.
318+
Junio C Hamanoc05b7642023-10-13 22:27:26319If some '--trailer <keyAlias>=<value>' arguments are also passed
Junio C Hamano51a55bc2021-05-12 05:22:19320on the command line, the command is called again once for each
Junio C Hamanoc05b7642023-10-13 22:27:26321of these arguments with the same <keyAlias>. And the <value> part
Junio C Hamano51a55bc2021-05-12 05:22:19322of these arguments, if any, will be passed to the command as its
323first argument. This way the command can produce a <value> computed
Junio C Hamanoc05b7642023-10-13 22:27:26324from the <value> passed in the '--trailer <keyAlias>=<value>' argument.
Junio C Hamano4c43d652014-10-20 21:14:29325
326EXAMPLES
327--------
328
329* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
Junio C Hamano9469c132023-06-23 20:26:29330 add two of these trailers to a commit message file:
Junio C Hamano4c43d652014-10-20 21:14:29331+
332------------
333$ git config trailer.sign.key "Signed-off-by"
334$ cat msg.txt
335subject
336
Junio C Hamano9469c132023-06-23 20:26:29337body text
Junio C Hamanod37473e2023-05-15 23:04:43338$ git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' <msg.txt
Junio C Hamano4c43d652014-10-20 21:14:29339subject
340
Junio C Hamano9469c132023-06-23 20:26:29341body text
Junio C Hamano4c43d652014-10-20 21:14:29342
343Signed-off-by: Alice <alice@example.com>
344Signed-off-by: Bob <bob@example.com>
345------------
346
Junio C Hamano9469c132023-06-23 20:26:29347* Use the `--in-place` option to edit a commit message file in place:
Junio C Hamano7d098642016-01-30 00:05:21348+
349------------
350$ cat msg.txt
351subject
352
Junio C Hamano9469c132023-06-23 20:26:29353body text
Junio C Hamano7d098642016-01-30 00:05:21354
355Signed-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
358subject
359
Junio C Hamano9469c132023-06-23 20:26:29360body text
Junio C Hamano7d098642016-01-30 00:05:21361
362Signed-off-by: Bob <bob@example.com>
363Acked-by: Alice <alice@example.com>
364------------
365
Junio C Hamano4c43d652014-10-20 21:14:29366* 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
3710001-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------------
Junio C Hamanod37473e2023-05-15 23:04:43380$ cat msg1.txt
381subject
382
Junio C Hamano9469c132023-06-23 20:26:29383body text
Junio C Hamano4c43d652014-10-20 21:14:29384$ git config trailer.sign.key "Signed-off-by: "
385$ git config trailer.sign.ifmissing add
386$ git config trailer.sign.ifexists doNothing
Junio C Hamanod37473e2023-05-15 23:04:43387$ git config trailer.sign.cmd 'echo "$(git config user.name) <$(git config user.email)>"'
388$ git interpret-trailers --trailer sign <msg1.txt
389subject
390
Junio C Hamano9469c132023-06-23 20:26:29391body text
Junio C Hamano4c43d652014-10-20 21:14:29392
393Signed-off-by: Bob <bob@example.com>
Junio C Hamanod37473e2023-05-15 23:04:43394$ cat msg2.txt
395subject
396
Junio C Hamano9469c132023-06-23 20:26:29397body text
Junio C Hamanod37473e2023-05-15 23:04:43398
399Signed-off-by: Alice <alice@example.com>
400$ git interpret-trailers --trailer sign <msg2.txt
401subject
402
Junio C Hamano9469c132023-06-23 20:26:29403body text
Junio C Hamano4c43d652014-10-20 21:14:29404
405Signed-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
415subject
416
417Fix #42
418------------
419
Junio C Hamano51a55bc2021-05-12 05:22:19420* 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
427test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
Junio C Hamanod37473e2023-05-15 23:04:43428$ cat msg.txt
429subject
430
Junio C Hamano9469c132023-06-23 20:26:29431body text
Junio C Hamano51a55bc2021-05-12 05:22:19432$ git config trailer.help.key "Helped-by: "
433$ git config trailer.help.ifExists "addIfDifferentNeighbor"
434$ git config trailer.help.cmd "~/bin/glog-find-author"
Junio C Hamanod37473e2023-05-15 23:04:43435$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <msg.txt
Junio C Hamano51a55bc2021-05-12 05:22:19436subject
437
Junio C Hamano9469c132023-06-23 20:26:29438body text
Junio C Hamano51a55bc2021-05-12 05:22:19439
440Helped-by: Junio C Hamano <gitster@pobox.com>
441Helped-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
451test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
Junio C Hamanod37473e2023-05-15 23:04:43452$ cat msg.txt
453subject
454
Junio C Hamano9469c132023-06-23 20:26:29455body text
Junio C Hamano51a55bc2021-05-12 05:22:19456$ git config trailer.ref.key "Reference-to: "
457$ git config trailer.ref.ifExists "replace"
458$ git config trailer.ref.cmd "~/bin/glog-grep"
Junio C Hamanod37473e2023-05-15 23:04:43459$ git interpret-trailers --trailer="ref:Add copyright notices." <msg.txt
Junio C Hamano51a55bc2021-05-12 05:22:19460subject
461
Junio C Hamano9469c132023-06-23 20:26:29462body text
Junio C Hamano51a55bc2021-05-12 05:22:19463
464Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)
465------------
466
Junio C Hamano4c43d652014-10-20 21:14:29467* 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------------
Junio C Hamanod37473e2023-05-15 23:04:43471$ cat msg.txt
472subject
473
Junio C Hamano9469c132023-06-23 20:26:29474body text
Junio C Hamanod37473e2023-05-15 23:04:43475
476see: HEAD~2
477$ cat ~/bin/glog-ref
478#!/bin/sh
479git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
Junio C Hamano4c43d652014-10-20 21:14:29480$ git config trailer.see.key "See-also: "
481$ git config trailer.see.ifExists "replace"
482$ git config trailer.see.ifMissing "doNothing"
Junio C Hamanod37473e2023-05-15 23:04:43483$ git config trailer.see.cmd "glog-ref"
484$ git interpret-trailers --trailer=see <msg.txt
Junio C Hamano4c43d652014-10-20 21:14:29485subject
486
Junio C Hamano9469c132023-06-23 20:26:29487body text
Junio C Hamano4c43d652014-10-20 21:14:29488
489See-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------------
Junio C Hamanod37473e2023-05-15 23:04:43499$ cat temp.txt
500***subject***
501
502***message***
503
504Fixes: Z
505Cc: Z
506Reviewed-by: Z
507Signed-off-by: Z
508$ sed -e 's/ Z$/ /' temp.txt > commit_template.txt
Junio C Hamano4c43d652014-10-20 21:14:29509$ git config commit.template commit_template.txt
Junio C Hamanod37473e2023-05-15 23:04:43510$ cat .git/hooks/commit-msg
511#!/bin/sh
512git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
513mv "\$1.new" "\$1"
Junio C Hamano4c43d652014-10-20 21:14:29514$ chmod +x .git/hooks/commit-msg
515------------
516
517SEE ALSO
518--------
519linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
520
521GIT
522---
523Part of the linkgit:git[1] suite