在我的.zshrc文件中,我有一个基于当前路径设置环境变量的chpwd函数GIT_CONFIG。
像这样的东西:
update_gitconfig() {
if [[ "$(pwd | grep -Poe '^/home/user/repositories/user-A(/|$)')" != "" ]]
then
export GIT_CONFIG="$HOME/.gitconfig-A"
return
fi
if [[ "$(pwd | grep -Poe '^/home/user/repositories/user-B(/|$)')" != "" ]]
then
export GIT_CONFIG="$HOME/.gitconfig-B"
return
fi
export GIT_CONFIG="$HOME/.gitconfig-default"
}
update_gitconfig
chpwd_functions+=(update_gitconfig)
Run Code Online (Sandbox Code Playgroud)
如果我运行git config --list,它会在每个目录下显示预期的配置:
$HOME/repositories/user-A它下面显示来自 的设置$HOME/.gitconfig-A。$HOME/repositories/user-B它下面显示来自 的设置$HOME/.gitconfig-B。$HOME/.gitconfig-default.当我运行时,问题就开始了git commit;它似乎没有得到设置:
*** Please tell me who you are.
Run
git config --global …Run Code Online (Sandbox Code Playgroud)