Sim*_*ter 637
当然,它是如何完成的取决于你的shell.在Bash中,您可以在消息周围使用单引号,并且可以保持报价打开,这将使Bash提示另一行,直到您关闭报价.像这样:
git commit -m 'Message
goes
here'
Run Code Online (Sandbox Code Playgroud)
或者,您可以使用"此处文档":
git commit -F- <<EOF
Message
goes
here
EOF
Run Code Online (Sandbox Code Playgroud)
Sim*_*mon 454
如果你只想要一条头条和一条内容,你可以使用:
git commit -m "My head line" -m "My content line."
Run Code Online (Sandbox Code Playgroud)
ess*_*sse 386
使用Bash命令行中的Git,您可以执行以下操作:
git commit -m "this is
> a line
> with new lines
> maybe"
Run Code Online (Sandbox Code Playgroud)
只需键入并Enter在需要新行时按下Enter,">"符号表示您已按下,并且有一个新行.其他答案也有效.
Pau*_*ce. 102
你应该可以使用
git commit -m $'first line\nsecond line'
Run Code Online (Sandbox Code Playgroud)
从Bash手册:
$' string ' 形式的单词是专门处理的.单词扩展为 字符串,替换为ANSI C标准指定的反斜杠转义字符.
这包括对上述新行的支持,以及十六进制和Unicode代码等.转到链接部分以查看反斜杠转义字符的列表.
Jon*_*ell 87
在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."
Run Code Online (Sandbox Code Playgroud)
然后验证你做了什么:
git log -1
Run Code Online (Sandbox Code Playgroud)
你应该得到这样的东西:
截图来自我使用PowerShell和Poshgit设置的示例.
Pet*_*mer 44
做点什么
git commit -m"test\ntest"
Run Code Online (Sandbox Code Playgroud)
不起作用,但有点像
git commit -m"$(echo -e "test\ntest")"
Run Code Online (Sandbox Code Playgroud)
有效,但不是很漂亮.你git-commitlb
在你的设置命令PATH
做了这样的事情:
#!/bin/bash
message=$1
git commit -m"$(echo -e "$message")"
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
git commitlb "line1\nline2\nline3"
Run Code Online (Sandbox Code Playgroud)
警告的话,我有一种感觉,即一般惯例是将摘要行作为第一行,然后是两个换行符,然后是提交消息中的扩展消息,因此这样做会破坏该约定.你当然可以这样做:
git commitlb "line1\n\nline2\nline3"
Run Code Online (Sandbox Code Playgroud)
Sar*_*n M 37
从Git文档:
-m <msg>
--message = <msg>
使用给定的<msg>作为提交消息.如果-m
给出了多个选项,则它们的值将作为单独的段落连接在一起.
所以,如果你正在寻找分组多个提交消息,这应该做的工作:
git commit -m "commit message1" -m "commit message2"
Run Code Online (Sandbox Code Playgroud)
Tob*_*bse 35
我希望这不会过于远离发布的问题,而是设置默认编辑器然后使用
git commit -e
Run Code Online (Sandbox Code Playgroud)
可能会更舒服.
blo*_*gho 23
没有必要使这些东西复杂化.-m "text...
通过按下获得下一行之后Enter.当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 ...
Run Code Online (Sandbox Code Playgroud)
Abi*_*ern 18
我在Mac上使用zsh,我可以在双引号(")中发布多行提交消息.基本上我一直在键入并按回新行,但是在我关闭引号并返回之前,消息不会发送到Git .
Eug*_*ash 11
在Bash/Zsh中,您只需在引号内使用文字换行符:
git commit -m 'Multi-line
commit
message'
Run Code Online (Sandbox Code Playgroud)
ANSI-C引用也适用于Bash/Zsh:
git commit -m $'Multi-line\ncommit\nmessage'
您还可以指示Git使用不同的编辑器.从git-commit上的文档:
用于编辑提交日志消息的编辑器将从
GIT_EDITOR
环境变量,core.editor
配置变量,VISUAL
环境变量或EDITOR
环境变量(按此顺序)中选择.有关详细信息,请参阅git-var.
以下是Windows 上使用标准 cmd.exe shell的失败解决方案列表(为您节省一些反复试验的时间!):
git commit -m 'Hello
Enter 不起作用:它不会要求换行
git commit -m "Hello
Enter 同上
git commit -m "Hello^
Enter 同上
git commit -m 'Hello^
Enter World'
看起来像在工作,因为它会问“更多?” 并允许写一个新行,但最后git log
你会看到它仍然是一条单行消息......
TL;DR:即使在 Windows 上,命令行解析的工作方式不同,并且^
允许多行输入,但在这里也无济于事。
最后git commit -e
可能是最好的选择。
就我个人而言,我发现在事实发生之后vi
(或您选择的git编辑器选择什么)而不是在命令行中进行修改,最简单的方法是在git commit --amend
after之后执行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'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
243525 次 |
最近记录: |