skip to content

What are Git commit trailers, and how do Signed-off-by and Co-authored-by get added?

level: middleimportance: should knowfreq 38%

answer

  1. shaped like email headers
  2. position in the message matters
  3. one flag writes one of them for you
  4. not the same as a cryptographic signature
  5. a plumbing command edits them safely

basics

~20 s

Trailers are Token: value lines in the last paragraph of a commit message, giving it machine-readable metadata. git commit -s adds a Signed-off-by line from your committer identity, and git interpret-trailers or git commit --trailer adds arbitrary ones such as Co-authored-by.

solid answer

~50 s

A trailer is a `Token: value` line in the **final paragraph** of a commit message, the same shape as an email header. Git parses that block so tools can read structured metadata without inventing a side channel. `git commit -s` (or `--signoff`) appends `Signed-off-by: Name <email>` built from your configured `user.name` and `user.email`. `Co-authored-by: Name <email>` is a convention for crediting a second person on one commit; Git stores the text and tooling that cares reads it. `git interpret-trailers` is the plumbing that adds, replaces or lists trailers correctly — it knows where the trailer block starts and respects `trailer.*` config — and recent Git also accepts `git commit --trailer "Token: value"` directly. To read them back, use a pretty format such as `%(trailers:key=Signed-off-by)`. The placement rule matters: a `Token: value` line stranded in the middle of the body is not a trailer.

code

bash · 3 lines
bash
git commit -s -m "Fix retry accounting"
git log -1 --format='%(trailers:key=Signed-off-by)'
git interpret-trailers --trailer "Co-authored-by: Grace <[email protected]>" --in-place .git/COMMIT_EDITMSG

go deeper

for a junior

Know that trailers are Token: value lines at the end of a commit message and that git commit -s adds a Signed-off-by line using your configured name and email.

for a middle

Explain the last-paragraph placement rule, the difference between -s and -S, and that git interpret-trailers is the tool that adds or replaces trailers correctly.

for a senior

Show how you would consume them in practice — trailer-aware log formats rather than grep — and argue for a small vocabulary of tokens someone actually reads instead of ceremonial noise.

for a principal

Decide what metadata belongs in the commit at all versus in a tracker or a review system, knowing trailers travel with the commit through patches and rebases while external records do not.

## What a trailer is A commit message is free text, but teams constantly want structured facts attached to a commit: who reviewed it, who co-wrote it, which ticket it belongs to, that someone certified its origin. Git's answer is the **trailer**: a line of the form `Token: value` in the last paragraph of the message. ``` Fix retry accounting in the payment client The loop ran one attempt too many. Signed-off-by: Ada Lovelace <[email protected]> Co-authored-by: Grace Hopper <[email protected]> Refs: PROJ-142 ``` The shape is deliberately email-header-like, because Git's culture grew around mailed patches and this block survives `git format-patch` and `git am` intact. ## The placement rule Only the **last** paragraph is scanned. A `Reviewed-by:` line in the middle of a prose body is not a trailer — it is prose that happens to contain a colon. The block must be separated from the rest of the body by a blank line, and it should consist of trailer lines (a continuation line indented under a trailer is allowed). Getting this wrong is the usual reason a tool "does not see" a trailer that is visibly present in the message. ## Signed-off-by `git commit -s` appends `Signed-off-by: <name> <email>` using your committer identity from `user.name` and `user.email`. Mechanically that is all it is: a text line, not a cryptographic signature. Do not confuse it with `git commit -S`, which creates a real cryptographic signature over the commit object — a different mechanism entirely, verified with different tooling. A sign-off asserts something about the author's claim regarding the change; the specific policy meaning depends on the project that asks for it. ## Co-authored-by `Co-authored-by: Name <email>` records that more than one person wrote a commit — useful for pairing, since a commit object has room for exactly one author field. Git stores and parses the line like any other trailer; whether it produces visible credit anywhere else depends on the tools reading the history. Add it manually in the editor, with `git commit --trailer "Co-authored-by: Grace Hopper <[email protected]>"` in recent Git, or through `git interpret-trailers`. ## git interpret-trailers This is the plumbing command for manipulating the trailer block, and its value is that it knows the placement rules so you do not have to do string surgery: - `git interpret-trailers --trailer "Reviewed-by: Ada <[email protected]>" --in-place <file>` adds a trailer to a message file, creating the block if needed. - `--only-trailers` prints just the trailer block from a message on stdin. - `--parse` normalises the output into one trailer per line, convenient for scripts. - `--if-exists` and `--if-missing` control what happens when the token is already present — add another, replace, or do nothing. Configuration lives under `trailer.*`: `trailer.separators` defines which characters count as the separator, and per-token settings such as `trailer.<token>.key` (a canonical spelling to insert) and `trailer.<token>.ifExists` let you define shorthand tokens for a repository. Because it reads a message on stdin or in a file, it is the natural tool for a `commit-msg` hook that needs to inject a trailer automatically. ## Reading trailers back The pretty-format placeholder `%(trailers)` prints the block; it takes arguments, so `git log --format='%(trailers:key=Co-authored-by,valueonly)'` extracts just the values for one token. That is how you answer questions like "which commits credit this person as a co-author" without regex-scraping whole messages — the parser respects the placement rule, a grep does not. ## Why they matter Trailers are the sanctioned way to attach facts to a commit without inventing a parallel database. They travel with the commit through `format-patch`, `am`, `cherry-pick` and rebase, because they are just message text. They are also cheap to abuse: a trailer block of fifteen tokens on every commit becomes noise, and a trailer nobody reads is dead weight. Add tokens that someone or something actually consumes. ## Interview framing Define the shape and the last-paragraph rule, name `-s` as the built-in for sign-off, separate it clearly from `-S` cryptographic signing, and mention `git interpret-trailers` as the correct tool rather than hand-editing. That combination shows you know trailers are a parsed structure, not a stylistic habit.

  • What is the difference between git commit -s and git commit -S?
    `-s` (`--signoff`) appends a plain-text `Signed-off-by:` trailer built from your configured name and email — anyone can type the same line. `-S` creates a cryptographic signature over the commit object, which can be verified against a key. They look adjacent on the command line and do completely different things: one is a message convention, the other is a security mechanism.
  • Why might a tool fail to see a trailer that is clearly present in the message?
    Because trailers are only recognised in the final paragraph. A `Reviewed-by:` line followed by more prose, or one embedded mid-body, is ordinary text as far as the parser is concerned. `git interpret-trailers` exists precisely to place lines correctly, and `git log --format='%(trailers)'` shows you what Git actually parsed.
  • How do you list every commit that credits a particular co-author?
    Use the trailer-aware pretty format rather than grepping the message: `git log --format='%H %(trailers:key=Co-authored-by,valueonly)'` prints the parsed values per commit, which you can filter. The advantage over a plain `--grep` is that it applies the placement rules, so prose that merely resembles a trailer does not match.

saying these in an interview costs you the question

  • Confuses Signed-off-by with a cryptographic signature
  • Puts trailers in the middle of the message body
  • Thinks Git enforces which trailer tokens are allowed
  • Believes -s signs the commit with a key
  • Says a commit can record two authors in the author field

context