[英]Use of an exclamation mark in a Git commit message via the command line
How do I enter an exclamation point into a Git commit message from the command line? 如何从命令行向Git提交消息输入感叹号?
It is possible to escape the exclamation point with a backslash, but then the backslash ends up in the commit message as well. 可以使用反斜杠转义感叹号,但反斜杠也会在提交消息中结束。
I want something like this: 我想要这样的东西:
git commit -am "Nailed it!"
Use single quotes instead of double quotes 使用单引号而不是双引号
git commit -am 'Nailed it!'
Alternatively, if you need to use double quotes for whatever reason but still want a literal !
或者,如果您因任何原因需要使用双引号但仍需要文字
!
then turn off history expansion at the top of your script via set +H
然后通过
set +H
关闭脚本顶部的历史记录扩展
Another way to solve that is to add a space after ! 另一种解决方法是在之后添加一个空格 ! like:
喜欢:
git commit -am "Nailed it! "
Note the space between ! 注意之间的空间 ! and the last " .
最后一个“ 。
(The space won't be included in the commit message - Git trims trailing whitespace from commit messages automatically.) (该空间不会包含在提交消息中 - Git会自动从提交消息中修剪尾随空格。)
No need to remember what quotes or escapes to use, instead 不需要记住要使用的引号或转义
Ctr
X
E
» will open your "external editor". Ctr
X
E
»将打开“外部编辑器”。 … the command will be executed & any special characters will show up correctly in the Git commit message! ...命令将被执行,任何特殊字符将在Git提交消息中正确显示!
(NB many other uses: typing complex commands, adding line breaks in your commit message etc.) (NB许多其他用途:输入复杂命令,在提交消息中添加换行符等)
You can also type: 你也可以输入:
git commit -am "Nailed it
!
"
So just hit enter and place the exclamation mark on a new line, then close off the commit message. 因此,只需按Enter键并将感叹号放在新行上,然后关闭提交消息。 Found that one out by accident one day.
发现那一天意外发生了一天。
If you need to use double quotes and the !
如果你需要使用双引号和
!
is the last character in the message, just keep the !
是消息中的最后一个字符, 只需保留
!
outside of the quotes , since we're only using quotes so that the spaces get included in the message. 在引号之外 ,因为我们只使用引号,以便空格包含在消息中。
git commit -m "Reverting last commit because I don't like it"!
If you need to include !
如果你需要包括
!
mid string, you can use single quotes but if you need to use a literal single quote, you'll need to close your quote, then put the '
outside of the string by escaping it. mid string,你可以使用单引号,但如果你需要使用文字单引号,你需要关闭你的引号,然后通过转义它来放置字符串
'
外部。 So, let's say your message is I don't like it! Reverting again!
所以,让我们说你的信息是
I don't like it! Reverting again!
I don't like it! Reverting again!
, this can be composed with 'I don'
+ \\'
+ 't like it! Reverting again!'
,这可以用
'I don'
+ \\'
+ 't like it! Reverting again!'
't like it! Reverting again!'
git commit -m 'I don'\''t like it! Reverting again!'
Anything more complicated than this, you're probably better off with git commit
and letting git invoke your default text editor :) 比这更复杂的东西,你可能最好用
git commit
并让git调用你的默认文本编辑器:)
Hmm. 嗯。 Escaping it with a slash doesn't show up in commit message for me.
使用斜杠转义它不会在提交消息中显示给我。
git commit -m "Nailed it\!"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.