Progress:
TIER 2 · MODULE 50· Intermediate

git interpret-trailers

The Co-authored-by:/Signed-off-by: handler.

🎯 What & why

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.

🧠 Mental model

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.

🛠️ Synopsis

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

🎚️ Switches & options

FlagWhat it does
--trailer <key>=<value>Trailer to add (also accepts Key: value form)
--in-placeRewrite the input file instead of writing to stdout
--if-exists=<action>addIfDifferent | addIfDifferentNeighbor | add | replace | doNothing
--if-missing=<action>add | doNothing
--no-dividerDon't treat --- as the end of the message (for git am-style input)
--parseEquivalent to --only-trailers --only-input --unfold
--only-trailersOutput only the trailer block, not the rest of the message

💡 Use cases

🧪 Examples

Add a sign-off
git interpret-trailers --trailer "Signed-off-by: $(git config user.name) <$(git config user.email)>" --in-place msg.txt
Add only if missing
git interpret-trailers --if-exists=doNothing --trailer 'Co-authored-by: X <x@y>' --in-place msg.txt
List trailers of HEAD
git log -1 --format=%B | git interpret-trailers --parse
Replace existing trailer
git interpret-trailers --if-exists=replace --trailer 'Reviewed-by: New <n@x>' --in-place msg.txt

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.