如何为新的Git存储库配置默认配置? [英] How to configure default configuration for new Git repository?
问题描述
在下面,我们看到尽管我进行了 .gitconfig
的配置,但Git仍默认将 ignorecase
设置为true.
In the following we see that Git set ignorecase
to true by default despite my .gitconfig
configuration.
$ 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?
How can I tell Git to set ignorecase
to false by default for new repositories?
我已将此配置文件放入 $ GIT_TEMPLATE_DIR
(/usr/share/git-core/templates):
I have put this config file in $GIT_TEMPLATE_DIR
(/usr/share/git-core/templates):
[core]
ignorecase = false
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
但是它仍然不起作用.看来我的 config
文件已被Git删除...
But it still doesn't work. It seems my config
file is erased by 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
它似乎不起作用.两种配置文件都不同:
It looks it doesn't work. Both config files are different:
~/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
变量,则相同:
It is the same if I declare the GIT_TEMPLATE_DIR
variable:
~/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
推荐答案
请参见git-init的模板目录.
默认情况下,当我们初始化一个新的git仓库时,/usr/share/git-core/templates
下的内容将被复制到该新仓库的 .git
.因此,我们可以在此处为 config
创建一个模板,其中包括
By default, when we initialize a new git repo, the contents under /usr/share/git-core/templates
will be copied to this new repo's .git
. So we can make a template for config
here, which includes
[core]
ignoreCase = false
对于 git-bash-for-windows
,它是/mingw64/share/git-core/templates/
或/mingw32/share/git-core/templates/
.
除手册所述外,我们还有以下用于指定模板的选项.
Besides as the manual says, we have the folloing options to specify the templates.
- 使用
-template
选项提供的参数; -
$ GIT_TEMPLATE_DIR
环境变量的内容; -
init.templateDir
配置变量.
- the argument given with the
--template
option; - the contents of the
$GIT_TEMPLATE_DIR
environment variable; - the
init.templateDir
configuration variable.
这篇关于如何为新的Git存储库配置默认配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!