定义具有相同名称的git别名来隐藏原始命令 [英] Define git alias with the same name to shadow original command
问题描述
我试图使用与现有命令相同的别名作为别名,以便别名会遮挡原始命令(防止我从正在工作的树中删除文件)。
[别名]
rm = rm - 缓存
diff = diff --color
不幸的是,这不起作用。有谁知道解决方法?
Thanks。
编辑
设置 color.diff = true $ c $对于像
rm --cached $ c这样的命令,
[别名]
rmc = rm --cached
您可能已经知道了这一点,但是Git别名不能影射现有的Git命令。从 git-config
手册页:
lockquote
为了避免混淆和脚本使用的麻烦,隐藏现有git命令的别名被忽略。
I'm trying to use to use the same name for an alias as the existing command, so that the alias shadows the original command (preventing me from deleting files off the working tree).
[alias]
rm = rm --cached
diff = diff --color
Unfortunatly this is not working. Does anyone know a workaround? Thanks.
Edit
Setting color.diff = true
gives colored output as default.
For commands like rm --cached
that don't have configurable options, your best bet is to just make an alias named differently. For example:
[alias]
rmc = rm --cached
You may have already figured this out, but Git aliases cannot shadow existing Git commands. From the git-config
man page:
To avoid confusion and troubles with script usage, aliases that hide existing git commands are ignored.
这篇关于定义具有相同名称的git别名来隐藏原始命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!