How can I change the default comments in the git commit message?
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).
Here is a python git-hook to clean up the default message. Hook name: prepare-commit-msg
.
#!/usr/bin/env python
import sys
commit_msg_file_path = sys.argv[1]
with open(commit_msg_file_path, 'a') as file:
file.write('')
You can simply add you text in the file.write()
method.
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.