Appearance
Git Trailers Quick Reference
Parse trailers
git log -1 --format="%B" | git interpret-trailers --parse
# Conditional CI skip
skip=$(git log -1 --format="%(trailers:key=CI-Skip,valueonly)")
test "$skip" = "true" && exit 0
# Single-key extract
git log -1 --format="%(trailers:key=Reviewed-by,valueonly)"
# All format placeholders (Git 2.44+)
%(trailers:key=K,valueonly) # just the value
%(trailers:key=K,separator=%n) # multi-value newline separator
%(trailers:only) # entire trailer blockAdd trailers at commit
git commit -m "msg" --trailer "Signed-off-by: A <a@b>"
git commit -m "msg" --trailer "Key: Val1" --trailer "Key: Val2"
git commit --amend --trailer "Reviewed-by: alice" --no-editAdd trailers after commit
git interpret-trailers --in-place --trailer "Release-Phase: staging" HEAD
git interpret-trailers --in-place --trailer "Fixes: #42" HEADConfig keys
[trailer "ChangeId"]
key = Change-Id
command = echo "I$(uuidgen | tr -d -)"
[trailer "Reviewed-by"]
where = before
ifexists = addIfDifferentNeighbor| Config | Values |
|---|---|
trailer.where | after, before, end, start |
trailer.ifexists | addIfDifferent, addIfDifferentNeighbor, add, replace, doNothing |
trailer.ifmissing | add, doNothing |
DevOps one-liners
DCO pre-receive check:
author=$(git log -1 --format="%aN <%aE>")
sob=$(git log -1 --format="%(trailers:key=Signed-off-by,valueonly)" | head -1)
test "$author" != "$sob" && exit 1Backport stamp:
git cherry-pick -x $SHA
git commit --amend --trailer "Backport-Source: $SHA" --no-editChangelog extract:
git log $FROM..$TO --format="%(trailers:key=Release-Notes,valueonly)" | grep -v '^$'Pitfalls
- Blank line before trailer block is required
%(trailers: ...)format needs Git 2.44+--in-placeonly edits the working message file, not the SHA