我正在从命令行使用Git,并试图在提交消息中添加换行符(使用Git commit -m "")而不进入Vim。
这可能吗?
我正在从命令行使用Git,并试图在提交消息中添加换行符(使用Git commit -m "")而不进入Vim。
这可能吗?
当前回答
在我看来,最初的提交信息行应该是简短的,而不是一段一段的。所以使用 Git commit -m "<short_message>" 就足够了
在此之后,为了扩展我们可以使用的初始提交消息
Git提交—修改
这将打开vim,然后我们可以输入提交消息的解释,在我看来,这比命令行更容易。
其他回答
如果您使用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'
我希望这不会偏离发布的问题太远,而是设置默认编辑器,然后使用
git commit -e
可能会舒服得多。
比如
git commit -m"test\ntest"
这并不奏效,但就像
git commit -m"$(echo -e "test\ntest")"
有用,但不是很漂亮。你在PATH中设置了一个git- commitb命令,它是这样做的:
#!/bin/bash
message=$1
git commit -m"$(echo -e "$message")"
像这样使用它:
git commitlb "line1\nline2\nline3"
提醒一下,我感觉一般惯例是第一行是摘要行,然后是两个换行符,然后是提交消息中的扩展消息,所以这样做会打破惯例。你当然可以:
git commitlb "line1\n\nline2\nline3"
就我个人而言,我发现在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不适用此方法。