@@ -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
@@ -81,19 +87,25 @@ trailer.sign.key "Signed-off-by: "
8187in your configuration, you only need to specify `--trailer="sign: foo"`
8288on the command line instead of `--trailer="Signed-off-by: foo"` .
8389
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.
90+ By default the new trailer will appear at the end of the trailer block.
91+ A trailer block will be created with only that trailer if a trailer
92+ block does not already exist. Recall that a trailer block needs to be
93+ preceded by a blank line, so a blank line (specifically an empty line)
94+ will be inserted before the new trailer block in that case.
8895
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
96+ Existing trailers are extracted from the input by looking for the
97+ trailer block. Concretely, that is a group of one or more lines that (i)
98+ is all trailers, or (ii) contains at least one Git-generated or
99+ user-configured trailer and consists of at
92100least 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).
101+ The trailer block is by definition at the end the the message. The end
102+ of the message in turn is either (i) at the end of the input, or (ii)
103+ the last non-whitespace lines before a line that starts with `---`
104+ (followed by a space or the end of the line).
105+
106+ This command ignores comment lines (see `core.commentString` in
107+ linkgit:git-config[1]). This is for use with the `prepare-commit-msg`
108+ and `commit-msg` hooks.
97109
98110When reading trailers, there can be no whitespace before or inside the
99111_<key>_ , but any number of regular space and tab characters are allowed
@@ -107,9 +119,6 @@ key: This is a very long value, with spaces and
107119 newlines in it.
108120------------------------------------------------
109121
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.
112-
113122OPTIONS
114123-------
115124`--in-place` ::
@@ -402,6 +411,29 @@ mv "\$1.new" "\$1"
402411$ chmod +x .git/hooks/commit-msg
403412------------
404413
414+ * Here we try to to use three different trailer keys. But it fails
415+ because two of them are not recognized as trailer keys.
416+ +
417+ ----
418+ $ cat msg.txt
419+ subject
420+
421+ Skapad-på: some-branch
422+ Hash-in-v6.11: 45c12d3269fe48f22834320c782ffe86c3560f2c
423+ Reviewed-by: Alice <alice @example.com >
424+ $ git interpret-trailers -- only-trailers <msg .txt
425+ $
426+ ----
427+ +
428+ Recall that a trailer key has to consist of only ASCII alphanumeric
429+ characters and hyphens, and this does not hold for the two first
430+ supposed trailer keys. And now none are recognized as trailers because
431+ the candidate trailer block has at least one non-trailer line, even
432+ though `Reviewed-by` is a valid trailer key. Recall that a trailer block
433+ has to either (i) be all trailers, or (ii) consist of at least one
434+ Git-generated or user-configured trailer (and some other conditions).
435+ And (ii) is not satisfied since we have not configured any trailer keys.
436+
405437SEE ALSO
406438--------
407439linkgit:git-commit[1], linkgit:git-format-patch[1], linkgit:git-config[1]
0 commit comments