0

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!

muel
  • 43
  • 1
  • 13

3 Answers3

3

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

lzhh
  • 852
  • 7
  • 16
  • Excellent dude! Your method 2, is another possible solution i was looking for. thanks so much! – muel Dec 20 '21 at 20:25
2

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
joanis
  • 10,635
  • 14
  • 30
  • 40
1

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
phd
  • 82,685
  • 13
  • 120
  • 165
  • thank you dude. i knew it but the problem about your solution is that it places new empty lines between body-lines too. and that's not pleasant by me. – muel Dec 19 '21 at 16:22