bash 不能加“!” 我的 git 提交消息中的符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8404328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:08:35  来源:igfitidea点击:

Can't add the "!" symbol in my git commit message

gitbash

提问by Ant's

Possible Duplicate:
How do I enter an exclamation point into a git commit message from the command line?

可能重复:
如何从命令行在 git commit 消息中输入感叹号?

I'm new to git, and I did this command:

我是 git 新手,我执行了以下命令:

git commit -m "First Commit!"

This throws an error like this:

这会引发这样的错误:

bash: !": event not found

Why is this error happening? Is is that in Git, I shouldn't use !symbols in commit?

为什么会发生此错误?是不是在 Git 中,我不应该!在 中使用符号commit

Are there other symbols which I shouldn't use or should escape with any escape sequence?

还有其他我不应该使用或应该使用任何转义序列转义的符号吗?

回答by Paul R

Nothing to do with git, more to do with bash - escape the !or use single quotes, i.e.

与 git 无关,更多与 bash 有关 - 转义!或使用单引号,即

$ git commit -m "First Commit\!"

or, better:

或更好:

$ git commit -m 'First Commit!'

回答by Dominik Honnef

That's not git related at all, but bash related. Using ! in a string will cause bash to attempt history expansion. If you don't want that, either use single-quoted strings or escape the exclamation mark with a backslash.

这根本不是 git 相关的,而是 bash 相关的。使用 !在字符串中将导致 bash 尝试历史扩展。如果您不想这样,请使用单引号字符串或使用反斜杠转义感叹号。

回答by Unapiedra

No, this is possible in with the git command line and double quotes. One easy fix is putting a space after !.

不,这在 git 命令行和双引号中是可能的。一个简单的解决方法是在!.

git commit -m "First Commit! "

Another way to get around this is by using git guior just git commitand then specifying the message in the editor that opens.

解决此问题的另一种方法是使用git guior justgit commit然后在打开的编辑器中指定消息。

The limitation is clearly a bash limitation and not a problem of git. You can avoid it using single quotes:

该限制显然是 bash 限制,而不是 git 的问题。您可以使用单引号避免它:

git commit -m 'First Commit!'