是否有可能通过git别名覆盖git命令? [英] Is it possible to override git command by git alias?

查看:117
本文介绍了是否有可能通过git别名覆盖git命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

my〜/ .gitconfig是:

  [别名] 
commit =!sh commit.sh

但是,当我键入 git commit 时,脚本不会被调用。 / p>

是否有可能,或者我必须使用别名?

解决方案

<这是不可能的



这是从我的克隆git.git:

  static int run_argv(int * argcp,const char *** argv)
{
int done_alias = 0;

while(1){
/ *看看它是否是内部命令* /
handle_internal_command(* argcp,* argv);

/ * ..然后尝试外部的* /
execv_dashed_external(* argv);

/ *它可以是一个别名 - 这可以通过使用
* alias.log = show来替代git show来覆盖git log的疯狂
*
* /
if(done_alias ||!handle_alias(argcp,argv))
break;
done_alias = 1;
}

return done_alias;
}

所以它不可能。 ( handle_internal_command 调用 exit 如果发现该命令)。

你可以通过改变行的顺序并且如果发现 handle_alias 调用 exit 别名。


my ~/.gitconfig is:

[alias]
        commit = "!sh commit.sh"

However, when I type git commit, script is not called.

Is it possible, or I have to use another alias name?

解决方案

It is NOT POSSIBLE

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;
}

So its not possible. (handle_internal_command calls exit if it finds the command).

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命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆