问题
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?
回答1:
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 thathttp.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 togit_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.
回答2:
git config --global -l
for global variables or git config -l
for local repository variables
P.S.: I know have passed 2 years since you posted the question, but I was looking for the same thing and I read this post so I guessed users like me would have wanted a solution to their problem and I posted a reply, even if you probabily have solved your problem long time ago.
回答3:
This method won't get you your settings along with the defaults, but this is a pretty solid method of getting the documented settings (and their defaults, if documented):
First get the Documentation from the source repo
svn export https://github.com/git/git/trunk/Documentation
or if you don't have svn
,
curl -L https://api.github.com/repos/git/git/tarball/master | tar -xvzf- --strip-components=1 --wildcards --no-anchored 'Documentation/*'
Enter the directory
cd Documentation
Begin grep
. I have two versions: one detailed, and one more compact (likely missing details). I'll use the longer flag names below for (some) clarity.
First the compact version:
grep --initial-tab \
--recursive \
--binary-files=without-match \
--no-filename \
--only-matching \
--perl-regexp \
--null-data \
--regexp='(?ms)(?:^[a-z][a-zA-Z]+\.[<>()*.a-zA-Z]+::\v+)+?(?:(?:\v|\h+\V+\v))+(?:\v|\Z)'
For the more 'detailed' version simply change the --regexp=
flag to
(?ms)(?:^[a-z][a-zA-Z]+\.[<>()*.a-zA-Z]+::\v+)+?(?:(?:\v|\h+\V+\v))+(?:\+\v+(?:--\v+.+?--|[^+]\V+(?!::\v))+)*(?:\v|\Z)
which expanded is
(?ms)
(?:
^[a-z][a-zA-Z]+\.
[<>()*.a-zA-Z]+::\v+
)+?
(?:
(?:\v|\h+\V+\v)
)+
(?:
\+\v+
(?:
--\v+
.+?
--
|
[^+]\V+(?!::\v)
)+
)*
(?:\v|\Z)
And since this is all based on regex extraction, it goes without saying that this may break someday (if they change the txt
file documentation formatting).
Some sample output--note that not all of them have default values:
core.hideDotFiles::
(Windows-only) If true, mark newly-created directories and files whose
name starts with a dot as hidden. If 'dotGitOnly', only the `.git/`
directory is hidden, but no other files starting with a dot. The
default mode is 'dotGitOnly'.
core.precomposeUnicode::
This option is only used by Mac OS implementation of Git.
When core.precomposeUnicode=true, Git reverts the unicode decomposition
of filenames done by Mac OS. This is useful when sharing a repository
between Mac OS and Linux or Windows.
(Git for Windows 1.7.10 or higher is needed, or Git under cygwin 1.7).
When false, file names are handled fully transparent by Git,
which is backward compatible with older versions of Git.
core.protectHFS::
If set to true, do not allow checkout of paths that would
be considered equivalent to `.git` on an HFS+ filesystem.
Defaults to `true` on Mac OS, and `false` elsewhere.
core.protectNTFS::
If set to true, do not allow checkout of paths that would
cause problems with the NTFS filesystem, e.g. conflict with
8.3 "short" names.
Defaults to `true` on Windows, and `false` elsewhere.
core.fsmonitor::
If set, the value of this variable is used as a command which
will identify all files that may have changed since the
requested date/time. This information is used to speed up git by
avoiding unnecessary processing of files that have not changed.
See the "fsmonitor-watchman" section of linkgit:githooks[5].
core.trustctime::
If false, the ctime differences between the index and the
working tree are ignored; useful when the inode change time
is regularly modified by something outside Git (file system
crawlers and some backup systems).
See linkgit:git-update-index[1]. True by default.
core.splitIndex::
If true, the split-index feature of the index will be used.
See linkgit:git-update-index[1]. False by default.
core.untrackedCache::
Determines what to do about the untracked cache feature of the
index. It will be kept, if this variable is unset or set to
`keep`. It will automatically be added if set to `true`. And
it will automatically be removed, if set to `false`. Before
setting it to `true`, you should check that mtime is working
properly on your system.
See linkgit:git-update-index[1]. `keep` by default.
core.quotePath::
Commands that output paths (e.g. 'ls-files', 'diff'), will
quote "unusual" characters in the pathname by enclosing the
pathname in double-quotes and escaping those characters with
backslashes in the same way C escapes control characters (e.g.
`\t` for TAB, `\n` for LF, `\\` for backslash) or bytes with
values larger than 0x80 (e.g. octal `\302\265` for "micro" in
UTF-8). If this variable is set to false, bytes higher than
0x80 are not considered "unusual" any more. Double-quotes,
backslash and control characters are always escaped regardless
of the setting of this variable. A simple space character is
not considered "unusual". Many commands can output pathnames
completely verbatim using the `-z` option. The default value
is true.
来源:https://stackoverflow.com/questions/33720397/git-config-list-all-variables-and-their-default-values