查看git的源码,在git.c中有一条注释:
/*
* We use PATH to find git commands, but we prepend some higher
* precedence paths: the "--exec-path" option, the GIT_EXEC_PATH
* environment, and the $(gitexecdir) from the Makefile at build
* time.
*/
如果你调用,git --exec-path
你最终会调用exec_cmd.c。看起来像这样:const char *git_exec_path(void)
const char *env;
if (argv_exec_path)
return argv_exec_path;
env = getenv(EXEC_PATH_ENVIRONMENT);
if (env && *env) {
return env;
}
return system_path(GIT_EXEC_PATH);
现在,_argv_exec_path_ 设置的时候你这么说--exec-path=/some/where
可以打折了。您已声明未设置环境变量。 GIT_EXEC_PATH
在编译期间在Makefile中定义。往回走,它似乎被定义为 just libexec/git-core
。所以,我们需要看看system_path()做了什么。
我不确定是否RUNTIME_PREFIX
为您定义。但是,在 Makefile 中查找时,我确实注意到前缀默认为$(HOME)
. 我怀疑这可能是您的问题的原因。
简单的答案是将其放入~/.bashrc
:
export GIT_EXEC_PATH=/opt/local/libexec/git-core
如果您想了解更多关于正在发生的事情,您可能必须使用port -d upgrade -f git-core
(或类似的)重新编译 git 并仔细查看构建日志以查看设置前缀的位置。顺便说一句,port cat git-core
显示大量使用${prefix}
所以它应该(希望)是显而易见的。