git 配置的优先级是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26824231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the priority regarding git configuration?
提问by djangofan
If I set configuration on my ~/.gitconfig
file, which config would override it?
如果我在我的~/.gitconfig
文件上设置配置,哪个配置会覆盖它?
- project level config :
.git/config
- system level config :
/etc/gitconfig
- 项目级配置:
.git/config
- 系统级配置:
/etc/gitconfig
采纳答案by Michael
From the Git manual (read http://git-scm.com/docs/git-config#FILES)
从 Git 手册(阅读http://git-scm.com/docs/git-config#FILES)
If not set explicitly with --file, there are four files where git config will search for configuration options:
$(prefix)/etc/gitconfig
System-wide configuration file.
$XDG_CONFIG_HOME/git/config
Second user-specific configuration file. If $XDG_CONFIG_HOME is not set or empty, $HOME/.config/git/config will be used. Any single-valued variable set in this file will be overwritten by whatever is in ~/.gitconfig. It is a good idea not to create this file if you sometimes use older versions of Git, as support for this file was added fairly recently.
~/.gitconfig
User-specific configuration file. Also called "global" configuration file.
$GIT_DIR/config
Repository specific configuration file.
If no further options are given, all reading options will read all of these files that are available. If the global or the system-wide configuration file are not available they will be ignored. If the repository configuration file is not available or readable, git config will exit with a non-zero error code. However, in neither case will an error message be issued.
The files are read in the order given above, with last value found taking precedence over values read earlier. When multiple values are taken then all values of a key from all files will be used.
如果没有用 --file 明确设置,git config 将在四个文件中搜索配置选项:
$(前缀)/etc/gitconfig
系统范围的配置文件。
$XDG_CONFIG_HOME/git/config
第二个特定于用户的配置文件。如果 $XDG_CONFIG_HOME 未设置或为空,则将使用 $HOME/.config/git/config。此文件中设置的任何单值变量都将被 ~/.gitconfig 中的任何内容覆盖。如果您有时使用旧版本的 Git,最好不要创建此文件,因为最近才添加了对该文件的支持。
~/.gitconfig
用户特定的配置文件。也称为“全局”配置文件。
$GIT_DIR/配置
存储库特定的配置文件。
如果没有给出更多选项,所有读取选项将读取所有这些可用文件。如果全局或系统范围的配置文件不可用,它们将被忽略。如果存储库配置文件不可用或不可读,git config 将退出并显示非零错误代码。但是,在任何情况下都不会发出错误消息。
文件按上面给出的顺序读取,发现的最后一个值优先于之前读取的值。当取多个值时,将使用来自所有文件的键的所有值。
回答by Michael Kohl
Lowest to highest priority:
从最低到最高优先级:
/etc/gitconfig
: system wide, edited when--system
parameter is used~/.gitconfig
: user specific configuration, edited when--global
parameter is used.git/config
: repository specific configuration
/etc/gitconfig
: 系统范围,在使用--system
参数时编辑~/.gitconfig
: 用户特定配置,--global
使用参数时编辑.git/config
: 存储库特定配置