Git 相当于 which/whence

Git equivalent of which/whence

当我 运行 git help -a 时,它会显示内部命令列表、我所有的别名和我所有的外部 git 命令(即任何以 [= 开头的可执行文件) 14=] 在我的道路上)。我想要的是一个别名或脚本,我可以 运行 as git which 它将告诉我以下之一:

我可以很容易地编写一个脚本来使用 git help -a 的输出并生成这个,但是我是否缺少一些 git 命令,它已经提供了部分或全部这些功能?

更新

感谢@jthill 的评论和回答,我想出了以下 git-which 脚本:

#!/bin/sh

if test $# -ne 1
then
        echo "Usage: [=12=] <git command>" >&2
        exit 1
fi

CMD=git-""

if PATH="$(git --exec-path)" command -v "$CMD" >/dev/null
then
    echo ": git built-in command"
    exit 0
elif command -v "$CMD"
then
    exit 0
elif git config --get-regexp '^alias\.'""'$' |\
    sed 's/^alias\.\([^\s]\+\)/: aliased to /'
then
        exit 0
fi

echo " not found"
exit 1

git help 会显示别名,例如 git help wtf'wtf' is aliased to 'blame -w'。对于其余部分,搜索 libexec/git-core 并不难,比如 git --exec-path,并且 which 已经搜索命令,所以

PATH=$(git --exec-path):$PATH which git-checkout

将为您代劳,别名无法覆盖内置函数,因此(手指到文本框警告:)

f() { PATH=$(git --exec-path)${PATH+:$PATH} which git- 2>&- || git help ; }

看起来是个不错的开始。