Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add multiple lines to git commit messages [duplicate]

Tags:

git

How do I add multi-line messages using

git commit -a -m "..."

The answer from this similar question appears to work (judging by the upvotes and acceptance), but it seems a bit cumbersome1.

The git documentation reads:

-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.

So, would it be advisable to just use a new -m for each new line of the message? Or do "paragraphs" add additional line spacings?

It would be nice if future versions of the command would allow us to just add \n between sentences, to denote line breaks.

1 The linked answer basically advises to use a message template file, and direct git to use the file via git commit -t <template_file>

like image 772
Blair Fonville Avatar asked Jan 24 '18 20:01

Blair Fonville


1 Answers

The answer may depend on what shell you use to run git. For example with bash (just tested this on windows using the bash shell installed with git):

git commit -m "this is
a multi-line
message"

because quite simply bash will not assume that hitting return ends the command if it's in the middle of a quoted string.

That said, I've only ever used -m for one-line messages; other options just "make more sense" to me if I need a multi-line message.

like image 127
Mark Adelsberger Avatar answered Oct 22 '22 22:10

Mark Adelsberger