git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] templates: detect messages that contain a separator line

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 7, 2026, 21:27 UTC
Message-ID
<xmqqldh4b5y2.fsf@gitster.g>
In-Reply-To
<83c100a73ec722bf72a15b7b40b0c82bf8829168.1770476279.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 14 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Messages that contain "---" separator lines will be truncated by
> "git am". This often surprises users so add a check to the sample
> "commit-msg" hook to reject such messages. As it's conceivable that
> someone is using "---" as their comment string we delete any commented
> lines before checking for a separator. The trailing ".*" when matching
> commented lines ensures that if the comment string ends with a "$"
> it is not treated as an anchor.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  templates/hooks/commit-msg.sample | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

I have no qualms about the topic up to the previous step, but I know one of the things that I sometimes do will be broken with the change in this step, namely, when I know what I want to write below the three-dash lines, I would commit with "---" and additional notes below it, so that I do not forget during "format-patch".

When the commit is turned into a patch email, possibly with some other material like "--notes=<ref>" that adds notes there, the resulting message will have two three-dashes lines, but because "am" cuts at the first one, and "apply" knows that the garbage lines at front, including three-dash lines, do not matter until it sees "^diff", this works out perfectly well.

Admittedly, I myself do not send out so many patches as I used to, but I suspect that there are others who have discovered this trick independently, and they would be unhappy to be interrupted by commit-msg hook like this.

A saving grace is that when the user is stopped with this, pre-commit hook that inspects the contents to be committed have already run successfully, so rerunning with "--no-verify" is not with too much risk. But still, I am not sure if this is a good thing to do overall.

Show 22 quoted lines
> diff --git a/templates/hooks/commit-msg.sample b/templates/hooks/commit-msg.sample
> index 099cc58c303..c7a9db88cb9 100755
> --- a/templates/hooks/commit-msg.sample
> +++ b/templates/hooks/commit-msg.sample
> @@ -39,9 +39,16 @@ comment_re="$(
>  		}'
>  )"
>  line="$(sed -n -e "/^${comment_re} -\{8,\} >8 -\{8,\}\$/q
> +		   /^${comment_re}.*/d
> +		   /^---\$/{p;q;}
>  		   /^diff -/{p;q;}
>  		   /^Index: /{p;q;}" "$1")"
> -if test -n "$line"
> +if test "$line" = "---"
> +then
> +	echo >&2 "Message contains a '---' separator line that will confuse"
> +	echo >&2 "'git am'. To fix this indent the '---' line."
> +	ret=1
> +elif test -n "$line"
>  then
>  	echo >&2 "Message contains a diff that will confuse 'git am'."
>  	echo >&2 "To fix this indent the diff."
Previous: Phillip WoodNext: Kristoffer Haugsbakk
Message 9 of 65 in “git-am applies commit message diffs”
  1. Matthias BeyerFeb 6, 2026
  2. Jacob KellerFeb 6, 2026
  3. Matthias BeyerFeb 6, 2026
  4. Jeff KingFeb 6, 2026
  5. 0/3 commit-msg.sample: reject messages that would confuse "git am"Phillip Wood, Feb 7, 2026
  6. 1/3 templates: add .gitattributes entry for sample hooksPhillip Wood, Feb 7, 2026
  7. 2/3 templates: detect commit messages containing diffsPhillip Wood, Feb 7, 2026
  8. 3/3 templates: detect messages that contain a separator linePhillip Wood, Feb 7, 2026
  9. Junio C HamanoFeb 7, 2026
  10. Kristoffer HaugsbakkFeb 7, 2026
  11. Junio C HamanoFeb 9, 2026
  12. Jeff KingFeb 9, 2026
  13. Phillip WoodFeb 9, 2026
  14. Jeff KingFeb 10, 2026
  15. Jeff KingFeb 9, 2026
  16. Phillip WoodFeb 9, 2026
  17. Matthias BeyerFeb 9, 2026
  18. Jeff KingFeb 10, 2026
  19. Patrick SteinhardtFeb 9, 2026
  20. Jacob KellerFeb 10, 2026
  21. Patrick SteinhardtFeb 10, 2026
  22. Junio C HamanoFeb 10, 2026
  23. Jacob KellerFeb 11, 2026
  24. Jacob KellerFeb 11, 2026
  25. Jeff KingFeb 11, 2026
  26. Kristoffer HaugsbakkFeb 11, 2026
  27. Junio C HamanoFeb 11, 2026
  28. Jeff KingFeb 10, 2026
  29. 0/2 commit-msg.sample: reject messages that would confuse "git am"Phillip Wood, Feb 13, 2026
  30. 1/2 templates: add .gitattributes entry for sample hooksPhillip Wood, Feb 13, 2026
  31. 2/2 templates: detect commit messages containing diffsPhillip Wood, Feb 13, 2026
  32. Kristoffer HaugsbakkFeb 13, 2026
  33. Junio C HamanoFeb 13, 2026
  34. Phillip WoodFeb 14, 2026
  35. Junio C HamanoFeb 13, 2026
  36. Phillip WoodFeb 14, 2026
  37. Junio C HamanoFeb 14, 2026
  38. Junio C HamanoFeb 13, 2026
  39. Florian WeimerFeb 6, 2026
  40. Jeff KingFeb 6, 2026
  41. Florian WeimerFeb 6, 2026
  42. Jeff KingFeb 6, 2026
  43. Kristoffer HaugsbakkFeb 6, 2026
  44. Jakob HaufeFeb 6, 2026
  45. Kristoffer HaugsbakkFeb 7, 2026
  46. Kristoffer HaugsbakkFeb 7, 2026
  47. doc: add caveat about roundtripping format-patchkristofferhaugsbakk@fastmail.com, Feb 8, 2026
  48. Junio C HamanoFeb 8, 2026
  49. Kristoffer HaugsbakkFeb 8, 2026
  50. Phillip WoodFeb 9, 2026
  51. Kristoffer HaugsbakkFeb 9, 2026
  52. Phillip WoodFeb 10, 2026
  53. Kristoffer HaugsbakkFeb 10, 2026
  54. doc: add caveat about roundtripping format-patchkristofferhaugsbakk@fastmail.com, Feb 9, 2026
  55. Junio C HamanoFeb 9, 2026
  56. Kristoffer HaugsbakkFeb 9, 2026
  57. Phillip WoodFeb 10, 2026
  58. Kristoffer HaugsbakkFeb 10, 2026
  59. doc: add caveat about round-tripping format-patchkristofferhaugsbakk@fastmail.com, Feb 12, 2026
  60. Junio C HamanoFeb 12, 2026
  61. Phillip WoodFeb 13, 2026
  62. Kristoffer HaugsbakkFeb 13, 2026
  63. Junio C HamanoFeb 13, 2026
  64. Christoph Anton MittererFeb 10, 2026
  65. Kristoffer HaugsbakkFeb 10, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.