在提交时如何评估Git配置? [英] How is the Git config evaluated when commit-ing?

查看:148
本文介绍了在提交时如何评估Git配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置My First Git Repo并运行;

  git config --list 

我注意到我有多个条目用于某些配置值;

  core.autocrlf =输入
[...]
core.autocrlf = false

我猜这些值会翻倍,因为它们出现在多个配置文件(系统,全局,文件)中的一个以上。我的问题是,这些值中的哪一个优先?配置文件是逐行读取的,最后一个条目是在提交过程中使用的吗?

解决方案

借用MYYN,这三个地方是找到配置文件的地方:
$ b $ ul
$ GIT_DIR / config

  • 〜/ .gitconfig(--global)

  • $(前缀)/ etc / gitconfig



  • 好吧,想象一下,您可以将您的电子邮件全局设置为niko.schwarz@gmail.com。现在,我们做一个新的回购:

      $ cd / tmp 
    $ mkdir try&& cd试试
    $ git init
    $ git config user.email niko.schwarz@s-i.ch
    $ touch hi
    $ git -add。
    $ git commit -m'bla'

    然后,您的user.email将被设置到两个值:

      $ git config --list | grep niko.schwarz 
    user.email=niko.schwarz@gmail.com
    user.email=niko.schwarz@si.ch

    但是,如果您查看日志,则电子邮件地址将设置为特定于回购的电子邮件地址:

      $ git log | grep niko.schwarz 
    作者:Niko Schwarz< niko.schwarz@s-i.ch>
    签名:Niko Schwarz< niko.schwarz@s-i.ch>

    因此,局部节拍是全局的,这是列出值的顺序。现在,随着信念的飞跃,我确实认为git config --list显示的东西顺序使后者优先。


    I'm setting up My First Git Repo, and on running;

    git config --list
    

    I've noticed I've got multiple entries for certain config values;

    core.autocrlf=input
    [...]
    core.autocrlf=false
    

    I'm guessing these values are doubled up because they appear in more than one of the various config files (system, global, file). My question is, which of these values takes precedence? Is the config file read line by line, and the last entry taken as the one used during a commit?

    解决方案

    Borrowed from The MYYN, these are the three places where to find config files:

    • $GIT_DIR/config
    • ~/.gitconfig (--global)
    • $(prefix)/etc/gitconfig

    Ok, imagine you globally set your email to niko.schwarz@gmail.com. Now, we make a new repo:

    $ cd /tmp
    $ mkdir try && cd try
    $ git init
    $ git config user.email niko.schwarz@s-i.ch
    $ touch hi
    $ git -add .
    $ git commit -m 'bla'
    

    Then, your user.email will be set to two values:

    $ git config --list | grep niko.schwarz
    user.email=niko.schwarz@gmail.com
    user.email=niko.schwarz@s-i.ch
    

    But if you look at the log, the email address will be set to the one specific to the repo:

    $ git log | grep niko.schwarz
    Author: Niko Schwarz <niko.schwarz@s-i.ch>
        Signed-off-by: Niko Schwarz <niko.schwarz@s-i.ch>
    

    Therefore, local beats global, which is the order in which the values are listed. Now, with a bit of a leap of faith, I'd indeed assume that git config --list shows things in an order that makes latter ones take precedence.

    这篇关于在提交时如何评估Git配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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