Git别名忽略全局设置

时间:2018-11-23 14:49:04

标签: git

我在relativePaths中为git status设置了~/.gitconfig

[status]
  relativePaths = true

然后定义一个git别名,如下所示:

st = !git status

当我调用git status时,将应用relativePaths设置,但是当我调用别名时,则不会。

如何使它正常工作?

注意: 使用别名,我实际上将git status的结果传递给grep,因此我需要使用! shell语法。我将其排除在此示例之外,因为没有它的行为是相同的

1 个答案:

答案 0 :(得分:1)

该设置可能已应用,您可以使用别名进行检查,例如:

[alias]
    check-status-rel = config --global --get status.relativePaths

man git-config设置说明的第二段中的alias.*中说明了它不适用于您的原因:

   alias.*
       Command aliases for the git(1) command wrapper - e.g. after
       defining "alias.last = cat-file commit HEAD", the invocation "git
       last" is equivalent to "git cat-file commit HEAD". To avoid
       confusion and troubles with script usage, aliases that hide
       existing Git commands are ignored. Arguments are split by spaces,
       the usual shell quoting and escaping is supported. A quote pair or
       a backslash can be used to quote them.

       If the alias expansion is prefixed with an exclamation point, it
       will be treated as a shell command. For example, defining
       "alias.new = !gitk --all --not ORIG_HEAD", the invocation "git new"
       is equivalent to running the shell command "gitk --all --not
       ORIG_HEAD". Note that shell commands will be executed from the
       top-level directory of a repository, which may not necessarily be
       the current directory.  GIT_PREFIX is set as returned by running
       git rev-parse --show-prefix from the original current directory.
       See git-rev-parse(1).

简而言之,作为shell命令的Git别名始终在存储库的根目录中执行。

编辑:显然,您可以在运行命令之前简单地cd进入目录:

[alias]
    st = "!cd \"$GIT_PREFIX\" && git status"
相关问题