How add new empty-lines in the message of one-line command "git commit -m"

2.3k Views Asked by At

If I want to not use any text editor and put all the commit message including subject and body lines into the useful one-line command:

$ git commit -m 'message including subject and body lines'

, I need to insert first body-line two lines after subject and the next lines just at the next new line.

For example:

feat: Derezz the master control program

  • MCP turned out to be evil and had become intent on world domination.
  • This commit throws Tron's disc into MCP.

So I tried to use "\n" but didn't solve the problem!

3

There are 3 best solutions below

1
joanis On BEST ANSWER

If you're working in Bash (on Linux or in Git Bash on Windows), then you can use the $'...' syntax from Bash, which lets you use \n and other escape sequences:

$ git commit -m $'message subject\n\nmessage body'

will create a commit with message

message subject

message body
1
phd On

You can use -m multiple times:

git commit -m 'message including subject' -m 'and body lines'

Every -m text separated with an empty line so this command will produce

message including subject

and body lines
1
lxvs On

Method 1:

git commit -m "title" -m "A paragraph." -m "Another paragraph."

Method 2:

git commit -m "title

A paragraph.

Another paragraph."

They have exactly the same outcome. Note that in the 2nd method you need to punch Enter twice at the end of each line (except the last one).