Preparing a git commit message before committing?
Solution 1:
Git can take the commit message from a file using the -F
or --file
flags:
git commit -F message.txt
You can prepare your message in advance in a text file and use that file when you commit.
If you do this often, it makes sense to create an alias for it, for example:
done = commit -F message.txt
So that you can simply type git done
to have it always use your text file.
If you make a mistake and commit too fast without updating the message file, not a problem, you can just do git commit --amend
and fix the message in the commit.
UPDATE
The -e
flag is useful too, as it lets you edit the message before committing:
git commit -eF message.txt
Solution 2:
If using the --file
option for git commit
you can pipe in the message through the standard input by using dash (-
) instead of a file name.
echo "Classy commit message" | git commit --file -
Solution 3:
If you're using VIM as Git's core editor, then when you run git commit
, VIM will be opened and you'll be presented with a buffer containing the commented-out output of the git status
command.
You can then use the VIM command :read COMMIT_MSG.txt
which will insert the contents of the file COMMIT_MSG.txt
(your pre-pared commit message) at the current cursor location.
This is really just an alternative to running git commit -eF COMMIT_MSG.txt
, but I personally find it easier to remember the VIM command :read
as opposed to having to remember yet another git command line argument. Personal preference, really.