git commit -m "Demonstrate multi-line commit message in Powershell" -m "Add a title to your commit after -m enclosed in quotes,
then add the body of your comment after a second -m.
Press ENTER before closing the quotes to add a line break.
Repeat as needed.
Then close the quotes and hit ENTER twice to apply the commit."
$ git commit -m "Another way of demonstrating multicommit messages:
>
> This is a new line written
> This is another new line written
> This one is really awesome too and we can continue doing so till ..."
$ git log -1
commit 5474e383f2eda610be6211d8697ed1503400ee42 (HEAD -> test2)
Author: ************** <*********@gmail.com>
Date: Mon Oct 9 13:30:26 2017 +0200
Another way of demonstrating multicommit messages:
This is a new line written
This is another new line written
This one is really awesome too and we can continue doing so till ...
19
如果您正在使用Bash,请按 C-x C-e (Ctrl x Ctrl e),它将在首选编辑器中打开当前命令 .
14 回答
当然,它是如何完成的取决于你的shell . 在Bash中,您可以在消息周围使用单引号,并且可以保持报价打开,这将使Bash提示另一行,直到您关闭报价 . 像这样:
或者,您可以使用“此处文档”:
使用Bash命令行中的Git,您可以执行以下操作:
只需键入并在需要新行时按Enter键,">"符号表示您已按Enter键,并且有一个新行 . 其他答案也有效 .
如果你只想要一条头条和一条内容,你可以使用:
你应该可以使用
来自Bash manual:
这包括对上述新行的支持,以及十六进制和Unicode代码等 . 转到链接部分以查看反斜杠转义字符的列表 .
Adding line breaks to your Git commit
请尝试以下操作以创建多行提交消息:
然后验证你做了什么:
你应该得到这样的东西:
截图来自我使用PowerShell和Poshgit设置的示例 .
做点什么
不起作用,但有点像
有效,但不是很漂亮 . 你在
PATH
中设置一个git-commitlb
命令,它执行如下操作:并像这样使用它:
警告的话,我有一种感觉,即一般惯例是将摘要行作为第一行,然后是两个换行符,然后是提交消息中的扩展消息,因此这样做会破坏该约定 . 你当然可以这样做:
我希望这不会过于远离发布的问题,但是setting the default editor然后使用
可能会更舒服 .
来自Git documentation:
所以,如果你正在寻找分组多个提交消息,这应该做的工作:
我在Mac上使用zsh,我可以在双引号(“)中发布多行提交消息 . 基本上我一直在键入并按回新行,但是在我关闭引号并返回之前,消息不会发送到Git .
没有必要使这些东西复杂化 . 在
-m "text...
之后,按Enter键获取下一行 . 按Enter键时,出现>
. 完成后,只需输入"
并按Enter键:如果您正在使用Bash,请按
C-x C-e
(Ctrl x Ctrl e),它将在首选编辑器中打开当前命令 .您可以通过调整
VISUAL
和EDITOR
来更改首选编辑器 .这就是我在_1453740中所拥有的:
在Bash / Zsh中,您只需在引号内使用文字换行符:
ANSI-C quoting也适用于Bash / Zsh:
git commit -m $'Multi-line\ncommit\nmessage'
您还可以指示Git使用不同的编辑器 . 来自git-commit上的文档:
就个人而言,我发现最简单的方法是在
vi
(或者你选择的任何git编辑器)之后修改提交消息,而不是在命令行上,通过在git commit
之后执行git commit --amend
.以下是Windows上带有标准cmd.exe shell的失败解决方案列表(为了节省一些试错时间!):
git commit -m 'Hello
输入don 't work: it won' t要求换行git commit -m "Hello
输入同一性git commit -m "Hello^
输入同一性git commit -m 'Hello^
输入World'
看起来像是在工作,因为它要求"More?"并允许写一个新行,但最后在做git log
时你会发现它仍然是一行消息......TL; DR:即使在Windows上,命令行解析工作differently,
^
允许多行输入,它也无济于事这里 .最后git commit -e可能是最好的选择 .