小编noi*_*ixy的帖子

基于当前路径的不同 .gitconfig

在我的.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)

zsh git

5
推荐指数
1
解决办法
1048
查看次数

标签 统计

git ×1

zsh ×1