yarun can yarun can - 1 year ago 42
Git Question

Preparing a git commit messaging before committing?

Is it possible to prepare a commit message prior to a commit, meaning that I will type my commit message before the actual commit or during the working dir so that I know what I am working on and I know what this branch or commit will be all about. When I say "before" I do not mean just couple secs before I enter the commit on the commandline. I literally mean right after a commit or at the starting of a branch so that the next commit will automatically inherit the message in the queue or what ever that might be called.

Naturally I can put these messages during the commit, to me there is a difference. And I can see the argument of well git is not meant for that as well. I am just curious about it.

I also know I can give my branches more meaningful names but I just want a bit space for such purpose.

thanks

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download