优雅的方式分别保存.git配置?

问题描述 投票:1回答:1

参考https://git-scm.com/docs/git-config表示git的配置由三个范围保存,系统,全局和项目特定。

我想知道是否有其他方法可以在全局和项目之间分离更具体的范围。

例如,我有许多项目与我的正式工作有关,那时我需要user.name =“NAME IN CORP”。 OTOH其他人需要user.name =“NAME IN PUBLIC”。

问题是属于我提到的两个范围(工作,公共)的项目太多,无法逐个指定项目范围。有没有有效的方法来解决它?

git
1个回答
3
投票

从git 2.13开始,可以使用新引入的Conditional includes来解决这个问题。

一个例子:

全局配置〜/ .gitconfig

[user]
    name = John Doe
    email = [email protected]

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

特定于工作的配置〜/ work / .gitconfig

[user]
    email = [email protected]
© www.soinside.com 2019 - 2024. All rights reserved.