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

2019-01-05 07:02发布

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?

标签: git bash shell
14条回答
相关推荐>>
2楼-- · 2019-01-05 07:04

I hope this isn't leading too far away from the posted question, but setting the default editor and then using

git commit -e

might be much more comfortable.

查看更多
【Aperson】
3楼-- · 2019-01-05 07:05

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 line

  • git commit -m "Hello Enter idem

  • git commit -m "Hello^ Enter idem

  • git commit -m 'Hello^ Enter World' looks like working because it asks "More?" and allows to write a new line, but finally when doing git 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.

查看更多
趁早两清
4楼-- · 2019-01-05 07:07

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 and EDITOR.

That's what I have in my .bashrc:

export ALTERNATE_EDITOR=''
export EDITOR='emacsclient -t'
export VISUAL='emacsclient -c'
export SUDO_EDITOR='emacsclient -t'
查看更多
一纸荒年 Trace。
5楼-- · 2019-01-05 07:08

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 doing git commit --amend right after git commit.

查看更多
干净又极端
6楼-- · 2019-01-05 07:09

In Bash/Zsh you can simply use literal line breaks inside quotes:

git commit -m 'Multi-line
commit
message'

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:

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order). See git-var for details.

查看更多
狗以群分
7楼-- · 2019-01-05 07:09

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."
查看更多
登录 后发表回答