From caae319e49e236205d463de2ecf24ce5aae642ab Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 4 Sep 2012 08:28:27 -0700 Subject: [PATCH 1/3] Document file-glob for "git checkout -- '*.c'" Just like we give a similar example in "git add" documentation. Signed-off-by: Junio C Hamano --- Documentation/git-checkout.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 63a251612a..5634efffa0 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -367,6 +367,18 @@ $ git checkout hello.c <3> <2> take a file out of another commit <3> restore hello.c from the index + +If you want to check out _all_ C source files out of the index, +you can say ++ +------------ +$ git checkout -- '*.c' +------------ ++ +Note the quotes around `*.c`. The file `hello.c` will also be +checked out, even though it is no longer in the working tree, +because the file globbing is used to match entries in the index +(not in the working tree by the shell). ++ If you have an unfortunate branch that is named `hello.c`, this step would be confused as an instruction to switch to that branch. You should instead write: From 008566e0f8ef9751c43197f40ac08d3bdfce78a7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 10 Sep 2012 12:47:38 -0700 Subject: [PATCH 2/3] gitcli: formatting fix The paragraph to encourage use of "--" in scripts belongs to the bullet point that describes the behaviour for a command line without the explicit "--" disambiguation; it is not a supporting explanation for the entire bulletted list, and it is wrong to make it a separate paragraph outside the list. Signed-off-by: Junio C Hamano --- Documentation/gitcli.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index ea17f7a53b..c4edf042d4 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -37,7 +37,7 @@ arguments. Here are the rules: file called HEAD in your work tree, `git diff HEAD` is ambiguous, and you have to say either `git diff HEAD --` or `git diff -- HEAD` to disambiguate. - ++ When writing a script that is expected to handle random user-input, it is a good practice to make it explicit which arguments are which by placing disambiguating `--` at appropriate places. From 8300016e0ab6959c4b45f64ec585832726430fc7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 7 Sep 2012 13:49:15 -0700 Subject: [PATCH 3/3] gitcli: contrast wildcard given to shell and to git People who are not used to working with shell may intellectually understand how the command line argument is massaged by the shell but still have a hard time visualizing the difference between letting the shell expand fileglobs and having Git see the fileglob to use as a pathspec. Signed-off-by: Junio C Hamano --- Documentation/gitcli.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index c4edf042d4..00b8403225 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -42,6 +42,23 @@ When writing a script that is expected to handle random user-input, it is a good practice to make it explicit which arguments are which by placing disambiguating `--` at appropriate places. + * Many commands allow wildcards in paths, but you need to protect + them from getting globbed by the shell. These two mean different + things: ++ +-------------------------------- +$ git checkout -- *.c +$ git checkout -- \*.c +-------------------------------- ++ +The former lets your shell expand the fileglob, and you are asking +the dot-C files in your working tree to be overwritten with the version +in the index. The latter passes the `*.c` to Git, and you are asking +the paths in the index that match the pattern to be checked out to your +working tree. After running `git add hello.c; rm hello.c`, you will _not_ +see `hello.c` in your working tree with the former, but with the latter +you will. + Here are the rules regarding the "flags" that you should follow when you are scripting git: