gpt4 book ai didi

git - 我的 Git 配置中的设置来自哪里?

转载 作者:IT王子 更新时间:2023-10-29 00:32:28 24 4
gpt4 key购买 nike

我注意到当我运行 git config -l

时,我有两个 core.autocrlf list
$ git config -l
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.name=name
user.email=email@example.com
core.autocrlf=true

最后三个(从 user.name 向下)是我的 C:\users\username\.gitconfig 文件中唯一的。其他的都是从哪里来的?为什么 core.autocrlf 被列出两次?

这是与 MSysGit 1.8.3 一起使用的,我还安装了 Sourcetree (Windows 7)。在 Sourcetree 中,我取消选中“允许 Sourcetree 修改您的全局 Git 配置文件”

最佳答案

Git 检查配置文件的四个位置:

  1. 你机器的系统 .gitconfig 文件。
  2. 您的用户 .gitconfig 文件位于 ~/.gitconfig
  3. 位于 $XDG_CONFIG_HOME/git/config$HOME/.config/git/config 的第二个用户特定配置文件。
  4. 本地仓库的配置文件.git/config

设置按以下顺序级联,每个文件添加或覆盖其上方文件中定义的设置。

  1. 系统配置。
  2. 用户配置。
  3. 特定于存储库的配置。

您可以使用以下命令查看每个文件定义的内容:

# System, applies to entire machine and all users
$ git config --system --list
$ git config --system --edit

# User defined
$ git config --global --list
$ git config --global --edit

您可以通过打开该存储库的文件 .git/config 来查看特定于存储库的文件定义了什么。

如果您在 Windows 上使用 MSysGit,您可能会在 %homepath% 指向的地方找到您的用户 ~/.gitconfig 文件,如果您使用 echo %homepath% 来自 Windows 命令提示符。

来自documentation for git config :

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.

All writing options will per default write to the repository specific configuration file. Note that this also affects options like --replace-all and --unset. git config will only ever change one file at a time.

You can override these rules either by command-line options or by environment variables. The --global and the --system options will limit the file used to the global or system-wide file respectively. The GIT_CONFIG environment variable has a similar effect, but you can specify any filename you want.

关于git - 我的 Git 配置中的设置来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17756753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com