Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add line break to 'git commit -m' from the command line

Tags:

git

bash

shell

I am using Git from the command line and am trying to add a line break to the commit message (using git commit -m "") without going into Vim.

Is this possible?

like image 901
Alan Whitelaw Avatar asked Feb 21 '11 10:02

Alan Whitelaw


People also ask

How do I add a new line to a commit message?

- Fixed a bug Another method of adding a multi-line Git commit message is using quotes with your message, though it depends on your shell's capacity. To do this, add single or double quotes before typing the message, keep pressing enter and writing the next line, and finally close the quote at end of the message.

What is the Git commit command?

The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to.


2 Answers

Certainly, how it's done depends on your shell. In Bash, you can use single quotes around the message and can just leave the quote open, which will make Bash prompt for another line, until you close the quote. Like this:

git commit -m 'Message  goes here' 

Alternatively, you can use a "here document" (also known as heredoc):

git commit -F- <<EOF Message  goes here EOF 
like image 169
Simon Richter Avatar answered Oct 08 '22 08:10

Simon Richter


If you just want, say, a head line and a content line, you can use:

git commit -m "My head line" -m "My content line." 

Note that this creates separate paragraphs - not lines. So there will be a blank line between each two -m lines, e.g.:

My head line  My content line. 
like image 34
Simon Avatar answered Oct 08 '22 08:10

Simon