You just use the following command:
$ git commit -m "1. what i changed
> 2. blank line
> 3. why i changed"
In your terminal, just hit 'enter' for a new line. The commit message won't end until you add the closing quote. The git log will look like:
$ git log
commit abcde2f660c707br2d20411581c4183170c3p0c2
Author: Alex Pan <[email protected]>
Date: Tue Apr 28 20:52:44 2015 -0700
1. what i changed
2. blank line
3. why i changed
Answer from Alex Pan on Stack OverflowYou just use the following command:
$ git commit -m "1. what i changed
> 2. blank line
> 3. why i changed"
In your terminal, just hit 'enter' for a new line. The commit message won't end until you add the closing quote. The git log will look like:
$ git log
commit abcde2f660c707br2d20411581c4183170c3p0c2
Author: Alex Pan <[email protected]>
Date: Tue Apr 28 20:52:44 2015 -0700
1. what i changed
2. blank line
3. why i changed
Use two --message/-m options, first one for the subject and second one for the body.
Excerpt from documentation:
-m <msg> --message=<msg>Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.
In your case it does exactly what you want, inserts a blank line between first and second lines.
git commit -m "Subject: what I changed" -m "Body: why I changed it"
This is useful if you want to amend previously added comment.
Looking for some advice here.
I have done a lot of reading on writing good git commit messages. Use imperative mood, 50 characters max for the first line, capitalize the first letter, no period at the end, etc. These make sense and I follow all these guidelines.
The one thing I don't really do is commit often. That's because I am working alone, mainly on my dotfiles and scripts. I understand if you are writing a piece of software or doing web dev, you should commit often, but for me that seems overkill. Should I really git commit if I just change something as simple as hex code for a background? I don't think so.
What I have been doing is writing multi-line commits.
For example (without hyphens):
-
Create directory if it doesn't exist
-
Fix bug in script
-
Remove unused aliases
-
Change background colour to orange
I figure this is better than a single message saying something like... "Minor changes", which is discouraged.
On Github, the first line will be shown as the commit message with 3 dots or ellipsis at the end. If you press the dots, it shows the remaining 3 lines. I could just do it all in one line, but then it will wrap at the character limit, and not look very nice. I think in-line messages look far better, even if you can't see it all at once.
What is your opinion?
bash - How to add line break to 'git commit -m' from the command line? - Stack Overflow
Can you create a multi-line commit?
Git commit accepts several message flags (-m) to allow multiline commits
Pasting multiple lines into commit summary field executes commands
Videos
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
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.