1git-interpret-trailers(1) 2========================= 3 4NAME 5---- 6git-interpret-trailers - help add structured information into commit messages 7 8SYNOPSIS 9-------- 10[verse] 11'git interpret-trailers' [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...] 12 13DESCRIPTION 14----------- 15Help adding 'trailers' lines, that look similar to RFC 822 e-mail 16headers, at the end of the otherwise free-form part of a commit 17message. 18 19This command reads some patches or commit messages from either the 20<file> arguments or the standard input if no <file> is specified. Then 21this command applies the arguments passed using the `--trailer` 22option, if any, to the commit message part of each input file. The 23result is emitted on the standard output. 24 25Some configuration variables control the way the `--trailer` arguments 26are applied to each commit message and the way any existing trailer in 27the commit message is changed. They also make it possible to 28automatically add some trailers. 29 30By default, a '<token>=<value>' or '<token>:<value>' argument given 31using `--trailer` will be appended after the existing trailers only if 32the last trailer has a different (<token>, <value>) pair (or if there 33is no existing trailer). The <token> and <value> parts will be trimmed 34to remove starting and trailing whitespace, and the resulting trimmed 35<token> and <value> will appear in the message like this: 36 37------------------------------------------------ 38token: value 39------------------------------------------------ 40 41This means that the trimmed <token> and <value> will be separated by 42`': '` (one colon followed by one space). 43 44By default the new trailer will appear at the end of all the existing 45trailers. If there is no existing trailer, the new trailer will appear 46after the commit message part of the output, and, if there is no line 47with only spaces at the end of the commit message part, one blank line 48will be added before the new trailer. 49 50Existing trailers are extracted from the input message by looking for 51a group of one or more lines that (i) are all trailers, or (ii) contains at 52least one Git-generated or user-configured trailer and consists of at 53least 25% trailers. 54The group must be preceded by one or more empty (or whitespace-only) lines. 55The group must either be at the end of the message or be the last 56non-whitespace lines before a line that starts with '---'. Such three 57minus signs start the patch part of the message. 58 59When reading trailers, there can be whitespaces after the 60token, the separator and the value. There can also be whitespaces 61inside the token and the value. The value may be split over multiple lines with 62each subsequent line starting with whitespace, like the "folding" in RFC 822. 63 64Note that 'trailers' do not follow and are not intended to follow many 65rules for RFC 822 headers. For example they do not follow 66the encoding rules and probably many other rules. 67 68OPTIONS 69------- 70--in-place:: 71 Edit the files in place. 72 73--trim-empty:: 74 If the <value> part of any trailer contains only whitespace, 75 the whole trailer will be removed from the resulting message. 76 This applies to existing trailers as well as new trailers. 77 78--trailer <token>[(=|:)<value>]:: 79 Specify a (<token>, <value>) pair that should be applied as a 80 trailer to the input messages. See the description of this 81 command. 82 83--only-trailers:: 84 Output only the trailers, not any other parts of the input. 85 86--only-input:: 87 Output only trailers that exist in the input; do not add any 88 from the command-line or by following configured `trailer.*` 89 rules. 90 91--unfold:: 92 Remove any whitespace-continuation in trailers, so that each 93 trailer appears on a line by itself with its full content. 94 95CONFIGURATION VARIABLES 96----------------------- 97 98trailer.separators:: 99 This option tells which characters are recognized as trailer 100 separators. By default only ':' is recognized as a trailer 101 separator, except that '=' is always accepted on the command 102 line for compatibility with other git commands. 103+ 104The first character given by this option will be the default character 105used when another separator is not specified in the config for this 106trailer. 107+ 108For example, if the value for this option is "%=$", then only lines 109using the format '<token><sep><value>' with <sep> containing '%', '=' 110or '$' and then spaces will be considered trailers. And '%' will be 111the default separator used, so by default trailers will appear like: 112'<token>% <value>' (one percent sign and one space will appear between 113the token and the value). 114 115trailer.where:: 116 This option tells where a new trailer will be added. 117+ 118This can be `end`, which is the default, `start`, `after` or `before`. 119+ 120If it is `end`, then each new trailer will appear at the end of the 121existing trailers. 122+ 123If it is `start`, then each new trailer will appear at the start, 124instead of the end, of the existing trailers. 125+ 126If it is `after`, then each new trailer will appear just after the 127last trailer with the same <token>. 128+ 129If it is `before`, then each new trailer will appear just before the 130first trailer with the same <token>. 131 132trailer.ifexists:: 133 This option makes it possible to choose what action will be 134 performed when there is already at least one trailer with the 135 same <token> in the message. 136+ 137The valid values for this option are: `addIfDifferentNeighbor` (this 138is the default), `addIfDifferent`, `add`, `replace` or `doNothing`. 139+ 140With `addIfDifferentNeighbor`, a new trailer will be added only if no 141trailer with the same (<token>, <value>) pair is above or below the line 142where the new trailer will be added. 143+ 144With `addIfDifferent`, a new trailer will be added only if no trailer 145with the same (<token>, <value>) pair is already in the message. 146+ 147With `add`, a new trailer will be added, even if some trailers with 148the same (<token>, <value>) pair are already in the message. 149+ 150With `replace`, an existing trailer with the same <token> will be 151deleted and the new trailer will be added. The deleted trailer will be 152the closest one (with the same <token>) to the place where the new one 153will be added. 154+ 155With `doNothing`, nothing will be done; that is no new trailer will be 156added if there is already one with the same <token> in the message. 157 158trailer.ifmissing:: 159 This option makes it possible to choose what action will be 160 performed when there is not yet any trailer with the same 161 <token> in the message. 162+ 163The valid values for this option are: `add` (this is the default) and 164`doNothing`. 165+ 166With `add`, a new trailer will be added. 167+ 168With `doNothing`, nothing will be done. 169 170trailer.<token>.key:: 171 This `key` will be used instead of <token> in the trailer. At 172 the end of this key, a separator can appear and then some 173 space characters. By default the only valid separator is ':', 174 but this can be changed using the `trailer.separators` config 175 variable. 176+ 177If there is a separator, then the key will be used instead of both the 178<token> and the default separator when adding the trailer. 179 180trailer.<token>.where:: 181 This option takes the same values as the 'trailer.where' 182 configuration variable and it overrides what is specified by 183 that option for trailers with the specified <token>. 184 185trailer.<token>.ifexist:: 186 This option takes the same values as the 'trailer.ifexist' 187 configuration variable and it overrides what is specified by 188 that option for trailers with the specified <token>. 189 190trailer.<token>.ifmissing:: 191 This option takes the same values as the 'trailer.ifmissing' 192 configuration variable and it overrides what is specified by 193 that option for trailers with the specified <token>. 194 195trailer.<token>.command:: 196 This option can be used to specify a shell command that will 197 be called to automatically add or modify a trailer with the 198 specified <token>. 199+ 200When this option is specified, the behavior is as if a special 201'<token>=<value>' argument were added at the beginning of the command 202line, where <value> is taken to be the standard output of the 203specified command with any leading and trailing whitespace trimmed 204off. 205+ 206If the command contains the `$ARG` string, this string will be 207replaced with the <value> part of an existing trailer with the same 208<token>, if any, before the command is launched. 209+ 210If some '<token>=<value>' arguments are also passed on the command 211line, when a 'trailer.<token>.command' is configured, the command will 212also be executed for each of these arguments. And the <value> part of 213these arguments, if any, will be used to replace the `$ARG` string in 214the command. 215 216EXAMPLES 217-------- 218 219* Configure a 'sign' trailer with a 'Signed-off-by' key, and then 220 add two of these trailers to a message: 221+ 222------------ 223$ git config trailer.sign.key "Signed-off-by" 224$ cat msg.txt 225subject 226 227message 228$ cat msg.txt | git interpret-trailers --trailer 'sign: Alice <alice@example.com>' --trailer 'sign: Bob <bob@example.com>' 229subject 230 231message 232 233Signed-off-by: Alice <alice@example.com> 234Signed-off-by: Bob <bob@example.com> 235------------ 236 237* Use the `--in-place` option to edit a message file in place: 238+ 239------------ 240$ cat msg.txt 241subject 242 243message 244 245Signed-off-by: Bob <bob@example.com> 246$ git interpret-trailers --trailer 'Acked-by: Alice <alice@example.com>' --in-place msg.txt 247$ cat msg.txt 248subject 249 250message 251 252Signed-off-by: Bob <bob@example.com> 253Acked-by: Alice <alice@example.com> 254------------ 255 256* Extract the last commit as a patch, and add a 'Cc' and a 257 'Reviewed-by' trailer to it: 258+ 259------------ 260$ git format-patch -1 2610001-foo.patch 262$ git interpret-trailers --trailer 'Cc: Alice <alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>' 0001-foo.patch >0001-bar.patch 263------------ 264 265* Configure a 'sign' trailer with a command to automatically add a 266 'Signed-off-by: ' with the author information only if there is no 267 'Signed-off-by: ' already, and show how it works: 268+ 269------------ 270$ git config trailer.sign.key "Signed-off-by: " 271$ git config trailer.sign.ifmissing add 272$ git config trailer.sign.ifexists doNothing 273$ git config trailer.sign.command 'echo "$(git config user.name) <$(git config user.email)>"' 274$ git interpret-trailers <<EOF 275> EOF 276 277Signed-off-by: Bob <bob@example.com> 278$ git interpret-trailers <<EOF 279> Signed-off-by: Alice <alice@example.com> 280> EOF 281 282Signed-off-by: Alice <alice@example.com> 283------------ 284 285* Configure a 'fix' trailer with a key that contains a '#' and no 286 space after this character, and show how it works: 287+ 288------------ 289$ git config trailer.separators ":#" 290$ git config trailer.fix.key "Fix #" 291$ echo "subject" | git interpret-trailers --trailer fix=42 292subject 293 294Fix #42 295------------ 296 297* Configure a 'see' trailer with a command to show the subject of a 298 commit that is related, and show how it works: 299+ 300------------ 301$ git config trailer.see.key "See-also: " 302$ git config trailer.see.ifExists "replace" 303$ git config trailer.see.ifMissing "doNothing" 304$ git config trailer.see.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" 305$ git interpret-trailers <<EOF 306> subject 307> 308> message 309> 310> see: HEAD~2 311> EOF 312subject 313 314message 315 316See-also: fe3187489d69c4 (subject of related commit) 317------------ 318 319* Configure a commit template with some trailers with empty values 320 (using sed to show and keep the trailing spaces at the end of the 321 trailers), then configure a commit-msg hook that uses 322 'git interpret-trailers' to remove trailers with empty values and 323 to add a 'git-version' trailer: 324+ 325------------ 326$ sed -e 's/ Z$/ /' >commit_template.txt <<EOF 327> ***subject*** 328> 329> ***message*** 330> 331> Fixes: Z 332> Cc: Z 333> Reviewed-by: Z 334> Signed-off-by: Z 335> EOF 336$ git config commit.template commit_template.txt 337$ cat >.git/hooks/commit-msg <<EOF 338> #!/bin/sh 339> git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" > "\$1.new" 340> mv "\$1.new" "\$1" 341> EOF 342$ chmod +x .git/hooks/commit-msg 343------------ 344 345SEE ALSO 346-------- 347linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1] 348 349GIT 350--- 351Part of the linkgit:git[1] suite