how can I customize git's merge commit message?
I'm aware this isn't answering the original question, but for the benefit of git noobs like myself who reach this page because it's currently the first Google result for "git change merge commit message", I'll mention that it is possible to:
git commit --amend -m"New commit message"
to change the commit message of a merge commit without losing the link to any of the parents of the merge commit.
Looks like as of version Git 1.7.8 you can do git merge --edit ...
to specify the commit message.
And as of 1.7.10, dropping into edit mode will be the default behavior
From this release on, the "git merge" command in an interactive session will start an editor when it automatically resolves the merge for the user to explain the resulting commit, just like the "git commit" command does when it wasn't given a commit message.
(though I'm not seeing it on in msysgit on windows).
I've found there are two ways for solving this problem
note: don't use both at the same time, as if the commit fails to merge it will add the log again to the bottom.
personal note: I'm using the first solution as it relies entirely on git's hooks and config properties, instead of an external script.
For a real solution one would have to extend a git command named 'fmt-merge-msg' that generates the oneline descriptions when passing the --log option (if you really need this solution you'll have to create your own patch (for git) and compile it from source).
1. using prepare-commit-message as VonC suggested
this solution has the problem that you need to interrupt the commit and then commit manually
setting an alias that will build the desired commit message:
[alias]
lm = log --pretty=format:'%s%n by %C(yellow)%an%Creset (%ad)%n %n%b' --date=local
creating the prepare-commit-msg hook by creating an executable prepare-commit-msg in $GIT_DIR/hooks/ (example script below)
#!/bin/sh
#...
case "$2,$3" in
merge,)
echo "Merge details:" >> $1
echo "" >> $1
git lm ORIG_HEAD..MERGE_HEAD >> "$1" ;;
*) ;;
esac
one should define an alias commit msg such as
[alias]
m = merge --no-ff --no-commit
2. using a custom command that will generate the merge automatically
(using the lm alias created in 1.)
#!/bin/sh
echo ""
echo "merge with commit details -- HEAD..$1"
git merge --no-ff --no-log -m "`git lm HEAD..$1`" --no-commit $1
and then execute a rather rigid command:
./cmd-name <branch to merge>
if you still wish to have the oneline description of the commits you'll need to add new commands or whatever to the -m argument (if you use --log then it will be generated on the bottom)