我的Git配置中的设置来自哪里? [英] Where do the settings in my Git configuration come from?

查看:160
本文介绍了我的Git配置中的设置来自哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到当我运行 git config -l <​​/ code> <2>时,我有2个> core.autocrlf / p>

  $ 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

最后3个(来自user.name)是我的 c:\users\username\.gitconfig 文件。其他所有来自哪里?为什么core.autocrlf列出两次?



这是msysgit 1.8.3,我也安装了SourceTree(Windows 7)。在SourceTree中,我没有选中允许SourceTree修改您的全局Git配置文件。

解决方案

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


  1. 您的计算机系统 .gitconfig 文件。

  2. 您的用户 .gitconfig 位于〜/ .gitconfig 的文件。

  3. 位于 $ XDG_CONFIG_HOME / git / config $ HOME / .config / git / config 的第二个用户特定配置文件c $ c>。

  4. 本地repo的配置文件 .git / config

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


  1. 系统配置

  2. 用户配置。

  3. 特定于配置的配置。 >

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

     #系统,适用于整个机器和所有用户
    $ git config --system --list
    $ git config --system --edit

    #用户定义
    $ git config --global --list
    $ git config --global --edit

    您可以通过打开该回购文件 .git / config 来查看回购专用文件的定义。



    如果您在Windows上使用msysgit,您可能会发现您的用户〜/ .gitconfig 文件,其中<$如果您在Windows命令提示符下使用 echo%homepath%,c $ c>%homepath%指向



    git config
    $ b


    如果未使用 - file 显式设置,则有四个其中 git config 的文件将搜索配置选项:


    • $(前缀)/ etc / gitconfig



      系统级配置文件。


    • $ XDG_CONFIG_HOME / git / config



      第二个用户特定的配置文件。如果 $ XDG_CONFIG_HOME
      未设置或为空, $ HOME / .config / git / config 将会用过的。这个文件中设置的任何
      单值变量都将被
      覆盖,无论它在〜/ .gitconfig 中。如果您有时使用旧版本的Git,最好不要创建此
      文件,因为对
      文件的支持最近才添加。


    • 〜/ .gitconfig



      用户特定的配置文件。也称为全局配置
      文件。


    • $ GIT_DIR / config



      特定于存储库的配置文件

    • ,所有阅读选项将读取所有可用的
      这些文件。如果全局或系统范围的
      配置文件不可用,它们将被忽略。如果
      存储库配置文件不可用或不可读, git config 将以非零错误代码退出。但是,在任何情况下,
      都不会发出错误消息。


      这些文件按上面给出的顺序读取,最后一个值为
      优先于先前读取的值。当多个值为
      时,将使用所有文件中的所有键值。



      所有编写选项将默认写入存储库特定的
      配置文件。请注意,这也会影响诸如
      - replace-all - unset 之类的选项。 git config 一次只能更改
      一个文件。



      您可以通过命令行选项或
      环境变量覆盖这些规则。 - global - system 选项将限制用于全局或系统的文件
      分别为全文档。
      GIT_CONFIG 环境变量具有类似的效果,但是您
      可以指定您想要的任何文件名。



    I've noticed that I have 2 listings for core.autocrlf when I run git config -l

    $ 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
    

    Those last 3 (from user.name down) are the only ones in my c:\users\username\.gitconfig file. Where are all of the other ones coming from? Why is core.autocrlf listed twice?

    This is with msysgit 1.8.3 and I also have SourceTree installed (Windows 7). In SourceTree I have unchecked the "Allow SourceTree to modify your global Git config files"

    解决方案

    Git checks 4 places for a configuration file:

    1. Your machine's system .gitconfig file.
    2. Your user .gitconfig file located at ~/.gitconfig.
    3. A second user-specific configuration file located at $XDG_CONFIG_HOME/git/config or $HOME/.config/git/config.
    4. The local repo's config file .git/config.

    The settings cascade in the following order, with each file adding or overriding settings defined in the file above it.

    1. System config.
    2. User config.
    3. Repo-specific config.

    You can see what each file has defined using the following commands:

    # 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
    

    You can see what just the repo-specific file has defined by opening up the file .git/config for that repo.

    If you're using msysgit on Windows, you'll probably find your user ~/.gitconfig file where ever %homepath% points to if you use echo %homepath% from a Windows command prompt.

    From the 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配置中的设置来自哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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