Search code examples
gitcommitgit-commitcommit-message

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


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!


Solution

  • 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