如何为新的Git存储库配置默认配置?

时间:2017-07-28 15:03:31

标签: git cygwin

在下文中,我们看到Git默认将ignorecase设置为true,尽管配置为.gitconfig

$ mkdir foo && cd foo && git init
Initialized empty Git repository in /cygdrive/c/Users/nowox/home/git/foo/.git/
$ cat .git/config | grep ignore
        ignorecase = true

我如何告诉Git默认情况下为新存储库将ignorecase设置为false?

我已将此配置文件放在$GIT_TEMPLATE_DIR(/ usr / share / git-core / templates)中:

[core]
        ignorecase = false 
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

但它仍然无效。好像我的config文件被Git删除了......

完整示例

~/test $ git init
Initialized empty Git repository in /cygdrive/c/test/.git/
~/test $ cat .git/config
[core]
        ignorecase = true
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

~/test $ cat /usr/share/git-core/templates/config
[core]
        ignorecase = false
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

它看起来不起作用。两个配置文件都不同:

~/test $ diff  /usr/share/git-core/templates/config .git/config
2,5c2,5
<         ignorecase = false
<         repositoryformatversion = 0
<         filemode = true
<         bare = false
---
>       ignorecase = true
>       repositoryformatversion = 0
>       filemode = true
>       bare = false

如果我声明GIT_TEMPLATE_DIR变量:

,则相同
~/test $ rm -rf .git
~/test $ GIT_TEMPLATE_DIR=/usr/share/git-core/templates git init .
Initialized empty Git repository in /cygdrive/test/.git/
~/test $ cat .git/config
[core]
        ignorecase = true
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

1 个答案:

答案 0 :(得分:0)

请参阅TEMPLATE DIRECTORY of git-init

默认情况下,当我们初始化新的git repo时,/usr/share/git-core/templates下的内容将被复制到这个新的repo&#39; s .git。因此,我们可以在此处为config制作模板,其中包括

[core]
    ignoreCase = false

git-bash-for-windows/mingw64/share/git-core/templates//mingw32/share/git-core/templates/

除了手册所说,我们还有以下选项来指定模板。

  1. 使用--template选项提供的参数;
  2. $GIT_TEMPLATE_DIR环境变量的内容;
  3. init.templateDir配置变量。