Koxzi
Koxzi

Reputation: 1051

What is a convenient way of writing a multiline commit message?

Rather than write a short, 40-character Git commit message, I would like to write a longer, multiline message.

As I understand it, I'd need to add a newline after the message 'title'. How can I enter a newline in OS X Terminal or in Win8 CMD?

Upvotes: 3

Views: 2192

Answers (3)

R. Gulde
R. Gulde

Reputation: 1

For multi line commit messages I prefer to use a file with the -F CommitMsgFile. In the file I suggest referencing your bug/ticket thus: CommitMsgFile: BugName(IA-4) Detail of what was fixed (2-3 lines). Test notes, or link to documents/rational if exceptionally hard bug only.

result: $git commit -F CommitMsgFile (msg about commit)

See how it keeps the format etc in the commit message: $git log -1 Author: name Date: date info

BugName(IA-4) Detail of what was fixed (2-3 lines). Test notes, or link to documents/rational if exceptionally hard bug only.

Upvotes: 0

jub0bs
jub0bs

Reputation: 66183

You seem to think (your follow-up comment confirms this) that

git commit -m "<msg>"

is the only way of creating a commit. The git-commit man page describes the -m flag thus:

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

This flag allows you to write the commit message inline; it is convenient for short (i.e. typically one-line) commit messages, but not so much for longer ones. For multi-line commit messages, you should eschew the -m flag and simply run

git commit

This will cause your editor to pop up and allow you to write and format your commit message in a much more convenient fashion than at the command line.

I refer you to the relevant section of the Pro Git Book for more details.

Upvotes: 6

Francis Colas
Francis Colas

Reputation: 3647

If you don't put the -m flag, you'll be prompted to enter the message in your default editor, where you can easily enter many lines.

Upvotes: 1

Related Questions