'Git commit -m with multiple line
How do I produce a multiline comment in my git commit using -m
$ git commit -m "This change is for blah"
$ git commit -m "This change is for blah\nAnd also for this blah"
The second line, the \n doesn't produce a multiline comment
I'm using Mac terminal, not sure if that matter.
Solution 1:[1]
In many environments (MacOS included) you can just hit enter to end the first line, as long as the quotes for the message are still open.
git commit -m "this is
a multiline
message"
Another option is to compose the message in a file and use -F. (This is a more scriptable alternative to letting a text editor open for the commit message.)
The "multiple -m option' approach others are suggesting kinda-sorta works, but puts blank lines between the messages in my tests.
Solution 2:[2]
Consider using --file instead of -m. You can prepare the message in a file and then commit like this:
git commit --file=../commit_message
Solution 3:[3]
If you just use
git commit
It will open your editor and allow you to add more complex commit messages.
If you use
git commit -m "This is for blah" -m "This is more text"
it should commit several lines of text.
Solution 4:[4]
This depends on your shell, most shells have a process-C-escapes marker. bash and I think many others use $''.
git commit -m subject -m $'this\nhas\nexplicit\nlinebreaks'
Just a note, git log can do word wrapping for you anyway, try
git log --pretty='%h%+w(76,6,9)%B'
for starters.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Romain Valeri |
| Solution 2 | Peter Evselyev |
| Solution 3 | Kenny Grant |
| Solution 4 | jthill |
