tags:

views:

44

answers:

2

Is it possible to modify the commented part of the default git commit message? I want to add a bit more 'context' information for my users.

# Please enter the commit message for your changes.
# (Comment lines starting with '#' will not be included)
# Explicit paths specified without -i nor -o; assuming --only paths...
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   test.txt
#
+5  A: 

You can use git hooks for that. Before the person who wants to commit the changes is shown the commit message, the prepare-commit-msg script is run.

You can find an example prepare-commit-msg script in .git/hooks.

To edit the default message create a new file called prepare-commit-msg in the .git/hooks folder. You can edit the commit message by using a script like this:

#!/bin/sh
echo "#Some more info...." >> $1

The $1 variable stores the file path to the commit message file.

I knew it was possible. I read about it somewhere and couldn't find this any more. Thanks!
zedoo
Just beware that hooks don't get added to the repo. When this repo is cloned somewhere else, you'll have to set up the hook again.
Bryce
+4  A: 

There is commit.template configuration variable, which according to git-config(1) manpage:

Specify a file to use as the template for new commit messages. "~/" is expanded to the value of $HOME and "~user/" to the specified user's home directory.

You can put it in per-repository (.git/config), user's (~/.gitconfig) and system (/etc/gitconfig) configuration file(s).

Jakub Narębski