定义同名的 git 别名来隐藏原始命令 [英] Define git alias with the same name to shadow original command
问题描述
我试图使用与现有命令相同的别名作为别名,以便别名隐藏原始命令(防止我从工作树中删除文件).
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.
编辑设置 color.diff = true
将提供彩色输出作为默认值.
Edit
Setting color.diff = true
gives colored output as default.
推荐答案
对于像 rm --cached
这样没有可配置选项的命令,最好的办法是创建一个不同名称的别名.例如:
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
您可能已经明白这一点,但是 Git 别名无法隐藏现有的 Git 命令.来自 git-config
man页面:
You may have already figured this out, but Git aliases cannot shadow existing Git commands. From the git-config
man page:
为了避免脚本使用的混乱和麻烦,隐藏现有 git 命令的别名将被忽略.
To avoid confusion and troubles with script usage, aliases that hide existing git commands are ignored.
这篇关于定义同名的 git 别名来隐藏原始命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!