我正在从命令行使用Git,并试图在提交消息中添加换行符(使用Git commit -m "")而不进入Vim。
这可能吗?
我正在从命令行使用Git,并试图在提交消息中添加换行符(使用Git commit -m "")而不进入Vim。
这可能吗?
当前回答
在Git提交中添加换行符
尝试以下命令创建多行提交消息:
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 log -1
你应该得到这样的结果:
截图来自我使用PowerShell和Poshgit创建的一个示例。
这适用于所有终端和操作系统AFAIK。
下面是bash的示例:
导致这个提交:
其他回答
就我个人而言,我发现在vi(或任何你选择的git编辑器)中修改提交消息比在命令行中更容易,在git提交后立即执行git commit——modify。
没有必要把事情复杂化。在-m "文本之后…下一行是通过按Enter得到的。当按下回车键时,出现>。当你完成后,只需输入“”并按Enter:
$ 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 ...
(编辑05-05-2021)
对于Windows用户,请使用GitBash For Windows。内置的Windows cmd不适用此方法。
在Git提交中添加换行符
尝试以下命令创建多行提交消息:
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 log -1
你应该得到这样的结果:
截图来自我使用PowerShell和Poshgit创建的一个示例。
这适用于所有终端和操作系统AFAIK。
下面是bash的示例:
导致这个提交:
我一直在寻找这个问题的答案,因为我曾经多次看到用于检查提交消息的正则表达式。无论如何,在使用-m标志创建提交时,没有任何想法可以工作。
因此,实现多行提交消息的最简单方法是在终端中只输入git commit。 然后,你将有机会输入你想要的笔记:
不需要更复杂的方法了。
如果您使用Bash,点击C-x C-e (Ctrl+x Ctrl+e),它将在您首选的编辑器中打开当前命令。
您可以通过调整VISUAL和editor来更改首选编辑器。
这就是我的。bashrc文件:
export ALTERNATE_EDITOR=''
export EDITOR='emacsclient -t'
export VISUAL='emacsclient -c'
export SUDO_EDITOR='emacsclient -t'