Last Updated: February 25, 2016
·
27.88K
· diogoandre

Multi-line Git commit message from CLI

Providing a good commit message improves collaboration by making easier to others understand what you did and your motivations.

The ProGit book provides a nice explanation of how a commit message should be formatted:

As a general rule, your messages should start with a single line that’s no more than about 50 characters and that describes the changeset concisely, followed by a blank line, followed by a more detailed explanation.

Here are a few options to create multi-line commit messages from the command line (besides the obvious git commit -e:

Most systems should allow you to use multiple -m options, each one will become a separate line in you commit message:

   ➜ savana git:(master) ✗ git commit -m 'Adding giraffes' -m 'Giraffes are really interesting animals'
git log
commit 228e689c246c0092b4201bc0c7cbde38a92d094b
Author: Diogo André <diogo@regattapix.com>
Date:   Mon Apr 8 08:11:01 2013 -0300

    Adding giraffes

    Giraffes are really interesting animals

Second option is to just hit return within a single-quoted commit message:

➜ savana git:(master) ✗ git commit -m 'Adding giraffes 
quote> Giraffes are really interesting animals'
git log
commit 228e689c246c0092b4201bc0c7cbde38a92d094b
Author: Diogo André <diogo@regattapix.com>
Date:   Mon Apr 8 08:11:01 2013 -0300

    Adding giraffes
    Giraffes are really interesting animals

Notice that no extra line between the 'title' and the 'body' will was added in this case.

And last, but not least, you can use a $ sign in *nix environments to tell the shell to evaluate new line characters within your string:

➜ savana git:(master) ✗ git commit -m $'Adding giraffes\n\nGiraffes are really interesting animals'
git log
commit 228e689c246c0092b4201bc0c7cbde38a92d094b
Author: Diogo André <diogo@regattapix.com>
Date:   Mon Apr 8 08:11:01 2013 -0300

    Adding giraffes

    Giraffes are really interesting animals

Hope it helps! :)

1 Response
Add your response

yes, it helped ;-) (especially solution 3) .. Thank you

over 1 year ago ·