本文介绍了是否可以通过 git 别名覆盖 git 命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 ~/.gitconfig 是:
my ~/.gitconfig is:
[alias]
commit = "!sh commit.sh"
但是,当我输入 git commit 时,不会调用脚本.
However, when I type git commit, script is not called.
是否可以,或者我必须使用其他别名?
Is it possible, or I have to use another alias name?
推荐答案
这不可能
这是来自我的 git.git 克隆:
This is from my clone of git.git:
static int run_argv(int *argcp, const char ***argv)
{
int done_alias = 0;
while (1) {
/* See if it's an internal command */
handle_internal_command(*argcp, *argv);
/* .. then try the external ones */
execv_dashed_external(*argv);
/* It could be an alias -- this works around the insanity
* of overriding "git log" with "git show" by having
* alias.log = show
*/
if (done_alias || !handle_alias(argcp, argv))
break;
done_alias = 1;
}
return done_alias;
}
所以这是不可能的.(handle_internal_command
如果找到命令则调用 exit
).
So its not possible. (handle_internal_command
calls exit
if it finds the command).
您可以通过更改行的顺序并让 handle_alias
调用 exit
(如果找到别名)来解决此问题.
You could fix this in your sources by changing the order of the lines and making handle_alias
call exit
if it finds the alias.
这篇关于是否可以通过 git 别名覆盖 git 命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!