Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit -m with multiple line

Tags:

git

How do I produce a multiline comment in my git commit using -m

$ git commit -m "This change is for blah"
$ git commit -m "This change is for blah\nAnd also for this blah"

The second line, the \n doesn't produce a multiline comment

I'm using Mac terminal, not sure if that matter.

like image 837
RonPringadi Avatar asked Dec 06 '25 14:12

RonPringadi


2 Answers

In many environments (MacOS included) you can just hit enter to end the first line, as long as the quotes for the message are still open.

git commit -m "this is
a multiline
message"

Another option is to compose the message in a file and use -F. (This is a more scriptable alternative to letting a text editor open for the commit message.)

The "multiple -m option' approach others are suggesting kinda-sorta works, but puts blank lines between the messages in my tests.

like image 139
Mark Adelsberger Avatar answered Dec 09 '25 04:12

Mark Adelsberger


If you just use

git commit

It will open your editor and allow you to add more complex commit messages.

If you use

git commit -m "This is for blah" -m "This is more text" 

it should commit several lines of text.

like image 29
Kenny Grant Avatar answered Dec 09 '25 03:12

Kenny Grant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!