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

Re: How do I control the automated commit message on a merge?

From
Stephan Beyer <s-beyer@gmx.net>
Date
Jun 4, 2008, 07:33 UTC
Message-ID
<20080604073317.GA7752@leksak.fem-net>
In-Reply-To
<bd2cb52a0806031705x7cc153bsc00e1a0198d6e7b5@mail.gmail.com>
Hi,
Show 11 quoted lines
> >> when Git does a merge (no conflicts), it auto-generates a commit message
> >> like:
> >>
> >>         Merge branch 'master' of  /path/to/other/repo
> >>
> >> How can I change this so my required string gets written at the
> >> beginning of the commit message.
> >
> > s/./?/
> 
> Where do I do the substitution in this case?

In the question that you sent to the list ;-) (But something like s/\./?/ makes more sense.)

The real answer of Johannes to your question was only:
> You might be happy with a post-merge hook amending the commit with a
> completely different message.
Meaning, you should put something like
 #!/bin/sh
 git commit -m "This is my new commit message." --amend
or better:
 #!/bin/sh
 git commit --amend -m "$(git cat-file commit HEAD |
 	sed -e '1,/^$/d;s/^/YOUR SIMPLE STATIC STRING HERE\n\n/')"
into .git/hooks/post-merge (and make it executable).
YOUR SIMPLE STATIC STRING HERE is the new first line.
Replace the \n\n by a space to get someting like
"YOUR SIMPLE STATIC STRING HERE Merge foo into HEAD."
> Also, having the prepare-commit-msg hook add text had the side-effect
> that in my normal commits, the message was always accepted, even when
> I wanted to abort (vi using :q!).
Let the commit-msg hook add the text afterwards.

Or remove the prepared commit message in vi and then press :x (or :wq), because commit aborts on an *empty* commit message and not on an unchanged commit message.

Regards,
  Stephan
-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F
Previous: Marvin Fraeman
Message 4 of 4 in “How do I control the automated commit message on a merge?”
  1. Marvin FraemanJun 3, 2008
  2. Johannes SchindelinJun 3, 2008
  3. Marvin FraemanJun 4, 2008
  4. Stephan BeyerJun 4, 2008

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.