Git - Do colours mean something in vi when I commi

2019-03-17 09:52发布

问题:

I'm using Git Bash on Windows and, when I run git commit, the vi editor opens to allow me writing a Commit note. I noticed that the first row of the text I write is yellow (although not all of it, only the first 30 or 40 characters), the second is white on a red background and from the 3rd onwards they are gray. Does this colour coding mean anything, or is it just some sort of weird glitch? I come from an SVN background, where Commit comment was pure text and I wasn't expecting this "rainbow". :)

Thanks in advance for the answers.

回答1:

Vi is giving you a hint about "properly" formatting your commit message.

While there is no specific enforcement of one message style w.r.t. another, "traditionally" Git commit messages are structured this way:

  • A short title describing the changeset (usually less than 50-60 characters);
  • One blank line;
  • A more complete description of the commit, optionally divided in paragraphs with other blank lines.

The last paragraph is usually used for "metadata" entries, like Signed-off-by:.

So, in your case, Vi is probably warning you that the first line is a a little longer than usual and that you did not leave a blank line after it (I say "probably" because I do not use Vi, so I am not sure about it).