How to Write a Multi-line Git Commit Message
Passing -m twice, as in git commit -m "subject" -m "body", creates a two-paragraph commit message with a blank line between the subject and the body. This is a way to write the reason for a change or additional notes in the commit body with a single command, without opening an editor. Other options are to put line breaks inside the quotes, to read from a file or standard input with -F, or to write in an editor. I ran the git commands in a test environment and show the output as it appeared.
The test environment was Ubuntu 24.04, Git 2.43.0, and bash 5.2.21. I set the author name and email to example values (Neko <neko@example.com>). I did not test Windows Command Prompt, PowerShell, other shells such as zsh, or editors such as VS Code.
- 1. Repository before the operation
- 2. Passing -m two or more times to split the subject and body
- 3. Writing \n inside -m does not produce a line break
- 4. Pressing Enter before closing the quote to break the line
- 5. \n becomes a line break inside $'…'
- 6. Reading from a file or standard input with -F
- 7. Writing in an editor without -m
- 8. Lines starting with # are kept when using -m
- 9. Without a blank line after the subject, the second line becomes part of the subject
- 10. History after the operations
Repository before the operation
I started with a repository called neko-app, which had one commit with a single-line message.
$ git log
commit 7e817a63371d430dfe4dbdc35561d1ed25cafea8
Author: Neko <neko@example.com>
Date: Thu Nov 12 09:50:00 2026 +0900
トップページを作る
Passing -m two or more times to split the subject and body
I added style.css and committed with -m passed three times.
$ git status --short
A style.css
$ git commit -m "文字の色を決める" -m "本文の文字を濃い灰色にした。" -m "見出しの色は次のコミットで決める。"
[main 6a7e8c5] 文字の色を決める
1 file changed, 1 insertion(+)
create mode 100644 style.css
With git log -1, the first -m became the subject, and the second and third became paragraphs separated by blank lines.
$ git log -1
commit 6a7e8c5ce18bdc5be3e8c74660f70d9d7a971cae
Author: Neko <neko@example.com>
Date: Thu Nov 12 10:10:00 2026 +0900
文字の色を決める
本文の文字を濃い灰色にした。
見出しの色は次のコミットで決める。
The official reference for -m also says that when -m is given more than once, each value is joined as a separate paragraph. A blank line is always inserted between -m values. If you want lines in the body without a blank line between them (such as a bulleted list), use the quoted multi-line form or -F described below. Writing \n inside -m does not work.
Writing \n inside -m does not produce a line break
When I wrote \n inside the -m string, it was not converted to a line break. It was recorded as the two characters \n.
$ git commit -q -m "見出しの色を決める\n\n水色にした。"
$ git log -1 --format=%B
見出しの色を決める\n\n水色にした。
--format=%B is a format that shows the subject and body as they are. Whether \n becomes a line break is decided by how the shell parses the string, not by git. Here I undid this commit with git reset --soft HEAD~1 and redid it with the method below.
Pressing Enter before closing the quote to break the line
In bash, if you press Enter before closing a double quote ("), the command is not run, and input continues on the next line. A > is shown at the start of continuation lines. I wrote the subject, pressed Enter, pressed Enter on an empty line, wrote the body, and closed the quote with ". The line breaks were kept as they were in the message.
$ git commit -q -m "見出しの色を決める
>
> 見出しを濃い水色にした。"
$ git log -1 --format=%B
見出しの色を決める
見出しを濃い水色にした。
The > is a prompt from the shell and is not part of the message.
\n becomes a line break inside $'…'
In bash, if you enclose the text in $'...', \n inside it becomes a line break. Because it fits on one line, this form is also convenient in scripts.
$ git commit -q -m $'日記を1件書く\n\n晴れの日の記録を足した。'
$ git log -1 --format=%B
日記を1件書く
晴れの日の記録を足した。
Reading from a file or standard input with -F
For a long message or a list, you can write it to a file and pass it with -F.
$ cat ../msg.txt
日記をもう1件書く
- 雨の日の記録を足した
- 段落は p 要素で分けた
$ git commit -q -F ../msg.txt
$ git log -1 --format=%B
日記をもう1件書く
- 雨の日の記録を足した
- 段落は p 要素で分けた
As described in the official reference for -F, passing - instead of a file name reads from standard input. Combined with a bash here-document, you can write the message without creating a file. MSG is the delimiter; the message ends just before the line that contains only MSG.
$ git commit -q -F - <<'MSG'
フッターの文字を小さくする
12px にした。
MSG
$ git log -1 --format=%B
フッターの文字を小さくする
12px にした。
Writing in an editor without -m
If you run git commit without -m or -F, an editor opens. The official reference's section on environment and configuration variables says the editor is chosen in this order: the GIT_EDITOR environment variable, the core.editor setting, the VISUAL environment variable, then EDITOR.
For the test, I set GIT_EDITOR to a script (../editor.sh) that displays the contents of the file it is given, then prepends the following four lines and one blank line. The first line starts with # on purpose.
# Note: this line will disappear
タイトルを付ける
title 要素を足した。
The editor was given a file containing lines that start with #.
$ GIT_EDITOR=../editor.sh git commit -q
----- File passed to the editor -----
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Changes to be committed:
# modified: index.html
#
----- End here -----
$ git log -1 --format=%B
タイトルを付ける
title 要素を足した。
In a normal editor, you would write the subject on the first line of this file, leave one blank line, write the body, then save and close. The comment lines and the # メモ line I added were both removed from the message.
Lines starting with # are kept when using -m
The # lines that were removed in the editor were kept when I passed the message with -m.
$ git commit -q -m "日記を1件書く" -m "#3 のくもりの日の分。"
$ git log -1 --format=%B
日記を1件書く
#3 のくもりの日の分。
According to the official reference for --cleanup, when nothing is specified, lines starting with # are removed if the message is edited in an editor (strip). Otherwise, only leading and trailing blank lines and trailing whitespace are tidied (whitespace).
Without a blank line after the subject, the second line becomes part of the subject
I made a two-line message without a blank line between the subject and the body.
$ git commit -q -m $'リンクの色を決める\nピンクにした。'
$ git log --oneline -1
f786f05 リンクの色を決める ピンクにした。
$ git log -1 --format=%s
リンクの色を決める ピンクにした。
$ git log -1 --format=%b
Both git log --oneline and the subject %s show the second line joined with a space. The body %b was empty. The official reference says that the text up to the first blank line is treated as the subject (title), and that Git uses it in many places. The same section recommends keeping the subject to a short single line of 50 characters or fewer, and writing the detailed explanation after a blank line.
History after the operations
Looking at the commits above with git log --oneline, each subject appears on its own line. For commits written with a blank line between the subject and body, only the subject is shown. Only the last commit, which had no blank line, shows its second line.
$ git log --oneline
f786f05 リンクの色を決める ピンクにした。
c7b3429 日記を1件書く
cfa57c8 タイトルを付ける
7f9274d フッターの文字を小さくする
0adcc78 日記をもう1件書く
afb61a0 日記を1件書く
eed4696 見出しの色を決める
6a7e8c5 文字の色を決める
7e817a6 トップページを作る





