在Windows上的Git 2.13条件配置 [英] Git 2.13 conditional config on windows

查看:204
本文介绍了在Windows上的Git 2.13条件配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git版本: 2.13.0.windows.1



操作系统:

CLI: Git bash



.gitconfig

  [user] 
name = Gyandeep Singh
email = private@email.com
[push]
default = current
[core]
autocrlf = input
[includeIfgitdir:〜/ Documents / webstorm / corporate /]
path = .gitconfig-work

.gitconfig-work

  [user] 
name = Gyandeep Singh
email = corporate@email.com


  • 上面的两个配置文件都放在同一个目录(home)中。


发生了什么:在公司文件夹内的文件夹(示例测试)上打开CLI,然后运行 git config user.email 输出是 private@email.com



预期: strong>结果应该是 corporate@email.com



我做错了什么或者我的期望不正确?我确实遵循了git文档。



解决方案



您必须运行 git config - 在git初始化目录中显示user.email 。如果它没有被初始化,那么 includeIf gitdir 功能将不起作用。



它很奇怪,但却是真实的。我希望它仍然有效。

解决方案

您的全局 C:/ Users /< user-name> /.gitconfig 应该有这个 includeIf

  [includeIfgitdir:C:/ Users /< user-name> / Documents / webstorm / corporate /] 
path = .gitconfig-work

C:/ Users /<用户名> / Documents / webstorm / corporate 条件工作配置应该位于 C:/ Users /< user-name> /。gitconfig-work



至少在Window的 cmd Cmder 中适用于我。一个 git config --show-origin --get user.email 应该显示你从哪里加载/解析配置值。



似乎只有在Git存储库中发布时才使用条件工作配置。

  C:\ Users \< user-name> \Documents\webstorm\corporate 
λgit config --show-origin --get user.email
file:C:/ Users /< user-name> /。gitconfig foo@oss.com

C:\Users\\ \\< user-name> \ Documents \webstorm\corporate\some-repo
λgit config --show-origin --get user.email
file:C:/ Users / < user-name> /。gitconfig-work foo@company.com

C:\ Users \< user-name> \Documents\webstorm\corporate\some- non-repo-dir
git config --show-origin --get user.email
file:C:/ Users /< user-name> /。gitconfig foo@oss.com


Git version: 2.13.0.windows.1

OS: Windows 7

CLI: Git bash

.gitconfig

[user]
    name = Gyandeep Singh
    email = private@email.com
[push]
    default = current
[core]
    autocrlf = input
[includeIf "gitdir: ~/Documents/webstorm/corporate/"]
    path = .gitconfig-work

.gitconfig-work

[user]
    name = Gyandeep Singh
    email = corporate@email.com

  • Both the config files above sit together in the same directory (home).

What happened: open CLI on a folder (example test) inside corporate folder and then run git config user.email the output is private@email.com.

Expected: Outcome should be corporate@email.com.

Am I doing something wrong or my expectation is not correct? I did follow the git docs.

Solution

You have to run git config --show-origin --get user.email on a git initialized directory. If its not git initialized then the includeIf gitdir functionality will not work.

Its strange but true. I wish it still worked.

解决方案

Your global C:/Users/<user-name>/.gitconfig should have this includeIf:

[includeIf "gitdir:C:/Users/<user-name>/Documents/webstorm/corporate/"]
    path = .gitconfig-work

with having your work Git repos in C:/Users/<user-name>/Documents/webstorm/corporate and the conditional work configuration should be located at C:/Users/<user-name>/.gitconfig-work.

That's at least working for me in Window's cmd and Cmder. A git config --show-origin --get user.email should than show you from where a config value is loaded/resolved.

It also seems like the conditional work configuration is only used when issued from within a Git repository.

C:\Users\<user-name>\Documents\webstorm\corporate
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig  foo@oss.com

C:\Users\<user-name>\Documents\webstorm\corporate\some-repo
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig-work  foo@company.com

C:\Users\<user-name>\Documents\webstorm\corporate\some-non-repo-dir
λ git config --show-origin --get user.email
file:C:/Users/<user-name>/.gitconfig  foo@oss.com

这篇关于在Windows上的Git 2.13条件配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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