Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preparing a git commit message before committing?

Tags:

git

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.

like image 873
yarun can Avatar asked Dec 07 '13 06:12

yarun can


People also ask

What should be the first commit message in git?

Usually the first commit is named "Initial commit". As best practice its include a README file describing the project. The README is usually is a md file.


2 Answers

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 
like image 147
janos Avatar answered Sep 24 '22 22:09

janos


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 - 
like image 24
Maic López Sáenz Avatar answered Sep 24 '22 22:09

Maic López Sáenz