Home > Mobile >  how to add new empty-lines in a one-line compact command of git commit message using -m
how to add new empty-lines in a one-line compact command of git commit message using -m

Time:12-20

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. E.g.:

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

CodePudding user response:

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

CodePudding user response:

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

CodePudding user response:

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

  • Related