@@ -3,7 +3,7 @@ git-interpret-trailers(1)
33
44NAME
55----
6- git-interpret-trailers - Add or parse structured information in commit messages
6+ git-interpret-trailers - Add or parse metadata in commit messages
77
88SYNOPSIS
99--------
@@ -14,9 +14,15 @@ git interpret-trailers [--in-place] [--trim-empty]
1414
1515DESCRIPTION
1616-----------
17- Add or parse _trailer_ lines that look similar to RFC 822 e-mail
18- headers, at the end of the otherwise free-form part of a commit
19- message. For example, in the following commit message
17+ Add or parse trailers metadata at the end of the otherwise
18+ free-form part of a commit message, or any other kind of text.
19+
20+ A _trailer_ in its simplest form is a key-value pair with a colon as a
21+ separator. The _key_ consists of ASCII alphanumeric characters and
22+ hyphens (`-` ). A _trailer block_ consists of one or more trailers. The
23+ trailer block needs to be preceded by a blank line, where a _blank line_
24+ is either an empty or a whitespace-only line. For example, in the
25+ following commit message
2026
2127------------------------------------------------
2228subject
@@ -68,6 +74,22 @@ key: value
6874This means that the trimmed _<key>_ and _<value>_ will be separated by
6975"`:` {nbsp} " (one colon followed by one space).
7076
77+ By default the new trailer will appear at the end of the trailer block.
78+ A trailer block will be created with only that trailer if a trailer
79+ block does not already exist. Recall that a trailer block needs to be
80+ preceded by a blank line, so a blank line (specifically an empty line)
81+ will be inserted before the new trailer block in that case.
82+
83+ Existing trailers are extracted from the input by looking for the
84+ trailer block. Concretely, that is a group of one or more lines that (i)
85+ is all trailers, or (ii) contains at least one Git-generated or
86+ user-configured trailer and consists of at
87+ least 25% trailers.
88+ The trailer block is by definition at the end the the message. The end
89+ of the message in turn is either (i) at the end of the input, or (ii)
90+ the last non-whitespace lines before a line that starts with `---`
91+ (followed by a space or the end of the line).
92+
7193For convenience, a _<key-alias>_ can be configured to make using `--trailer`
7294shorter to type on the command line. This can be configured using the
7395`trailer.<key-alias>.key` configuration variable. The _<key-alias>_ must be a prefix
@@ -81,20 +103,6 @@ trailer.sign.key "Signed-off-by: "
81103in your configuration, you only need to specify `--trailer="sign: foo"`
82104on the command line instead of `--trailer="Signed-off-by: foo"` .
83105
84- By default the new trailer will appear at the end of all the existing
85- trailers. If there is no existing trailer, the new trailer will appear
86- at the end of the input. A blank line will be added before the new
87- trailer if there isn't one already.
88-
89- Existing trailers are extracted from the input by looking for
90- a group of one or more lines that (i) is all trailers, or (ii) contains at
91- least one Git-generated or user-configured trailer and consists of at
92- least 25% trailers.
93- The group must be preceded by one or more empty (or whitespace-only) lines.
94- The group must either be at the end of the input or be the last
95- non-whitespace lines before a line that starts with `---` (followed by a
96- space or the end of the line).
97-
98106When reading trailers, there can be no whitespace before or inside the
99107_<key>_ , but any number of regular space and tab characters are allowed
100108between the _<key>_ and the separator. There can be whitespaces before,
@@ -107,8 +115,15 @@ key: This is a very long value, with spaces and
107115 newlines in it.
108116------------------------------------------------
109117
110- Note that trailers do not follow (nor are they intended to follow) many of the
111- rules for RFC 822 headers. For example they do not follow the encoding rule.
118+ OTHER RULES
119+ -----------
120+
121+ What was covered in the previous section are the rules that are relevant
122+ for regular use. The following points are included for completeness.
123+
124+ This command ignores comment lines (see `core.commentString` in
125+ linkgit:git-config[1]). This is for use with the `prepare-commit-msg`
126+ and `commit-msg` hooks.
112127
113128OPTIONS
114129-------
@@ -402,6 +417,29 @@ mv "\$1.new" "\$1"
402417$ chmod +x .git/hooks/commit-msg
403418------------
404419
420+ * Here we try to to use three different trailer keys. But it fails
421+ because two of them are not recognized as trailer keys.
422+ +
423+ ----
424+ $ cat msg.txt
425+ subject
426+
427+ Skapad-på: some-branch
428+ Hash-in-v6.11: 45c12d3269fe48f22834320c782ffe86c3560f2c
429+ Reviewed-by: Alice <alice @example.com >
430+ $ git interpret-trailers -- only-trailers <msg .txt
431+ $
432+ ----
433+ +
434+ Recall that a trailer key has to consist of only ASCII alphanumeric
435+ characters and hyphens, and this does not hold for the two first
436+ supposed trailer keys. And now none are recognized as trailers because
437+ the candidate trailer block has at least one non-trailer line, even
438+ though `Reviewed-by` is a valid trailer key. Recall that a trailer block
439+ has to either (i) be all trailers, or (ii) consist of at least one
440+ Git-generated or user-configured trailer (and some other conditions).
441+ And (ii) is not satisfied since we have not configured any trailer keys.
442+
405443SEE ALSO
406444--------
407445linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
0 commit comments