git commit -m "add !empty check";zsh:未找到事件:空 [英] git commit -m "add !empty check" zsh: event not found: empty
问题描述
我刚刚观察到有!在 git commit 消息触发 zsh 中的事件之前.
I just observed having ! before a git commit message triggers events in zsh.
不确定是 zsh 问题还是 git 功能.请解释.
Not sure if it's zsh issue or git feature. Please explain.
推荐答案
这与 git 无关,你的 shell 正在尝试扩展 !
.
This is unrelated to git, your shell is trying to expand the !
.
使用 \!
转义字符或 '
单引号 '
而不是 "
双引号"
在字符串中禁用 shell 的变量/历史扩展.
Use either \!
to escape the character or '
single quotes'
instead of "
double quotes"
to disable the shell's variable/history expansion within the string.
要了解有关 shell 历史扩展的更多信息,请查看 zsh 的用户指南 - 3.6.1:历史扩展
To learn more about your shell's history expansion, have a look at zsh's User Guide - 3.6.1: History expansion
最简单的用例是在忘记在开头指定 sudo 后使用 sudo !!
重新运行命令.
The simplest use-case for it is re-running a command with sudo !!
after forgetting to specify sudo at the beginning.
关于 git commit
的旁注:
我强烈建议在提交时反对使用 -m
,因为它会消除注意到提交错误的机会.
I strongly recommend against using -m
when committing, because it takes away the chance to notice something being wrong with the commit.
如果您不使用 -m
消息输入的文本编辑器将有一个暂存/未暂存更改列表.在最终确定提交之前,先简短地查看一下这些列表总是一个好主意.
If you don't use -m
the text editor for message input will have a list of staged/unstaged changes. It's always a good idea to have a short look at those lists before finalizing the commit.
(如果您发现有问题,只需保存为空消息,提交将中止)
(If you notice something is wrong, just save with empty message and the commit will be aborted)
这篇关于git commit -m "add !empty check";zsh:未找到事件:空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!