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>
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+ +
370382If you have an unfortunate branch that is named `hello.c`, this
371383step would be confused as an instruction to switch to that branch.
372384You should instead write:
Original file line number Diff line number Diff 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+ +
4141When writing a script that is expected to handle random user-input, it is
4242a good practice to make it explicit which arguments are which by placing
4343disambiguating `--` 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+
4562Here are the rules regarding the "flags" that you should follow when you are
4663scripting git:
4764
You can’t perform that action at this time.
0 commit comments