git配置:列出所有变量及其默认值 - git config: list all variables and their default values

- 此内容更新于:2016-02-03
主题:

类似于MySQL命令显示所有变量中定义,而不只是那些,我希望看到一个列表的所有配置变量以及它们的默认值,而不仅仅是那些在我的定义。这是可能的吗?

原文:

Similar to the MySQL show variables command that shows all variables and not just the ones defined in my.ini, I would like to see a list of all config variables in git along with their default values, and not just those defined in my ~/.gitconfig.

Is this possible?

网友:你所寻找的是命令?其他VonC后回答你的问题。

(原文:are you looking for git config --list command? else VonC post answers to your question.)

网友:@rajuGT我不认为是哈利正在寻找,因为它只会返回配置在系统,显式地设置全局或局部的水平,而不是其他的设置没有设置默认值。

(原文:@rajuGT I don't think git config --list is what Harry is looking for, since it would only return the config explicitly set at system, global or local level, and not all the other settings not set, with their default values.)

解决方案:
讨论2013年在这个线程,要求SebastianSchuberth杰夫•金()添加:预期的输出当然是一个问题,但比这更根本的问题:甚至不知道什么是默认为任何给定的选项。它假定调用者知道如何处理一个设置值。这是与git配置;内部C代码相同的方式工作。实际违约是不必然通过配置可表现的。如。,我知道认为“复原”是截然不同的”“或”“,但设置只能屈服后两个值中的一个。我相信也有其他人,(我只是碰巧注意到一个本周)。(例如:)我当然可以看到一个论点,世界将是一个更好的地方如果代码有一个大桌子的选择及其描述,可能值,和违约,如果我们使用,生成文档以及验证输入。但是没有人去麻烦的构造,表和转换所有的调用者。和Jakub(JakubNar?bski)所提到的,这样一个中央表无法存储配置与git的外部程序。简而言之:git配置甚至不知道它管理的任何选项或值,但仅仅是一个“哑巴”前端写作/阅读不管你把它从一个文件中。注意:git配置了提交1771299(git0.99.9a,2005年10月)不同的程序可以应对不同的配置选项,尽管他们应该回到调用“git_default_config()“在任何配置选项名称,他们不认识。所以在内部,有一种方法来加载默认配置,使用提交72549df,git2.2.0-rc1,2014年11月,由同一Peff:当我们开始git-fetch计划,我们称之为git_config加载所有的配置,但是我们只回调处理的选择;我们不链。这意味着我们不能加载一些核心配置产生影响。例如,我们不加载,这影响我们是否创建reflogs裸存储库。我们先加载核心配置的取回,我们知道我们有看到另一个例子与提交3e1dd17git1.7.7-rc1,2011年8月用默认颜色配置。
原文:

That was debated in this thread in 2013, requested by Sebastian Schuberth, Jeff King (Peff) adding:

The expected output is certainly a problem, but the issue is more fundamental than that: git config does not even know what the default is for any given option.

It is assumed that the caller knows what to do with an unset value. And this is nothing to do with git config; the internal C code works the same way.
The actual defaults are not even necessarily expressible through the config.
E.g., I know that http.receivepack considers "unset" to be distinct either "true" or "false", but setting it can yield only one of those latter two values.
I'm sure there are others, too (I just happened to notice that one this week).

(For instance: gc.prune)

I could certainly see an argument that the world would be a better place if the code had a big table of options and their descriptions, possible values, and defaults, and if we used that to generate documentation as well as validate input.
But nobody has gone to the trouble to construct that table and convert all of the callers. And as Jakub (Jakub Narębski) mentioned, such a central table can do nothing for external programs that store their config alongside git's.

In short:

git config does not even know any of the options or values it manages, but just is a "dumb" front-end to writing / reading whatever you pass it to / from a file.


Note: git config was introduced in commit 1771299 (git 0.99.9a, Oct. 2005)

Different programs can react to different config options, although they should always fall back to calling "git_default_config()" on any config option name that they don't recognize.

So internally, there is a way to load default config, used as recently as commit 72549df, git 2.2.0-rc1, Nov. 2014, by the same Peff:

When we start the git-fetch program, we call git_config to load all config, but our callback only processes the fetch.prune option; we do not chain to git_default_config at all.

This means that we may not load some core configuration which will have an effect. For instance, we do not load core.logAllRefUpdates, which impacts whether or not we create reflogs in a bare repository.

Let's just load the core config at the start of fetch, so we know we have it

See another example with commit 3e1dd17, git 1.7.7-rc1, Aug. 2011 with the default color config.

楼主:不确定如果我买中给出的参数,作为新国旗/选项可以被添加在不提高向后兼容性问题。但我指向线程+1!

(原文:Not sure if I buy the arguments presented in there, as a new flag/option can always be added without raising backward compatibility concerns. But +1 for pointing me to the thread!)

网友:@Harry我不认为这是一个兼容性的问题,但是,我刚才编辑的回答,这一事实只是读取配置文件,不知道任何关于git设置。

(原文:@Harry I don't think it is a compatibility problem, but, as I just edited in the answer, the fact that git config is only there to read config files, not to know anything about git settings.)