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?
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?
I hope this isn't leading too far away from the posted question, but setting the default editor and then using
might be much more comfortable.
Here is a list of failing solutions on Windows with standard cmd.exe shell (to save you some trial-and-error time!):
git commit -m 'Hello
Enter doesn't work: it won't ask for a new linegit commit -m "Hello
Enter idemgit commit -m "Hello^
Enter idemgit commit -m 'Hello^
EnterWorld'
looks like working because it asks "More?" and allows to write a new line, but finally when doinggit log
you will see that it's still a one-line message...TL;DR: Even if on Windows, commandline parsing works differently, and
^
allows multiline input, it doesn't help here.Finally
git commit -e
is probably the best option.If you are using Bash, hit
C-x C-e
(Ctrl+x Ctrl+e), and it will open the current command in your preferred editor.You can change the preferred editor by tweaking
VISUAL
andEDITOR
.That's what I have in my
.bashrc
:Personally, I find it easiest to modify commit messages after the fact in
vi
(or whatever your git editor of choice is) rather than on the command line, by doinggit commit --amend
right aftergit commit
.In Bash/Zsh you can simply use literal line breaks inside quotes:
ANSI-C quoting also works in Bash/Zsh:
git commit -m $'Multi-line\ncommit\nmessage'
You can also instruct Git to use a different editor. From the docs on git-commit:
If you just want, say, a head line and a content line, you can use: