首页 > 解决方案 > 阻止 Gitconfig 文件被本地 .git/config 覆盖

问题描述

最近我开始在我的 git 配置中使用 includeIf 功能来处理不同项目的多个 git 用户帐户,但是我遇到了一个让我发疯的问题。

脚本的 includeIf 部分似乎覆盖了主 git 配置文件。即使我没有使用应该应用它的存储库。

这是我的.gitconfig

[user]
    name = Default Gitlab
    email = default.gitlab@project1.com
[includeIf "gitdir:~/repos/project2/"]
    path = ~/.gitconfig-github

.gitconfig-github

[user]
    name = Another Github
    email = another.github@project2.com

问题是,过了一会儿我的.gitconfig样子是这样的:

[user]
    name = Another Github
    email = another.github@project2.com
[includeIf "gitdir:~/repos/project2/"]
    path = ~/.gitconfig-github

我真的无法弄清楚为什么或如何发生这种情况。

感谢你的帮助!

########
# Edit #
########

我注意到不完全includeIf是这样做的。每次我的仓库本地 git 配置发生更改时,似乎都会发生更改。

还在努力想办法...

标签: git

解决方案


推荐阅读