<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="git-interpret-trailers(1)">
    <title>git-interpret-trailers(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>git-interpret-trailers(1)</primary>
</indexterm>
<simplesect id="git-interpret-trailers(1)__name">
<title>NAME</title>
<simpara>git-interpret-trailers - Add or parse structured information in commit messages</simpara>
</simplesect>
<simplesect id="git-interpret-trailers(1)__synopsis">
<title>SYNOPSIS</title>
<blockquote>
<literallayout><emphasis>git interpret-trailers</emphasis> [--in-place] [--trim-empty]
                        [(--trailer (&lt;key&gt;|&lt;key-alias&gt;)[(=|:)&lt;value&gt;])&#8230;]
                        [--parse] [&lt;file&gt;&#8230;]</literallayout>
</blockquote>
</simplesect>
<simplesect id="git-interpret-trailers(1)__description">
<title>DESCRIPTION</title>
<simpara>Add or parse <emphasis>trailer</emphasis> lines that look similar to RFC 822 e-mail
headers, at the end of the otherwise free-form part of a commit
message. For example, in the following commit message</simpara>
<screen>subject

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Signed-off-by: Alice &lt;alice@example.com&gt;
Signed-off-by: Bob &lt;bob@example.com&gt;</screen>
<simpara>the last two lines starting with "Signed-off-by" are trailers.</simpara>
<simpara>This command reads commit messages from either the
&lt;file&gt; arguments or the standard input if no &lt;file&gt; is specified.
If <emphasis>--parse</emphasis> is specified, the output consists of the parsed trailers
coming from the input, without influencing them with any command line
options or configuration variables.</simpara>
<simpara>Otherwise, this command applies <emphasis>trailer.*</emphasis> configuration variables
(which could potentially add new trailers, as well as reposition them),
as well as any command line arguments that can override configuration
variables (such as <emphasis>--trailer=...</emphasis> which could also add new trailers),
to each input file. The result is emitted on the standard output.</simpara>
<simpara>This command can also operate on the output of <xref linkend="git-format-patch(1)" />,
which is more elaborate than a plain commit message. Namely, such output
includes a commit message (as above), a "---" divider line, and a patch part.
For these inputs, the divider and patch parts are not modified by
this command and are emitted as is on the output, unless
<emphasis>--no-divider</emphasis> is specified.</simpara>
<simpara>Some configuration variables control the way the <emphasis>--trailer</emphasis> arguments
are applied to each input and the way any existing trailer in
the input is changed. They also make it possible to
automatically add some trailers.</simpara>
<simpara>By default, a <emphasis>&lt;key&gt;=&lt;value&gt;</emphasis> or <emphasis>&lt;key&gt;:&lt;value&gt;</emphasis> argument given
using <emphasis>--trailer</emphasis> will be appended after the existing trailers only if
the last trailer has a different (&lt;key&gt;, &lt;value&gt;) pair (or if there
is no existing trailer). The &lt;key&gt; and &lt;value&gt; parts will be trimmed
to remove starting and trailing whitespace, and the resulting trimmed
&lt;key&gt; and &lt;value&gt; will appear in the output like this:</simpara>
<screen>key: value</screen>
<simpara>This means that the trimmed &lt;key&gt; and &lt;value&gt; will be separated by
<emphasis>': '</emphasis> (one colon followed by one space).</simpara>
<simpara>For convenience, a &lt;key-alias&gt; can be configured to make using <emphasis>--trailer</emphasis>
shorter to type on the command line. This can be configured using the
<emphasis>trailer.&lt;key-alias&gt;.key</emphasis> configuration variable. The &lt;keyAlias&gt; must be a prefix
of the full &lt;key&gt; string, although case sensitivity does not matter. For
example, if you have</simpara>
<screen>trailer.sign.key "Signed-off-by: "</screen>
<simpara>in your configuration, you only need to specify <emphasis>--trailer="sign: foo"</emphasis>
on the command line instead of <emphasis>--trailer="Signed-off-by: foo"</emphasis>.</simpara>
<simpara>By default the new trailer will appear at the end of all the existing
trailers. If there is no existing trailer, the new trailer will appear
at the end of the input. A blank line will be added before the new
trailer if there isn't one already.</simpara>
<simpara>Existing trailers are extracted from the input by looking for
a group of one or more lines that (i) is all trailers, or (ii) contains at
least one Git-generated or user-configured trailer and consists of at
least 25% trailers.
The group must be preceded by one or more empty (or whitespace-only) lines.
The group must either be at the end of the input or be the last
non-whitespace lines before a line that starts with <emphasis>---</emphasis> (followed by a
space or the end of the line).</simpara>
<simpara>When reading trailers, there can be no whitespace before or inside the
&lt;key&gt;, but any number of regular space and tab characters are allowed
between the &lt;key&gt; and the separator. There can be whitespaces before,
inside or after the &lt;value&gt;. The &lt;value&gt; may be split over multiple lines
with each subsequent line starting with at least one whitespace, like
the "folding" in RFC 822. Example:</simpara>
<screen>key: This is a very long value, with spaces and
  newlines in it.</screen>
<simpara>Note that trailers do not follow (nor are they intended to follow) many of the
rules for RFC 822 headers. For example they do not follow the encoding rule.</simpara>
</simplesect>
<simplesect id="git-interpret-trailers(1)__options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--in-place
</term>
<listitem>
<simpara>
        Edit the files in place.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--trim-empty
</term>
<listitem>
<simpara>
        If the &lt;value&gt; part of any trailer contains only whitespace,
        the whole trailer will be removed from the output.
        This applies to existing trailers as well as new trailers.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--trailer &lt;key&gt;[(=|:)&lt;value&gt;]
</term>
<listitem>
<simpara>
        Specify a (&lt;key&gt;, &lt;value&gt;) pair that should be applied as a
        trailer to the inputs. See the description of this
        command.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--where &lt;placement&gt;
</term>
<term>
--no-where
</term>
<listitem>
<simpara>
        Specify where all new trailers will be added.  A setting
        provided with <emphasis>--where</emphasis> overrides the <emphasis>trailer.where</emphasis> and any
        applicable <emphasis>trailer.&lt;keyAlias&gt;.where</emphasis> configuration variables
        and applies to all <emphasis>--trailer</emphasis> options until the next occurrence of
        <emphasis>--where</emphasis> or <emphasis>--no-where</emphasis>. Upon encountering <emphasis>--no-where</emphasis>, clear the
        effect of any previous use of <emphasis>--where</emphasis>, such that the relevant configuration
        variables are no longer overridden. Possible placements are <emphasis>after</emphasis>,
        <emphasis>before</emphasis>, <emphasis>end</emphasis> or <emphasis>start</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--if-exists &lt;action&gt;
</term>
<term>
--no-if-exists
</term>
<listitem>
<simpara>
        Specify what action will be performed when there is already at
        least one trailer with the same &lt;key&gt; in the input.  A setting
        provided with <emphasis>--if-exists</emphasis> overrides the <emphasis>trailer.ifExists</emphasis> and any
        applicable <emphasis>trailer.&lt;keyAlias&gt;.ifExists</emphasis> configuration variables
        and applies to all <emphasis>--trailer</emphasis> options until the next occurrence of
        <emphasis>--if-exists</emphasis> or <emphasis>--no-if-exists</emphasis>. Upon encountering '--no-if-exists, clear the
        effect of any previous use of '--if-exists, such that the relevant configuration
        variables are no longer overridden. Possible actions are <emphasis>addIfDifferent</emphasis>,
        <emphasis>addIfDifferentNeighbor</emphasis>, <emphasis>add</emphasis>, <emphasis>replace</emphasis> and <emphasis>doNothing</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--if-missing &lt;action&gt;
</term>
<term>
--no-if-missing
</term>
<listitem>
<simpara>
        Specify what action will be performed when there is no other
        trailer with the same &lt;key&gt; in the input.  A setting
        provided with <emphasis>--if-missing</emphasis> overrides the <emphasis>trailer.ifMissing</emphasis> and any
        applicable <emphasis>trailer.&lt;keyAlias&gt;.ifMissing</emphasis> configuration variables
        and applies to all <emphasis>--trailer</emphasis> options until the next occurrence of
        <emphasis>--if-missing</emphasis> or <emphasis>--no-if-missing</emphasis>. Upon encountering '--no-if-missing,
        clear the effect of any previous use of '--if-missing, such that the relevant
        configuration variables are no longer overridden. Possible actions are <emphasis>doNothing</emphasis>
        or <emphasis>add</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--only-trailers
</term>
<listitem>
<simpara>
        Output only the trailers, not any other parts of the input.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--only-input
</term>
<listitem>
<simpara>
        Output only trailers that exist in the input; do not add any
        from the command-line or by applying <emphasis>trailer.*</emphasis> configuration
        variables.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--unfold
</term>
<listitem>
<simpara>
        If a trailer has a value that runs over multiple lines (aka "folded"),
        reformat the value into a single line.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--parse
</term>
<listitem>
<simpara>
        A convenience alias for <emphasis>--only-trailers --only-input
        --unfold</emphasis>. This makes it easier to only see the trailers coming from the
        input without influencing them with any command line options or
        configuration variables, while also making the output machine-friendly with
        --unfold.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--no-divider
</term>
<listitem>
<simpara>
        Do not treat <emphasis>---</emphasis> as the end of the commit message. Use this
        when you know your input contains just the commit message itself
        (and not an email or the output of <emphasis>git format-patch</emphasis>).
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-interpret-trailers(1)__configuration_variables">
<title>CONFIGURATION VARIABLES</title>
<variablelist>
<varlistentry>
<term>
trailer.separators
</term>
<listitem>
<simpara>
        This option tells which characters are recognized as trailer
        separators. By default only <emphasis>:</emphasis> is recognized as a trailer
        separator, except that <emphasis>=</emphasis> is always accepted on the command
        line for compatibility with other git commands.
</simpara>
<simpara>The first character given by this option will be the default character
used when another separator is not specified in the config for this
trailer.</simpara>
<simpara>For example, if the value for this option is "%=$", then only lines
using the format <emphasis>&lt;key&gt;&lt;sep&gt;&lt;value&gt;</emphasis> with &lt;sep&gt; containing <emphasis>%</emphasis>, <emphasis>=</emphasis>
or <emphasis>$</emphasis> and then spaces will be considered trailers. And <emphasis>%</emphasis> will be
the default separator used, so by default trailers will appear like:
<emphasis>&lt;key&gt;% &lt;value&gt;</emphasis> (one percent sign and one space will appear between
the key and the value).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.where
</term>
<listitem>
<simpara>
        This option tells where a new trailer will be added.
</simpara>
<simpara>This can be <emphasis>end</emphasis>, which is the default, <emphasis>start</emphasis>, <emphasis>after</emphasis> or <emphasis>before</emphasis>.</simpara>
<simpara>If it is <emphasis>end</emphasis>, then each new trailer will appear at the end of the
existing trailers.</simpara>
<simpara>If it is <emphasis>start</emphasis>, then each new trailer will appear at the start,
instead of the end, of the existing trailers.</simpara>
<simpara>If it is <emphasis>after</emphasis>, then each new trailer will appear just after the
last trailer with the same &lt;key&gt;.</simpara>
<simpara>If it is <emphasis>before</emphasis>, then each new trailer will appear just before the
first trailer with the same &lt;key&gt;.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.ifexists
</term>
<listitem>
<simpara>
        This option makes it possible to choose what action will be
        performed when there is already at least one trailer with the
        same &lt;key&gt; in the input.
</simpara>
<simpara>The valid values for this option are: <emphasis>addIfDifferentNeighbor</emphasis> (this
is the default), <emphasis>addIfDifferent</emphasis>, <emphasis>add</emphasis>, <emphasis>replace</emphasis> or <emphasis>doNothing</emphasis>.</simpara>
<simpara>With <emphasis>addIfDifferentNeighbor</emphasis>, a new trailer will be added only if no
trailer with the same (&lt;key&gt;, &lt;value&gt;) pair is above or below the line
where the new trailer will be added.</simpara>
<simpara>With <emphasis>addIfDifferent</emphasis>, a new trailer will be added only if no trailer
with the same (&lt;key&gt;, &lt;value&gt;) pair is already in the input.</simpara>
<simpara>With <emphasis>add</emphasis>, a new trailer will be added, even if some trailers with
the same (&lt;key&gt;, &lt;value&gt;) pair are already in the input.</simpara>
<simpara>With <emphasis>replace</emphasis>, an existing trailer with the same &lt;key&gt; will be
deleted and the new trailer will be added. The deleted trailer will be
the closest one (with the same &lt;key&gt;) to the place where the new one
will be added.</simpara>
<simpara>With <emphasis>doNothing</emphasis>, nothing will be done; that is no new trailer will be
added if there is already one with the same &lt;key&gt; in the input.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.ifmissing
</term>
<listitem>
<simpara>
        This option makes it possible to choose what action will be
        performed when there is not yet any trailer with the same
        &lt;key&gt; in the input.
</simpara>
<simpara>The valid values for this option are: <emphasis>add</emphasis> (this is the default) and
<emphasis>doNothing</emphasis>.</simpara>
<simpara>With <emphasis>add</emphasis>, a new trailer will be added.</simpara>
<simpara>With <emphasis>doNothing</emphasis>, nothing will be done.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.key
</term>
<listitem>
<simpara>
        Defines a &lt;keyAlias&gt; for the &lt;key&gt;. The &lt;keyAlias&gt; must be a
        prefix (case does not matter) of the &lt;key&gt;. For example, in <emphasis>git
        config trailer.ack.key "Acked-by"</emphasis> the "Acked-by" is the &lt;key&gt; and
        the "ack" is the &lt;keyAlias&gt;. This configuration allows the shorter
        <emphasis>--trailer "ack:..."</emphasis> invocation on the command line using the "ack"
        &lt;keyAlias&gt; instead of the longer <emphasis>--trailer "Acked-by:..."</emphasis>.
</simpara>
<simpara>At the end of the &lt;key&gt;, a separator can appear and then some
space characters. By default the only valid separator is <emphasis>:</emphasis>,
but this can be changed using the <emphasis>trailer.separators</emphasis> config
variable.</simpara>
<simpara>If there is a separator in the key, then it overrides the default
separator when adding the trailer.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.where
</term>
<listitem>
<simpara>
        This option takes the same values as the <emphasis>trailer.where</emphasis>
        configuration variable and it overrides what is specified by
        that option for trailers with the specified &lt;keyAlias&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.ifexists
</term>
<listitem>
<simpara>
        This option takes the same values as the <emphasis>trailer.ifexists</emphasis>
        configuration variable and it overrides what is specified by
        that option for trailers with the specified &lt;keyAlias&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.ifmissing
</term>
<listitem>
<simpara>
        This option takes the same values as the <emphasis>trailer.ifmissing</emphasis>
        configuration variable and it overrides what is specified by
        that option for trailers with the specified &lt;keyAlias&gt;.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.command
</term>
<listitem>
<simpara>
        Deprecated in favor of <emphasis>trailer.&lt;keyAlias&gt;.cmd</emphasis>.
        This option behaves in the same way as <emphasis>trailer.&lt;keyAlias&gt;.cmd</emphasis>, except
        that it doesn't pass anything as argument to the specified command.
        Instead the first occurrence of substring $ARG is replaced by the
        &lt;value&gt; that would be passed as argument.
</simpara>
<simpara>Note that $ARG in the user's command is
only replaced once and that the original way of replacing $ARG is not safe.</simpara>
<simpara>When both <emphasis>trailer.&lt;keyAlias&gt;.cmd</emphasis> and <emphasis>trailer.&lt;keyAlias&gt;.command</emphasis> are given
for the same &lt;keyAlias&gt;, <emphasis>trailer.&lt;keyAlias&gt;.cmd</emphasis> is used and
<emphasis>trailer.&lt;keyAlias&gt;.command</emphasis> is ignored.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
trailer.&lt;keyAlias&gt;.cmd
</term>
<listitem>
<simpara>
        This option can be used to specify a shell command that will be called
        once to automatically add a trailer with the specified &lt;keyAlias&gt;, and then
        called each time a <emphasis>--trailer &lt;keyAlias&gt;=&lt;value&gt;</emphasis> argument is specified to
        modify the &lt;value&gt; of the trailer that this option would produce.
</simpara>
<simpara>When the specified command is first called to add a trailer
with the specified &lt;keyAlias&gt;, the behavior is as if a special
<emphasis>--trailer &lt;keyAlias&gt;=&lt;value&gt;</emphasis> argument was added at the beginning
of the "git interpret-trailers" command, where &lt;value&gt;
is taken to be the standard output of the command with any
leading and trailing whitespace trimmed off.</simpara>
<simpara>If some <emphasis>--trailer &lt;keyAlias&gt;=&lt;value&gt;</emphasis> arguments are also passed
on the command line, the command is called again once for each
of these arguments with the same &lt;keyAlias&gt;. And the &lt;value&gt; part
of these arguments, if any, will be passed to the command as its
first argument. This way the command can produce a &lt;value&gt; computed
from the &lt;value&gt; passed in the <emphasis>--trailer &lt;keyAlias&gt;=&lt;value&gt;</emphasis> argument.</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="git-interpret-trailers(1)__examples">
<title>EXAMPLES</title>
<itemizedlist>
<listitem>
<simpara>
Configure a <emphasis>sign</emphasis> trailer with a <emphasis>Signed-off-by</emphasis> key, and then
  add two of these trailers to a commit message file:
</simpara>
<screen>$ git config trailer.sign.key "Signed-off-by"
$ cat msg.txt
subject

body text
$ git interpret-trailers --trailer 'sign: Alice &lt;alice@example.com&gt;' --trailer 'sign: Bob &lt;bob@example.com&gt;' &lt;msg.txt
subject

body text

Signed-off-by: Alice &lt;alice@example.com&gt;
Signed-off-by: Bob &lt;bob@example.com&gt;</screen>
</listitem>
<listitem>
<simpara>
Use the <emphasis>--in-place</emphasis> option to edit a commit message file in place:
</simpara>
<screen>$ cat msg.txt
subject

body text

Signed-off-by: Bob &lt;bob@example.com&gt;
$ git interpret-trailers --trailer 'Acked-by: Alice &lt;alice@example.com&gt;' --in-place msg.txt
$ cat msg.txt
subject

body text

Signed-off-by: Bob &lt;bob@example.com&gt;
Acked-by: Alice &lt;alice@example.com&gt;</screen>
</listitem>
<listitem>
<simpara>
Extract the last commit as a patch, and add a <emphasis>Cc</emphasis> and a
  <emphasis>Reviewed-by</emphasis> trailer to it:
</simpara>
<screen>$ git format-patch -1
0001-foo.patch
$ git interpret-trailers --trailer 'Cc: Alice &lt;alice@example.com&gt;' --trailer 'Reviewed-by: Bob &lt;bob@example.com&gt;' 0001-foo.patch &gt;0001-bar.patch</screen>
</listitem>
<listitem>
<simpara>
Configure a <emphasis>sign</emphasis> trailer with a command to automatically add a
  'Signed-off-by: ' with the author information only if there is no
  'Signed-off-by: ' already, and show how it works:
</simpara>
<screen>$ cat msg1.txt
subject

body text
$ git config trailer.sign.key "Signed-off-by: "
$ git config trailer.sign.ifmissing add
$ git config trailer.sign.ifexists doNothing
$ git config trailer.sign.cmd 'echo "$(git config user.name) &lt;$(git config user.email)&gt;"'
$ git interpret-trailers --trailer sign &lt;msg1.txt
subject

body text

Signed-off-by: Bob &lt;bob@example.com&gt;
$ cat msg2.txt
subject

body text

Signed-off-by: Alice &lt;alice@example.com&gt;
$ git interpret-trailers --trailer sign &lt;msg2.txt
subject

body text

Signed-off-by: Alice &lt;alice@example.com&gt;</screen>
</listitem>
<listitem>
<simpara>
Configure a <emphasis>fix</emphasis> trailer with a key that contains a <emphasis>#</emphasis> and no
  space after this character, and show how it works:
</simpara>
<screen>$ git config trailer.separators ":#"
$ git config trailer.fix.key "Fix #"
$ echo "subject" | git interpret-trailers --trailer fix=42
subject

Fix #42</screen>
</listitem>
<listitem>
<simpara>
Configure a <emphasis>help</emphasis> trailer with a cmd use a script <emphasis>glog-find-author</emphasis>
  which search specified author identity from git log in git repository
  and show how it works:
</simpara>
<screen>$ cat ~/bin/glog-find-author
#!/bin/sh
test -n "$1" &amp;&amp; git log --author="$1" --pretty="%an &lt;%ae&gt;" -1 || true
$ cat msg.txt
subject

body text
$ git config trailer.help.key "Helped-by: "
$ git config trailer.help.ifExists "addIfDifferentNeighbor"
$ git config trailer.help.cmd "~/bin/glog-find-author"
$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" &lt;msg.txt
subject

body text

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Helped-by: Christian Couder &lt;christian.couder@gmail.com&gt;</screen>
</listitem>
<listitem>
<simpara>
Configure a <emphasis>ref</emphasis> trailer with a cmd use a script <emphasis>glog-grep</emphasis>
  to grep last relevant commit from git log in the git repository
  and show how it works:
</simpara>
<screen>$ cat ~/bin/glog-grep
#!/bin/sh
test -n "$1" &amp;&amp; git log --grep "$1" --pretty=reference -1 || true
$ cat msg.txt
subject

body text
$ git config trailer.ref.key "Reference-to: "
$ git config trailer.ref.ifExists "replace"
$ git config trailer.ref.cmd "~/bin/glog-grep"
$ git interpret-trailers --trailer="ref:Add copyright notices." &lt;msg.txt
subject

body text

Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)</screen>
</listitem>
<listitem>
<simpara>
Configure a <emphasis>see</emphasis> trailer with a command to show the subject of a
  commit that is related, and show how it works:
</simpara>
<screen>$ cat msg.txt
subject

body text

see: HEAD~2
$ cat ~/bin/glog-ref
#!/bin/sh
git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14
$ git config trailer.see.key "See-also: "
$ git config trailer.see.ifExists "replace"
$ git config trailer.see.ifMissing "doNothing"
$ git config trailer.see.cmd "glog-ref"
$ git interpret-trailers --trailer=see &lt;msg.txt
subject

body text

See-also: fe3187489d69c4 (subject of related commit)</screen>
</listitem>
<listitem>
<simpara>
Configure a commit template with some trailers with empty values
  (using sed to show and keep the trailing spaces at the end of the
  trailers), then configure a commit-msg hook that uses
  <emphasis>git interpret-trailers</emphasis> to remove trailers with empty values and
  to add a <emphasis>git-version</emphasis> trailer:
</simpara>
<screen>$ cat temp.txt
***subject***

***message***

Fixes: Z
Cc: Z
Reviewed-by: Z
Signed-off-by: Z
$ sed -e 's/ Z$/ /' temp.txt &gt; commit_template.txt
$ git config commit.template commit_template.txt
$ cat .git/hooks/commit-msg
#!/bin/sh
git interpret-trailers --trim-empty --trailer "git-version: \$(git describe)" "\$1" &gt; "\$1.new"
mv "\$1.new" "\$1"
$ chmod +x .git/hooks/commit-msg</screen>
</listitem>
</itemizedlist>
</simplesect>
<simplesect id="git-interpret-trailers(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-commit(1)" />, <xref linkend="git-format-patch(1)" />, <xref linkend="git-config(1)" /></simpara>
</simplesect>
<simplesect id="git-interpret-trailers(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
