10

I just read Writing good commit messages and liked it a lot. The problem is, I prefer the command line (plain ole' git).

  • How can I add newlines and tabs to commit messages, so as to have a "summary line" and message body (which may consist of several paragraphs)?
  • Does GitHub support markdown in their commit messages? After reading "Shiny new commit styles" this doesn't seem possible
smeeb
  • 27,777
  • 57
  • 250
  • 447

3 Answers3

14

git automatically spawns your preferred $EDITOR to prompt for a commit message when you run git commit. So it may be as simple as leaving -m off of your git commit command

If git launches the wrong editor, or fails to launch an editor, try setting the EDITOR environment variable to your preferred editor:

export EDITOR=/usr/bin/vim

Or, to only change the editor used by git, you can set core.editor

git config --global core.editor /usr/bin/vim

Using an editor to compose a commit message this way has a couple of further advantages. Git populates the file you are editing with a summary of the files that were changed in the commit, which should help you write a better commit message. Also, vim (and other editors) support basic syntax highlighting for this kind of file, making it even easier.

ComputerDruid
  • 16,897
  • 1
  • 19
  • 28
5
  1. For newline, just hit enter inside quotes, like this: git commit -m "Some headline <hit enter>. Also you can use your text editor to write commit messages.

  2. Unfortunately no, e.g. this commit with markdown for example.

Community
  • 1
  • 1
Tomas Votruba
  • 23,240
  • 9
  • 79
  • 115
  • 12
    It's worth noting that if a commit on GitHub with Markdown formatting (like the one you've linked to) is submitted as a pull request, the text of the commit message is used as the PR's text, which does render GitHub-Flavored-Markdown. Also, there are a couple of Git clients (not-GitHub-specific) here & there that'll render Markdown commit messages. _I personally write all my commit messages in Markdown— since a couple `**`s or a few lines starting with `* ` can go a long way to convey meaning. And MD (by design) never looks too grody when displayed as plaintext._ – Slipp D. Thompson Jul 22 '16 at 04:02
  • @SlippD.Thompson : BitBucket also uses the commit message to prefill the PR message. – Sebastian Wagner Nov 07 '17 at 10:18
0

When creating a git commit, you can use -m multiple times and it will create multiple paragraphs.

To quote the man page

-m <msg>, --message=<msg>

Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs

Also, as mentioned before, if you leave out the -m option, then git will open an editor (set with a command like git config --global core.editor /usr/bin/vim) in which you can type your commit message.