The easiest way to do it is to run git commit
without -m
and the message.
(git commit -a
is a shortcut for git add -u; git commit
, with some other minor technical differences)
It will start an editor where you can enter the commit message on multiple lines. Then you save the file and when the editor exits, git commit
continues and uses the message from the file.
If you prefer to do everything from a single command (or you write a script that needs to call git commit
and this interactive way of committing is not an option) then you can provide the commit subject and the commit message body by using the -m
argument two times:
git commit -m "this is the subject" -m "this is the body"
Using -m
multiple times in the command line concatenates the messages as separate paragraphs (separated by an empty line). This works perfectly to provide the subject as the argument of the first -m
and the message body as the argument of the second -m
.
There is no easy way to embed newlines in the commit message body. Using three or more times the -m
option will produce a commit message that contains empty lines and this is probably not what you want.
If you are on Linux
or macOS
and you shell of choice is bash
then there is an ugly but working way to write a message body that contains new lines. Embed each line in quotes ("
) to allow them contain spaces and join the lines with $'\n'
which is the bash
way of writing special characters in the command line (or in a script).
The command looks like this:
git commit -m "the subject" -m "the first line"$'\n'"the second line"$'\n'"the third line"