File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -367,6 +367,18 @@ $ git checkout hello.c <3>
367
367
<2> take a file out of another commit
368
368
<3> restore hello.c from the index
369
369
+
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
+ +
370
382
If you have an unfortunate branch that is named `hello.c`, this
371
383
step would be confused as an instruction to switch to that branch.
372
384
You should instead write:
Original file line number Diff line number Diff line change @@ -37,11 +37,28 @@ arguments. Here are the rules:
37
37
file called HEAD in your work tree, `git diff HEAD` is ambiguous, and
38
38
you have to say either `git diff HEAD --` or `git diff -- HEAD` to
39
39
disambiguate.
40
-
40
+ +
41
41
When writing a script that is expected to handle random user-input, it is
42
42
a good practice to make it explicit which arguments are which by placing
43
43
disambiguating `--` at appropriate places.
44
44
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
+
45
62
Here are the rules regarding the "flags" that you should follow when you are
46
63
scripting git:
47
64
You can’t perform that action at this time.
0 commit comments