7

I'm commiting to git using git commit -m 'commit message', but this only has the short description. How would I add the more detailed description using git bash?

Jimmt
  • 852
  • 2
  • 11
  • 29
  • Why doesn't that work for longer messages? – Thilo Sep 29 '13 at 05:45
  • I'm not saying it doesn't, but I didn't know you could have multiple options – Jimmt Sep 29 '13 at 05:45
  • Possible duplicate of [Add line break to git commit -m from command line](http://stackoverflow.com/questions/5064563/add-line-break-to-git-commit-m-from-command-line) –  Mar 29 '14 at 12:53

6 Answers6

7

You can specify multiple -m options:

git commit -m 'foo bar' -m 'baz qux'

git log will show multiple paragraphs:

commit ...
Author: ...
Date:   ...

    foo bar

    baz qux
SheetJS
  • 22,470
  • 12
  • 65
  • 75
  • 1
    Clever, but not the best solution, as soon as you start having to use multiple lines, you're better off just opening up the commit dialog in an editor like vim. –  Mar 29 '14 at 12:50
7

How about this?

git commit -F - <<EOF
summary

This is
a multi-line
commit message.
EOF
FelipeC
  • 9,123
  • 4
  • 44
  • 38
7

Did you know you can just type git commit and it will pop open an editor for you to write your commit message in?

You can control which editor it is with some configuration. By default, Git will look at $GIT_EDITOR, then the core.editor configuration variable, then $VISUAL, and finally $EDITOR. You can look at the git-var man page for the search order, and the git-config has a little information in the core.editor section as well.

John Szakmeister
  • 44,691
  • 9
  • 89
  • 79
2

You can store the long commit message in a file and specify the filename instead of the message in your command. So the command will look like-

  git commit -F <path/to/file>

Reference: https://www.kernel.org/pub/software/scm/git/docs/git-commit.html

Hope this helps!

1

From man git commit:

-m <msg>, --message=<msg>
Use the given <msg> as the commit message.
If multiple -m options are given, their values
are concatenated as separate paragraphs.

In other words, this would work:

git commit -m "Subject" -m "paragraph 1" -m "paragraph 2"
mvp
  • 111,019
  • 13
  • 122
  • 148
0

You take the commit message from a file if the commit message is too long

-F "file", --file="file" Take the commit message from the given file. Use - to read the message from the standard input.

Shunya
  • 2,785
  • 2
  • 18
  • 17