Skip to content

Commit 6711759

Browse files
committed
Merge branch 'jc/maint-checkout-fileglob-doc' into maint-1.7.11
* jc/maint-checkout-fileglob-doc: gitcli: contrast wildcard given to shell and to git gitcli: formatting fix Document file-glob for "git checkout -- '*.c'"
2 parents 1403db4 + 8300016 commit 6711759

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Documentation/git-checkout.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ $ git checkout hello.c <3>
367367
<2> take a file out of another commit
368368
<3> restore hello.c from the index
369369
+
370+
If you want to check out _all_ C source files out of the index,
371+
you can say
372+
+
373+
------------
374+
$ git checkout -- '*.c'
375+
------------
376+
+
377+
Note the quotes around `*.c`. The file `hello.c` will also be
378+
checked out, even though it is no longer in the working tree,
379+
because the file globbing is used to match entries in the index
380+
(not in the working tree by the shell).
381+
+
370382
If you have an unfortunate branch that is named `hello.c`, this
371383
step would be confused as an instruction to switch to that branch.
372384
You should instead write:

Documentation/gitcli.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,28 @@ arguments. Here are the rules:
3737
file called HEAD in your work tree, `git diff HEAD` is ambiguous, and
3838
you have to say either `git diff HEAD --` or `git diff -- HEAD` to
3939
disambiguate.
40-
40+
+
4141
When writing a script that is expected to handle random user-input, it is
4242
a good practice to make it explicit which arguments are which by placing
4343
disambiguating `--` at appropriate places.
4444

45+
* Many commands allow wildcards in paths, but you need to protect
46+
them from getting globbed by the shell. These two mean different
47+
things:
48+
+
49+
--------------------------------
50+
$ git checkout -- *.c
51+
$ git checkout -- \*.c
52+
--------------------------------
53+
+
54+
The former lets your shell expand the fileglob, and you are asking
55+
the dot-C files in your working tree to be overwritten with the version
56+
in the index. The latter passes the `*.c` to Git, and you are asking
57+
the paths in the index that match the pattern to be checked out to your
58+
working tree. After running `git add hello.c; rm hello.c`, you will _not_
59+
see `hello.c` in your working tree with the former, but with the latter
60+
you will.
61+
4562
Here are the rules regarding the "flags" that you should follow when you are
4663
scripting git:
4764

0 commit comments

Comments
 (0)