git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: checkout extra files

From
Philip Oakley <philipoakley@iee.org>
Date
Sep 8, 2012, 20:40 UTC
Message-ID
<3DA7C9D97E19414C81F8D73CB66171DA@PhilipOakley>
In-Reply-To
<7vk3w5woc4.fsf@alter.siamese.dyndns.org>
From: "Junio C Hamano" <gitster@pobox.com>
Sent: Friday, September 07, 2012 9:49 PM
Show 26 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> But that is not what is happening at all.  What goes on is far
>> simpler than that.
>>
>>  - the shell sees '*', matches it against working tree files, to
>>    obtain "f1" and "f2";
>>
>>  - the shell tells "git" to "checkout e6f935e -- f1 f2";
>>
>>  - "git" looks into the tree of e6f935e to find paths that match
>>    "f1" and "f2".
>>
>> When "git" is run by the shell in the last step, it has _no_ clue
>> that the end user typed "*" from the shell.  It only sees "f1" and
>> "f2" on the command line.  There is no "set T" to be intersected
>> with "set W", so stop thinking in those terms, and you will be fine.
>>
>> Now the question is, _you_ will be fine, but can the documentation
>> be updated in such a way so that it will help _others_ to also stop
>> thinking about "intersection between set W and set T"?  I do not
>> have a good answer to that.
>
> Let's do this.  I do not want a shell tutorial in "git checkout"
> documentation, but this would fit better in the documentation for
> the CLI convention.

The difficulty with putting it in gitcli is that it is referenced from almost nowhere, so won't provide help to the user.

Having said that, it would therefore be better to point folk at gitcli in a few more places, not just the 'see also' line at the very end of the general 'git' page, and buried within rev-parse.

Show 49 quoted lines
>
> -- >8 --
> 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 <gitster@pobox.com>
> ---
> Documentation/gitcli.txt | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git c/Documentation/gitcli.txt w/Documentation/gitcli.txt
> index ea17f7a..220621b 100644
> --- c/Documentation/gitcli.txt
> +++ w/Documentation/gitcli.txt
> @@ -38,6 +38,22 @@ arguments.  Here are the rules:
>    you have to say either `git diff HEAD --` or `git diff -- HEAD` to
>    disambiguate.
>
> + * 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.
> +
> 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.
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 36 in “checkout extra files”
  1. Angelo BorsottiSep 3, 2012
  2. Carlos Martín NietoSep 3, 2012
  3. Nguyen Thai Ngoc DuySep 3, 2012
  4. Junio C HamanoSep 3, 2012
  5. Nguyen Thai Ngoc DuySep 4, 2012
  6. Junio C HamanoSep 4, 2012
  7. Angelo BorsottiSep 4, 2012
  8. Junio C HamanoSep 4, 2012
  9. Junio C HamanoSep 4, 2012
  10. Junio C HamanoSep 4, 2012
  11. Junio C HamanoSep 7, 2012
  12. Philip OakleySep 8, 2012
  13. Junio C HamanoSep 9, 2012
  14. Matthieu MoySep 9, 2012
  15. Junio C HamanoSep 9, 2012
  16. Philip OakleySep 9, 2012
  17. Jeff KingSep 10, 2012
  18. Junio C HamanoSep 10, 2012
  19. Jeff KingSep 10, 2012
  20. Junio C HamanoSep 10, 2012
  21. 1/2 gitcli: formatting fixJunio C Hamano, Sep 10, 2012
  22. 2/2 gitcli: contrast wildcard given to shell and to gitJunio C Hamano, Sep 10, 2012
  23. Jeff KingSep 10, 2012
  24. Junio C HamanoSep 10, 2012
  25. Nguyen Thai Ngoc DuySep 4, 2012
  26. Junio C HamanoSep 4, 2012
  27. Carlos Martín NietoSep 3, 2012
  28. Carlos Martín NietoSep 4, 2012
  29. Angelo BorsottiSep 4, 2012
  30. Junio C HamanoSep 4, 2012
  31. Angelo BorsottiSep 4, 2012
  32. Junio C HamanoSep 4, 2012
  33. Philip OakleySep 4, 2012
  34. Junio C HamanoSep 4, 2012
  35. Junio C HamanoSep 8, 2012
  36. Junio C HamanoSep 10, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.