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