用于个人和工作资料的 Git includeIf 不起作用 [英] Git includeIf for personal and work profiles doesn't work

查看:38
本文介绍了用于个人和工作资料的 Git includeIf 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在谷歌上搜索这个,尝试了不同来源的不同方法......但它不起作用.

I've been googling about this, trying different methods from different sources... but it doesn't work.

我想用我的个人资料(用git config --global user.email ..."定义)推送提交,除非我在我的工作文件夹中.

I want to push commits with my personal profile (defined with "git config --global user.email ...") unless I'm on my work folder.

我的 .gitconfig 的内容位于 C:/Users/my-user/

The content of my .gitconfig is located at C:/Users/my-user/

[user]
    name = Personal
    email = personal@personal.com

[includeIf "gitdir: F:/Work/CompanyName/"]
    path = F:/Work/CompanyName/.gitconfig-work
    

我的 .gitconfig-work 的内容位于 F:/Work/CompanyName/

Content of my .gitconfig-work is located at F:/Work/CompanyName/

[user]
    name = Work
    email = work@work.com

当我从位于以下位置的工作中转到克隆存储库时:

When I go to a cloned repository from work located at:

F:/Work/CompanyName/Project

我用:

git config --show-origin --get user.email

它显示:

file:C:/Users//.gitconfig

而不是我定义的路线.

感谢您的帮助.

我创建了一个gist 来解释这些步骤.

I created a gist explaining the steps.

推荐答案

需要去掉一个空格:

[includeIf "gitdir: F:/Work/CompanyName/"]

即,将其改为:

[includeIf "gitdir:F:/Work/CompanyName/"]

注意gitdir后面的冒号和要测试的路径名之间没有空格.

Note the lack of a blank between the colon after gitdir and the path name to be tested.

(您的 Git 还需要至少为 2.13 版本.您可以考虑使用 gitdir/i:f:/work/companyname/ 以便在此处不区分大小写,假设您的主机系统也不区分大小写,正如 F: 部分所暗示的那样.)

(Your Git also needs to be at least version 2.13. You might consider using gitdir/i:f:/work/companyname/ so that you are not case-sensitive here, assuming your host system is also not case-sensitive, as the F: part suggests.)

这篇关于用于个人和工作资料的 Git includeIf 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆