Squash merge: "---------" separator before Co-authored-by pushes trailers in the PR description out of git's trailer block #212929
Replies: 2 comments
|
Thank you for your interest in contributing to our community! We currently only accept discussions created through the GitHub UI using our provided discussion templates. Please re-submit your discussion by navigating to the appropriate category and using the template provided. This discussion has been closed because it was not submitted through the expected format. If you believe this was a mistake, please reach out to the maintainers. |
|
Hi, I can reproduce the logic from your description, and I'm not aware of a repository setting that removes the 1. Edit the commit message in the merge dialog Before clicking "Confirm squash and merge", edit the message so the PR trailers and the co-author lines sit together in the final paragraph: GitHub may still append its own co-author block, so after merging check the result. This is manual, so it doesn't scale for a team. 2. Make the tooling not depend on git's trailer parser If release tools, changelog generators or commit checks only need the work item reference, read it in a way that survives the separator: # plain text match on the whole message
git log -1 --format=%B | grep -E '^Ref:'
# or take the reference from the PR instead of the commit
gh pr view 1 --json body --jq .body | grep -E '^Ref:'For CI checks, validate the PR description via the API before merge, since that is where the author wrote the trailer. 3. Put the trailer where the parser looks Some teams put required trailers in the PR title or in the first lines of the description (as 4. Change the merge strategy for multi-author PRs
Both change your history shape, so they may not fit a squash-only policy. 5. Post-merge fix (last resort) Rewriting a merged commit on a protected default branch isn't appropriate, so I'd avoid it. Normalizing the message in the tooling (option 2) is safer. 6. Report it as feedback This discussion is marked Closed, so it may not be read by the product team. The suggestion is clear and well-argued, so consider posting it again in the Community feedback category with the Product Feedback template, and include the exact before/after message. Your proposed fix (append co-authors to an existing trailer block, or add a setting to omit the separator) is a concrete request they can act on. |
Uh oh!
There was an error while loading. Please reload this page.
What is happening
When a pull request is squash-merged with the default commit message "Pull request
title and description" and the PR has commits from more than one author, GitHub
appends the co-authors as a separate paragraph after a "---------" line:
git only reads the last paragraph of a message as its trailer block. Any trailer
written at the end of the PR description (here
Ref:, but alsoSigned-off-by:,Reviewed-by:,Fixes:etc.) is therefore no longer a trailer:Listing the co-author in the description directly under
Ref:does not help:GitHub appends its own block anyway and the co-author appears twice.
Steps to reproduce
title and description".
a trailer, e.g.
Ref:AB#123.gh pr merge --squash).git interpret-trailers --parseon the merge commit.Expected
The description's trailers and the co-authors end up in one trailer block, e.g.
Why it matters
Teams that squash-merge put work item references and other trailers in the PR
description because it becomes the commit message. Release tooling, changelog
generators and commit checks read them with git's trailer parsing
(
%(trailers),git interpret-trailers). As soon as a PR has a co-author, thosetrailers silently disappear from the history.
Suggestion
If the generated message already ends with a trailer block, append the
Co-authored-by lines to that block instead of adding "---------" and a new
paragraph. Alternatively, a repository setting to omit the separator.
All reactions