Skip to content

Commit fe3ccc7

Browse files
committed
Merge branch 'ps/config-subcommands'
The operation mode options (like "--get") the "git config" command uses have been deprecated and replaced with subcommands (like "git config get"). * ps/config-subcommands: builtin/config: display subcommand help builtin/config: introduce "edit" subcommand builtin/config: introduce "remove-section" subcommand builtin/config: introduce "rename-section" subcommand builtin/config: introduce "unset" subcommand builtin/config: introduce "set" subcommand builtin/config: introduce "get" subcommand builtin/config: introduce "list" subcommand builtin/config: pull out function to handle `--null` builtin/config: pull out function to handle config location builtin/config: use `OPT_CMDMODE()` to specify modes builtin/config: move "fixed-value" option to correct group builtin/config: move option array around config: clarify memory ownership when preparing comment strings
2 parents b7a1d47 + 7b91d31 commit fe3ccc7

File tree

6 files changed

+812
-370
lines changed

6 files changed

+812
-370
lines changed

Documentation/git-config.txt

Lines changed: 126 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,22 @@ git-config - Get and set repository or global options
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git config' [<file-option>] [--type=<type>] [--comment=<message>] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] <name> [<value> [<value-pattern>]]
13-
'git config' [<file-option>] [--type=<type>] [--comment=<message>] --add <name> <value>
14-
'git config' [<file-option>] [--type=<type>] [--comment=<message>] [--fixed-value] --replace-all <name> <value> [<value-pattern>]
15-
'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get <name> [<value-pattern>]
16-
'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all <name> [<value-pattern>]
17-
'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp <name-regex> [<value-pattern>]
18-
'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch <name> <URL>
19-
'git config' [<file-option>] [--fixed-value] --unset <name> [<value-pattern>]
20-
'git config' [<file-option>] [--fixed-value] --unset-all <name> [<value-pattern>]
21-
'git config' [<file-option>] --rename-section <old-name> <new-name>
22-
'git config' [<file-option>] --remove-section <name>
23-
'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
24-
'git config' [<file-option>] --get-color <name> [<default>]
12+
'git config list' [<file-option>] [<display-option>] [--includes]
13+
'git config get' [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>
14+
'git config set' [<file-option>] [--type=<type>] [--all] [--value=<value>] [--fixed-value] <name> <value>
15+
'git config unset' [<file-option>] [--all] [--value=<value>] [--fixed-value] <name> <value>
16+
'git config rename-section' [<file-option>] <old-name> <new-name>
17+
'git config remove-section' [<file-option>] <name>
18+
'git config edit' [<file-option>]
2519
'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
26-
'git config' [<file-option>] -e | --edit
2720

2821
DESCRIPTION
2922
-----------
3023
You can query/set/replace/unset options with this command. The name is
3124
actually the section and the key separated by a dot, and the value will be
3225
escaped.
3326

34-
Multiple lines can be added to an option by using the `--add` option.
27+
Multiple lines can be added to an option by using the `--append` option.
3528
If you want to update or unset an option which can occur on multiple
3629
lines, a `value-pattern` (which is an extended regular expression,
3730
unless the `--fixed-value` option is given) needs to be given. Only the
@@ -74,6 +67,42 @@ On success, the command returns the exit code 0.
7467
A list of all available configuration variables can be obtained using the
7568
`git help --config` command.
7669

70+
COMMANDS
71+
--------
72+
73+
list::
74+
List all variables set in config file, along with their values.
75+
76+
get::
77+
Emits the value of the specified key. If key is present multiple times
78+
in the configuration, emits the last value. If `--all` is specified,
79+
emits all values associated with key. Returns error code 1 if key is
80+
not present.
81+
82+
set::
83+
Set value for one or more config options. By default, this command
84+
refuses to write multi-valued config options. Passing `--all` will
85+
replace all multi-valued config options with the new value, whereas
86+
`--value=` will replace all config options whose values match the given
87+
pattern.
88+
89+
unset::
90+
Unset value for one or more config options. By default, this command
91+
refuses to unset multi-valued keys. Passing `--all` will unset all
92+
multi-valued config options, whereas `--value` will unset all config
93+
options whose values match the given pattern.
94+
95+
rename-section::
96+
Rename the given section to a new name.
97+
98+
remove-section::
99+
Remove the given section from the configuration file.
100+
101+
edit::
102+
Opens an editor to modify the specified config file; either
103+
`--system`, `--global`, `--local` (default), `--worktree`, or
104+
`--file <config-file>`.
105+
77106
[[OPTIONS]]
78107
OPTIONS
79108
-------
@@ -82,10 +111,9 @@ OPTIONS
82111
Default behavior is to replace at most one line. This replaces
83112
all lines matching the key (and optionally the `value-pattern`).
84113

85-
--add::
114+
--append::
86115
Adds a new line to the option without altering any existing
87-
values. This is the same as providing '^$' as the `value-pattern`
88-
in `--replace-all`.
116+
values. This is the same as providing '--value=^$' in `set`.
89117

90118
--comment <message>::
91119
Append a comment at the end of new or modified lines.
@@ -99,22 +127,16 @@ OPTIONS
99127
not contain linefeed characters (no multi-line comments are
100128
permitted).
101129

102-
--get::
103-
Get the value for a given key (optionally filtered by a regex
104-
matching the value). Returns error code 1 if the key was not
105-
found and the last value if multiple key values were found.
130+
--all::
131+
With `get`, return all values for a multi-valued key.
106132

107-
--get-all::
108-
Like get, but returns all values for a multi-valued key.
133+
---regexp::
134+
With `get`, interpret the name as a regular expression. Regular
135+
expression matching is currently case-sensitive and done against a
136+
canonicalized version of the key in which section and variable names
137+
are lowercased, but subsection names are not.
109138

110-
--get-regexp::
111-
Like --get-all, but interprets the name as a regular expression and
112-
writes out the key names. Regular expression matching is currently
113-
case-sensitive and done against a canonicalized version of the key
114-
in which section and variable names are lowercased, but subsection
115-
names are not.
116-
117-
--get-urlmatch <name> <URL>::
139+
--url=<URL>::
118140
When given a two-part <name> as <section>.<key>, the value for
119141
<section>.<URL>.<key> whose <URL> part matches the best to the
120142
given URL is returned (if no such key exists, the value for
@@ -178,22 +200,6 @@ See also <<FILES>>.
178200
section in linkgit:gitrevisions[7] for a more complete list of
179201
ways to spell blob names.
180202

181-
--remove-section::
182-
Remove the given section from the configuration file.
183-
184-
--rename-section::
185-
Rename the given section to a new name.
186-
187-
--unset::
188-
Remove the line matching the key from config file.
189-
190-
--unset-all::
191-
Remove all lines matching the key from config file.
192-
193-
-l::
194-
--list::
195-
List all variables set in config file, along with their values.
196-
197203
--fixed-value::
198204
When used with the `value-pattern` argument, treat `value-pattern` as
199205
an exact string instead of a regular expression. This will restrict
@@ -248,8 +254,8 @@ Valid `<type>`'s include:
248254
contain line breaks.
249255

250256
--name-only::
251-
Output only the names of config variables for `--list` or
252-
`--get-regexp`.
257+
Output only the names of config variables for `list` or
258+
`get`.
253259

254260
--show-origin::
255261
Augment the output of all queried config options with the
@@ -273,38 +279,71 @@ Valid `<type>`'s include:
273279
When the color setting for `name` is undefined, the command uses
274280
`color.ui` as fallback.
275281

276-
--get-color <name> [<default>]::
277-
278-
Find the color configured for `name` (e.g. `color.diff.new`) and
279-
output it as the ANSI color escape sequence to the standard
280-
output. The optional `default` parameter is used instead, if
281-
there is no color configured for `name`.
282-
+
283-
`--type=color [--default=<default>]` is preferred over `--get-color`
284-
(but note that `--get-color` will omit the trailing newline printed by
285-
`--type=color`).
286-
287-
-e::
288-
--edit::
289-
Opens an editor to modify the specified config file; either
290-
`--system`, `--global`, `--local` (default), `--worktree`, or
291-
`--file <config-file>`.
292-
293282
--[no-]includes::
294283
Respect `include.*` directives in config files when looking up
295284
values. Defaults to `off` when a specific file is given (e.g.,
296285
using `--file`, `--global`, etc) and `on` when searching all
297286
config files.
298287

299288
--default <value>::
300-
When using `--get`, and the requested variable is not found, behave as if
289+
When using `get`, and the requested variable is not found, behave as if
301290
<value> were the value assigned to that variable.
302291

292+
DEPRECATED MODES
293+
----------------
294+
295+
The following modes have been deprecated in favor of subcommands. It is
296+
recommended to migrate to the new syntax.
297+
298+
'git config <name>'::
299+
Replaced by `git config get <name>`.
300+
301+
'git config <name> <value> [<value-pattern>]'::
302+
Replaced by `git config set [--value=<pattern>] <name> <value>`.
303+
304+
-l::
305+
--list::
306+
Replaced by `git config list`.
307+
308+
--get <name> [<value-pattern>]::
309+
Replaced by `git config get [--value=<pattern>] <name>`.
310+
311+
--get-all <name> [<value-pattern>]::
312+
Replaced by `git config get [--value=<pattern>] --all --show-names <name>`.
313+
314+
--get-regexp <name-regexp>::
315+
Replaced by `git config get --all --show-names --regexp <name-regexp>`.
316+
317+
--get-urlmatch <name> <URL>::
318+
Replaced by `git config get --all --show-names --url=<URL> <name>`.
319+
320+
--get-color <name> [<default>]::
321+
Replaced by `git config get --type=color [--default=<default>] <name>`.
322+
323+
--add <name> <value>::
324+
Replaced by `git config set --append <name> <value>`.
325+
326+
--unset <name> [<value-pattern>]::
327+
Replaced by `git config unset [--value=<pattern>] <name>`.
328+
329+
--unset-all <name> [<value-pattern>]::
330+
Replaced by `git config unset [--value=<pattern>] --all <name>`.
331+
332+
--rename-section <old-name> <new-name>::
333+
Replaced by `git config rename-section <old-name> <new-name>`.
334+
335+
--remove-section <name>::
336+
Replaced by `git config remove-section <name>`.
337+
338+
-e::
339+
--edit::
340+
Replaced by `git config edit`.
341+
303342
CONFIGURATION
304343
-------------
305344
`pager.config` is only respected when listing configuration, i.e., when
306-
using `--list` or any of the `--get-*` which may return multiple results.
307-
The default is to use a pager.
345+
using `list` or `get` which may return multiple results. The default is to use
346+
a pager.
308347

309348
[[FILES]]
310349
FILES
@@ -346,8 +385,8 @@ precedence over values read earlier. When multiple values are taken then all
346385
values of a key from all files will be used.
347386

348387
By default, options are only written to the repository specific
349-
configuration file. Note that this also affects options like `--replace-all`
350-
and `--unset`. *'git config' will only ever change one file at a time*.
388+
configuration file. Note that this also affects options like `set`
389+
and `unset`. *'git config' will only ever change one file at a time*.
351390

352391
You can limit which configuration sources are read from or written to by
353392
specifying the path of a file with the `--file` option, or by specifying a
@@ -482,23 +521,23 @@ Given a .git/config like this:
482521
you can set the filemode to true with
483522

484523
------------
485-
% git config core.filemode true
524+
% git config set core.filemode true
486525
------------
487526

488527
The hypothetical proxy command entries actually have a postfix to discern
489528
what URL they apply to. Here is how to change the entry for kernel.org
490529
to "ssh".
491530

492531
------------
493-
% git config core.gitproxy '"ssh" for kernel.org' 'for kernel.org$'
532+
% git config set --value='for kernel.org$' core.gitproxy '"ssh" for kernel.org'
494533
------------
495534

496535
This makes sure that only the key/value pair for kernel.org is replaced.
497536

498537
To delete the entry for renames, do
499538

500539
------------
501-
% git config --unset diff.renames
540+
% git config unset diff.renames
502541
------------
503542

504543
If you want to delete an entry for a multivar (like core.gitproxy above),
@@ -507,72 +546,66 @@ you have to provide a regex matching the value of exactly one line.
507546
To query the value for a given key, do
508547

509548
------------
510-
% git config --get core.filemode
511-
------------
512-
513-
or
514-
515-
------------
516-
% git config core.filemode
549+
% git config get core.filemode
517550
------------
518551

519552
or, to query a multivar:
520553

521554
------------
522-
% git config --get core.gitproxy "for kernel.org$"
555+
% git config get --value="for kernel.org$" core.gitproxy
523556
------------
524557

525558
If you want to know all the values for a multivar, do:
526559

527560
------------
528-
% git config --get-all core.gitproxy
561+
% git config get --all --show-names core.gitproxy
529562
------------
530563

531564
If you like to live dangerously, you can replace *all* core.gitproxy by a
532565
new one with
533566

534567
------------
535-
% git config --replace-all core.gitproxy ssh
568+
% git config set --all core.gitproxy ssh
536569
------------
537570

538571
However, if you really only want to replace the line for the default proxy,
539572
i.e. the one without a "for ..." postfix, do something like this:
540573

541574
------------
542-
% git config core.gitproxy ssh '! for '
575+
% git config set --value='! for ' core.gitproxy ssh
543576
------------
544577

545578
To actually match only values with an exclamation mark, you have to
546579

547580
------------
548-
% git config section.key value '[!]'
581+
% git config set --value='[!]' section.key value
549582
------------
550583

551584
To add a new proxy, without altering any of the existing ones, use
552585

553586
------------
554-
% git config --add core.gitproxy '"proxy-command" for example.com'
587+
% git config set --append core.gitproxy '"proxy-command" for example.com'
555588
------------
556589

557590
An example to use customized color from the configuration in your
558591
script:
559592

560593
------------
561594
#!/bin/sh
562-
WS=$(git config --get-color color.diff.whitespace "blue reverse")
563-
RESET=$(git config --get-color "" "reset")
595+
WS=$(git config get --type=color --default="blue reverse" color.diff.whitespace)
596+
RESET=$(git config get --type=color --default="reset" "")
564597
echo "${WS}your whitespace color or blue reverse${RESET}"
565598
------------
566599

567600
For URLs in `https://weak.example.com`, `http.sslVerify` is set to
568601
false, while it is set to `true` for all others:
569602

570603
------------
571-
% git config --type=bool --get-urlmatch http.sslverify https://good.example.com
604+
% git config get --type=bool --url=https://good.example.com http.sslverify
572605
true
573-
% git config --type=bool --get-urlmatch http.sslverify https://weak.example.com
606+
% git config get --type=bool --url=https://weak.example.com http.sslverify
574607
false
575-
% git config --get-urlmatch http https://weak.example.com
608+
% git config get --url=https://weak.example.com http
576609
http.cookieFile /tmp/cookie.txt
577610
http.sslverify false
578611
------------

0 commit comments

Comments
 (0)