Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I use an editor for Git commit messages?

Tags:

git

I get the feeling almost everybody uses an editor (Vim, Notepad++, etc.) for the Git commit messages. Why?

I find typing -m and a couple of quotes is easy and provides a easy way to redo a commit (pressing up arrow). I guess it's easier to do multi-line commit messages in an editor, but I have a hard enough time convincing fellow co-workers to write any message!

like image 748
Lachlan Avatar asked Aug 16 '10 21:08

Lachlan


People also ask

Why is it important to use a descriptive commit message with a standardized format in git?

Well-crafted commit messages are the best way to communicate why the commit was necessary, giving some context to the code changes. Commit messages are also very handy when looking over recent changes to the code base. Commit messages can give you a quick idea of what has changed recently.

Can you edit git commit message?

You can change the most recent commit message using the git commit --amend command. In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID--i.e., the SHA1 checksum that names the commit. Effectively, you are creating a new commit that replaces the old one.


2 Answers

You mentioned the most important thing - length. Commit messages should essentially always be multi-line. The only exceptions are trivial commits (e.g. "bumped version number to X.X.X") or merges with no conflicts (though even then, appending a shortlog isn't a bad idea). The average commit, as far as such a thing exists, should probably have a sentence or two beyond the subject; some could even have paragraphs. Just look at the log of git.git; it's pretty much guaranteed to be a good example of commit message style and length.

I realize that it may be hard to convince others to write good commit messages, but that doesn't mean you can't - and you will probably find it easier to use an editor to write them.

(I have exactly the same experience in my workplace. My coworkers are engineers first, programmers second, and version control users... third would be generous. But you can at least do your job right!)

like image 120
Cascabel Avatar answered Sep 23 '22 00:09

Cascabel


A proper git commit message should almost always be multi-line. From the official git-commit discussion,

Though not required, it's a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. Tools that turn commits into email, for example, use the first line on the Subject: line and the rest of the commit in the body.

If you're having a hard time getting any commit messages, (talk to your sysadmin and/or) make sure that at least one of the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable is set to something useful.

An option would be to create your own 'editor', which prompts for a short (<50 chars) description, and then a minimum number of characters or sentences. This might not be well received, but that would depend on your position and the culture of your work environment.

like image 45
Kevin Vermeer Avatar answered Sep 26 '22 00:09

Kevin Vermeer