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

Re: Proposal: Allow Customization of Git Merge Commit Message Template

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Dec 5, 2024, 23:16 UTC
Message-ID
<Z1I0XzE6QWlsyZkH@tapette.crustytoothpaste.net>
In-Reply-To
<DM4PR14MB4880061D71993B749F44F2EDA7302@DM4PR14MB4880.namprd14.prod.outlook.com>
On 2024-12-05 at 17:00:56, dangling . wrote:
Show 9 quoted lines
> Proposal:
> Introduce an option (e.g., a configuration setting or CLI flag) that allows users to specify a custom merge commit message template. For example:
> 
> - A new configuration option:
>   ```sh
>   [merge]
>       messageTemplate = "Merge %s into %s"
>   ```
>   Here, `%s` placeholders could represent the source and destination branches, respectively.

I think in general that such an option would need multiple placeholders. Just because in English we place the name of the second head before the name of the first head does not mean that that is true in all languages or translations.

> - Alternatively, a command-line flag:
>   ```sh
>   git merge --message-template="Merge %s into %s" upstream/main
>   ```

I think this can be done more generally with a `prepare-commit-msg` hook:

---- #!/bin/sh

COMMIT_MSG_FILE=$1 COMMIT_SOURCE=$2

case "$COMMIT_SOURCE" in
 merge)
   /usr/bin/perl -i.bak -pe '
   s/Merge remote-tracking branch '\''(.*)'\''/Merge $1/
   ' "$COMMIT_MSG_FILE"
   ;;
 *) ;;
esac
----

That's the approach we would generally recommend here, since it's more flexible and allows you more customization over the message. Of course, you can use sed or Ruby instead (or even ed or ex) if you prefer.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Previous: dangling .
Message 2 of 2 in “Proposal: Allow Customization of Git Merge Commit Message Template”
  1. dangling .Dec 5, 2024
  2. brian m. carlsonDec 5, 2024

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.