1

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 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent dude! Your method 2, is another possible solution i was looking for. thanks so much!
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

1 Comment

Excellent! that is the solution i was looking for. thanks so much!
2

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 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.