git commit -m "add !empty check" zsh:找不到事件:空
git commit -m "add !empty check" zsh: event not found: empty
我刚刚观察到有!在 git 提交消息触发 zsh 中的事件之前。
不确定是 zsh 问题还是 git 功能。请解释。
好像是这样for bash as well。
尝试转义该字符以避免任何 shell 相关的副作用:
git commit -m "add \!empty check"
# or
git commit -m 'add !empty check'
(参见单引号上的 jthill's )
或 turn off history substitution 使用 set +H
。
这与 git 无关,您的 shell 正在尝试扩展 !
。
使用 \!
转义字符或 '
单引号 '
而不是 "
双引号 "
来禁用 shell在字符串中的variable/history扩展。
要详细了解 shell 的历史扩展,请查看 zsh's User Guide - 3.6.1: History expansion
它最简单的用例是在忘记在开头指定 sudo 之后重新运行带有 sudo !!
的命令。
关于 git commit
的旁注:
我强烈建议 against 在提交时使用 -m
,因为它消除了注意到提交错误的机会。
如果您不使用 -m
,用于消息输入的文本编辑器将有一个 staged/unstaged 更改列表。在完成提交之前快速浏览一下这些列表总是一个好主意。
(如果您发现有问题,只需保存空消息,提交将被中止)
我刚刚观察到有!在 git 提交消息触发 zsh 中的事件之前。
不确定是 zsh 问题还是 git 功能。请解释。
好像是这样for bash as well。
尝试转义该字符以避免任何 shell 相关的副作用:
git commit -m "add \!empty check"
# or
git commit -m 'add !empty check'
(参见单引号上的 jthill's
或 turn off history substitution 使用 set +H
。
这与 git 无关,您的 shell 正在尝试扩展 !
。
使用 \!
转义字符或 '
单引号 '
而不是 "
双引号 "
来禁用 shell在字符串中的variable/history扩展。
要详细了解 shell 的历史扩展,请查看 zsh's User Guide - 3.6.1: History expansion
它最简单的用例是在忘记在开头指定 sudo 之后重新运行带有 sudo !!
的命令。
关于 git commit
的旁注:
我强烈建议 against 在提交时使用 -m
,因为它消除了注意到提交错误的机会。
如果您不使用 -m
,用于消息输入的文本编辑器将有一个 staged/unstaged 更改列表。在完成提交之前快速浏览一下这些列表总是一个好主意。
(如果您发现有问题,只需保存空消息,提交将被中止)