152479ebba6c74afd6d4e02d292a89b25d6bd346
   1git-interpret-trailers(1)
   2=========================
   3
   4NAME
   5----
   6git-interpret-trailers - add or parse structured information in commit messages
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git interpret-trailers' [<options>] [(--trailer <token>[(=|:)<value>])...] [<file>...]
  12'git interpret-trailers' [<options>] [--parse] [<file>...]
  13
  14DESCRIPTION
  15-----------
  16Help parsing or adding 'trailers' lines, that look similar to RFC 822 e-mail
  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
  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
  24Otherwise, this command applies the arguments passed using the
  25`--trailer` option, if any, to the commit message part of each input
  26file. The result is emitted on the standard output.
  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
  49after the commit message part of the output, and, if there is no line
  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
  54a group of one or more lines that (i) is all trailers, or (ii) contains at
  55least one Git-generated or user-configured trailer and consists of at
  56least 25% trailers.
  57The group must be preceded by one or more empty (or whitespace-only) lines.
  58The group must either be at the end of the message or be the last
  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
  61part of the message.
  62
  63When reading trailers, there can be whitespaces after the
  64token, the separator and the value. There can also be whitespaces
  65inside the token and the value. The value may be split over multiple lines with
  66each subsequent line starting with whitespace, like the "folding" in RFC 822.
  67
  68Note that 'trailers' do not follow and are not intended to follow many
  69rules for RFC 822 headers. For example they do not follow
  70the encoding rules and probably many other rules.
  71
  72OPTIONS
  73-------
  74--in-place::
  75        Edit the files in place.
  76
  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.
  80        This applies to existing trailers as well as new trailers.
  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
  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
 110--only-trailers::
 111        Output only the trailers, not any other parts of the input.
 112
 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
 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
 122--parse::
 123        A convenience alias for `--only-trailers --only-input
 124        --unfold`.
 125
 126CONFIGURATION VARIABLES
 127-----------------------
 128
 129trailer.separators::
 130        This option tells which characters are recognized as trailer
 131        separators. By default only ':' is recognized as a trailer
 132        separator, except that '=' is always accepted on the command
 133        line for compatibility with other git commands.
 134+
 135The first character given by this option will be the default character
 136used when another separator is not specified in the config for this
 137trailer.
 138+
 139For example, if the value for this option is "%=$", then only lines
 140using the format '<token><sep><value>' with <sep> containing '%', '='
 141or '$' and then spaces will be considered trailers. And '%' will be
 142the default separator used, so by default trailers will appear like:
 143'<token>% <value>' (one percent sign and one space will appear between
 144the token and the value).
 145
 146trailer.where::
 147        This option tells where a new trailer will be added.
 148+
 149This can be `end`, which is the default, `start`, `after` or `before`.
 150+
 151If it is `end`, then each new trailer will appear at the end of the
 152existing trailers.
 153+
 154If it is `start`, then each new trailer will appear at the start,
 155instead of the end, of the existing trailers.
 156+
 157If it is `after`, then each new trailer will appear just after the
 158last trailer with the same <token>.
 159+
 160If it is `before`, then each new trailer will appear just before the
 161first trailer with the same <token>.
 162
 163trailer.ifexists::
 164        This option makes it possible to choose what action will be
 165        performed when there is already at least one trailer with the
 166        same <token> in the message.
 167+
 168The valid values for this option are: `addIfDifferentNeighbor` (this
 169is the default), `addIfDifferent`, `add`, `replace` or `doNothing`.
 170+
 171With `addIfDifferentNeighbor`, a new trailer will be added only if no
 172trailer with the same (<token>, <value>) pair is above or below the line
 173where the new trailer will be added.
 174+
 175With `addIfDifferent`, a new trailer will be added only if no trailer
 176with the same (<token>, <value>) pair is already in the message.
 177+
 178With `add`, a new trailer will be added, even if some trailers with
 179the same (<token>, <value>) pair are already in the message.
 180+
 181With `replace`, an existing trailer with the same <token> will be
 182deleted and the new trailer will be added. The deleted trailer will be
 183the closest one (with the same <token>) to the place where the new one
 184will be added.
 185+
 186With `doNothing`, nothing will be done; that is no new trailer will be
 187added if there is already one with the same <token> in the message.
 188
 189trailer.ifmissing::
 190        This option makes it possible to choose what action will be
 191        performed when there is not yet any trailer with the same
 192        <token> in the message.
 193+
 194The valid values for this option are: `add` (this is the default) and
 195`doNothing`.
 196+
 197With `add`, a new trailer will be added.
 198+
 199With `doNothing`, nothing will be done.
 200
 201trailer.<token>.key::
 202        This `key` will be used instead of <token> in the trailer. At
 203        the end of this key, a separator can appear and then some
 204        space characters. By default the only valid separator is ':',
 205        but this can be changed using the `trailer.separators` config
 206        variable.
 207+
 208If there is a separator, then the key will be used instead of both the
 209<token> and the default separator when adding the trailer.
 210
 211trailer.<token>.where::
 212        This option takes the same values as the 'trailer.where'
 213        configuration variable and it overrides what is specified by
 214        that option for trailers with the specified <token>.
 215
 216trailer.<token>.ifexists::
 217        This option takes the same values as the 'trailer.ifexists'
 218        configuration variable and it overrides what is specified by
 219        that option for trailers with the specified <token>.
 220
 221trailer.<token>.ifmissing::
 222        This option takes the same values as the 'trailer.ifmissing'
 223        configuration variable and it overrides what is specified by
 224        that option for trailers with the specified <token>.
 225
 226trailer.<token>.command::
 227        This option can be used to specify a shell command that will
 228        be called to automatically add or modify a trailer with the
 229        specified <token>.
 230+
 231When this option is specified, the behavior is as if a special
 232'<token>=<value>' argument were added at the beginning of the command
 233line, where <value> is taken to be the standard output of the
 234specified command with any leading and trailing whitespace trimmed
 235off.
 236+
 237If the command contains the `$ARG` string, this string will be
 238replaced with the <value> part of an existing trailer with the same
 239<token>, if any, before the command is launched.
 240+
 241If some '<token>=<value>' arguments are also passed on the command
 242line, when a 'trailer.<token>.command' is configured, the command will
 243also be executed for each of these arguments. And the <value> part of
 244these arguments, if any, will be used to replace the `$ARG` string in
 245the command.
 246
 247EXAMPLES
 248--------
 249
 250* Configure a 'sign' trailer with a 'Signed-off-by' key, and then
 251  add two of these trailers to a message:
 252+
 253------------
 254$ git config trailer.sign.key "Signed-off-by"
 255$ cat msg.txt
 256subject
 257
 258message
 259$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>'
 260subject
 261
 262message
 263
 264Signed-off-by: Alice <alice@example.com>
 265Signed-off-by: Bob <bob@example.com>
 266------------
 267
 268* Use the `--in-place` option to edit a message file in place:
 269+
 270------------
 271$ cat msg.txt
 272subject
 273
 274message
 275
 276Signed-off-by: Bob <bob@example.com>
 277$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt
 278$ cat msg.txt
 279subject
 280
 281message
 282
 283Signed-off-by: Bob <bob@example.com>
 284Acked-by: Alice <alice@example.com>
 285------------
 286
 287* Extract the last commit as a patch, and add a 'Cc' and a
 288  'Reviewed-by' trailer to it:
 289+
 290------------
 291$ git format-patch -1
 2920001-foo.patch
 293$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch
 294------------
 295
 296* Configure a 'sign' trailer with a command to automatically add a
 297  'Signed-off-by: ' with the author information only if there is no
 298  'Signed-off-by: ' already, and show how it works:
 299+
 300------------
 301$ git config trailer.sign.key "Signed-off-by: "
 302$ git config trailer.sign.ifmissing add
 303$ git config trailer.sign.ifexists doNothing
 304$ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"'
 305$ git interpret-trailers <<EOF
 306> EOF
 307
 308Signed-off-by: Bob <bob@example.com>
 309$ git interpret-trailers <<EOF
 310> Signed-off-by: Alice <alice@example.com>
 311> EOF
 312
 313Signed-off-by: Alice <alice@example.com>
 314------------
 315
 316* Configure a 'fix' trailer with a key that contains a '#' and no
 317  space after this character, and show how it works:
 318+
 319------------
 320$ git config trailer.separators ":#"
 321$ git config trailer.fix.key "Fix #"
 322$ echo "subject" | git interpret-trailers --trailer fix=42
 323subject
 324
 325Fix #42
 326------------
 327
 328* Configure a 'see' trailer with a command to show the subject of a
 329  commit that is related, and show how it works:
 330+
 331------------
 332$ git config trailer.see.key "See-also: "
 333$ git config trailer.see.ifExists "replace"
 334$ git config trailer.see.ifMissing "doNothing"
 335$ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG"
 336$ git interpret-trailers <<EOF
 337> subject
 338> 
 339> message
 340> 
 341> see: HEAD~2
 342> EOF
 343subject
 344
 345message
 346
 347See-also: fe3187489d69c4 (subject of related commit)
 348------------
 349
 350* Configure a commit template with some trailers with empty values
 351  (using sed to show and keep the trailing spaces at the end of the
 352  trailers), then configure a commit-msg hook that uses
 353  'git interpret-trailers' to remove trailers with empty values and
 354  to add a 'git-version' trailer:
 355+
 356------------
 357$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF
 358> ***subject***
 359> 
 360> ***message***
 361> 
 362> Fixes: Z
 363> Cc: Z
 364> Reviewed-by: Z
 365> Signed-off-by: Z
 366> EOF
 367$ git config commit.template commit_template.txt
 368$ cat >.git/hooks/commit-msg <<EOF
 369> #!/bin/sh
 370> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new"
 371> mv "\$1.new" "\$1"
 372> EOF
 373$ chmod +x .git/hooks/commit-msg
 374------------
 375
 376SEE ALSO
 377--------
 378linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
 379
 380GIT
 381---
 382Part of the linkgit:git[1] suite