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