The Co-authored-by:/Signed-off-by: handler.
Reads or injects structured trailers (the Key: value lines at the bottom of commit messages, like Signed-off-by: or Co-authored-by:). The canonical tool for scripting trailer policy.
A commit message is subject\n\nbody\n\ntrailers. interpret-trailers is a parser/editor for that last block and nothing else - it never touches subject or body.
git interpret-trailers [<options>] [--parse] [<file>...]
# Add trailers (reads message from stdin, writes to stdout):
git interpret-trailers --trailer "Signed-off-by: A <a@x>" < msg.txt
# Edit a file in place:
git interpret-trailers --in-place --trailer "Acked-by: B <b@y>" msg.txt
# Just list existing trailers:
git interpret-trailers --parse < msg.txt
git log -1 --format=%B | git interpret-trailers --only-trailers --parse| Flag | What it does |
|---|---|
--trailer <key>=<value> | Trailer to add (also accepts Key: value form) |
--in-place | Rewrite the input file instead of writing to stdout |
--if-exists=<action> | addIfDifferent | addIfDifferentNeighbor | add | replace | doNothing |
--if-missing=<action> | add | doNothing |
--no-divider | Don't treat --- as the end of the message (for git am-style input) |
--parse | Equivalent to --only-trailers --only-input --unfold |
--only-trailers | Output only the trailer block, not the rest of the message |
prepare-commit-msg hook that auto-appends Signed-off-by: for the current user.Reviewed-by: trailer.git filter-repo to add a Change-Id:.git log output for changelog generation.git interpret-trailers --trailer "Signed-off-by: $(git config user.name) <$(git config user.email)>" --in-place msg.txtgit interpret-trailers --if-exists=doNothing --trailer 'Co-authored-by: X <x@y>' --in-place msg.txtgit log -1 --format=%B | git interpret-trailers --parsegit interpret-trailers --if-exists=replace --trailer 'Reviewed-by: New <n@x>' --in-place msg.txttrailer.<token>.key, .ifExists, .ifMissing in git config to set per-trailer defaults instead of repeating flags.commit-msg hooks for policy, not in prepare-commit-msg if you want users to see/edit the trailer.--parse --only-trailers for clean machine-readable output.--trailer key=value and --trailer 'key: value' both work, but = is friendlier in shell scripts.--if-exists is addIfDifferentNeighbor, which can produce duplicate trailers separated by other trailers.Hit each option, then Check answers. Score is recorded; Next is always open.