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

Re: [PATCH v2] git-checkout.txt: Document "git checkout <pathspec>" better

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 18, 2015, 01:07 UTC
Message-ID
<xmqqy4jh4ydz.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CACsJy8COWS+LoVOxKmAdMhk8FPEnOZpJ1mesJr0orOD7wN2Qsg@mail.gmail.com>
Duy Nguyen <pclouds@gmail.com> writes:
Show 8 quoted lines
>>> How about this:
>>>
>>> git-checkout - Switch branches or restore changes to the working tree
>>
>> Gahh.  We are NOT restoring CHANGES.  We are restoring the whole
>> contents to a path.
>
> "the whole contents" is only true when --patch is not used, I think.

I've seen that people repeat this "patch is not the whole" and have ignored that comment; you really need to think if that nitpick adds anything of value to the description before repeating it.

The "patch" interface of course allows you to pick and choose. You have some contents (call it W) in the working tree. You have different contents (call it X) somewhere else. Being able to do that is the whole point of the feature.

But what is presented you as the choice to pick or ignore? It is the difference between W and X. If you take none from what is offered, you won't check out anything. If you take all of them, you check out the whole of X. The result is somewhere in between.

An important point that everybody who repeats "patch is not the whole" seems to be missing is that it will never be somewhere between W and Y (the latter of which is different from X).

Now, what is the X in this operation?

It is either what is registered in the index, or in the tree-ish specified on the command line.

So I'd say that the right mental model to understand the "--patch" feature is that it allows you to check out the whole contents from elsewhere; after the command line argument selects from where, i.e. either from the index or from a tree-ish, you _additionally_ have a choice to pick which part of that whole to use. The diff between W and HEAD or W and index, i.e. "CHANGES", does not play any part of this selection process.

Previous: Duy NguyenNext: Matthieu Moy
Message 19 of 20 in “git-checkout.txt: Document "git checkout <pathspec>" better”
  1. git-checkout.txt: Document "git checkout <pathspec>" betterTorsten Bögershausen, Jun 17, 2015
  2. Duy NguyenJun 17, 2015
  3. Matthieu MoyJun 17, 2015
  4. Andres G. AragonesesJun 17, 2015
  5. Matthieu MoyJun 17, 2015
  6. Andres G. AragonesesJun 17, 2015
  7. Matthieu MoyJun 17, 2015
  8. Junio C HamanoJun 17, 2015
  9. Torsten BögershausenJun 17, 2015
  10. Junio C HamanoJun 17, 2015
  11. Torsten BögershausenJun 17, 2015
  12. Matthieu MoyJun 17, 2015
  13. Andres G. AragonesesJun 17, 2015
  14. Junio C HamanoJun 17, 2015
  15. Junio C HamanoJun 17, 2015
  16. Torsten BögershausenJun 17, 2015
  17. Junio C HamanoJun 17, 2015
  18. Duy NguyenJun 18, 2015
  19. Junio C HamanoJun 18, 2015
  20. Matthieu MoyJun 18, 2015

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.