【问题标题】:Can't add the "!" symbol in my git commit message [duplicate]不能加“!”我的 git 提交消息中的符号 [重复]
【发布时间】:2012-01-14 07:34:41
【问题描述】:

可能重复:
How do I enter an exclamation point into a git commit message from the command line?

我是 git 新手,我做了这个命令:

git commit -m "First Commit!"

这会引发如下错误:

bash: !": event not found

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

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

【问题讨论】:

标签: git bash


【解决方案1】:

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

$ git commit -m "First Commit\!"

或者,更好:

$ git commit -m 'First Commit!'

【讨论】:

  • 在第一种方法中使用反斜杠转义会在实际提交消息中留下难看的文字反斜杠。 the post this is a dupe of 上的答案更好。
  • 仅供不想手动转义字符的人使用。另一种方法是在终端中使用git gui 命令。然后我们可以使用提交消息而不需要手动转义字符
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    不,这可以在 git 命令行和双引号中实现。一个简单的解决方法是在! 之后放置一个空格。

    git commit -m "First Commit! "
    

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

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

    git commit -m 'First Commit!'
    

    【讨论】:

    • 这不是限制,而是功能
    • 不正确,如this answer所示:有可能,用单引号就可以了
    猜你喜欢
    • 2014-06-30
    • 2012-01-18
    • 2020-05-07
    • 2013-03-06
    • 2013-08-15
    • 2011-11-27
    • 2011-09-07
    • 2021-06-18
    • 2012-12-15
    相关资源
    最近更新 更多