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

Re: [PATCH] checkout doc: clarify command line args for "checkout paths" mode

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 11, 2017, 03:22 UTC
Message-ID
<20171011032240.GZ19555@aiede.mtv.corp.google.com>
In-Reply-To
<xmqqefqao1av.fsf_-_@gitster.mtv.corp.google.com>
Hi,
Junio C Hamano wrote:
[...]
> The source of the confusion is that -p(atch) is described as if it
> is just another "optional" part and its description is lumped
> together with the non patch mode, even though the actual end user
> experience is vastly different.

Makes sense. This should have been done as part of b831deda (2010-06-01), but better late than never.

Let's see how the patch goes...
[...]
Show 14 quoted lines
>  Documentation/git-checkout.txt | 32 +++++++++++++++++---------------
>  1 file changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
> index d6399c0af8..8e77a9de49 100644
> --- a/Documentation/git-checkout.txt
> +++ b/Documentation/git-checkout.txt
> @@ -13,7 +13,8 @@ SYNOPSIS
>  'git checkout' [-q] [-f] [-m] [--detach] <commit>
>  'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
>  'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
> +'git checkout' [<tree-ish>] [--] <pathspec>...
> -'git checkout' [-p|--patch] [<tree-ish>] [--] [<paths>...]
> +'git checkout' (-p|--patch) [<tree-ish>] [--] [<paths>...]

This file is inconsistent about <commit> versus <commit-ish>, <paths> versus <pathspec>, etc.

On the subject of <commit> versus <commit-ish>, nowadays <commit> is almost always preferable. Git commands consistently accept a tag pointing to a commit where a commit is expected, so emphasizing that feature by calling it a commit-ish only adds distraction. That's not what this patch is about, though.

Even for this particular form, the current file is inconsistent about whether to call the arguments '<paths>...' or '<pathspec>...'. "<paths>..." is even more strange when I think about it for a moment, since it is the plural of the plural of path --- i.e., it implies that each argument names multiple paths. Why does this patch use <pathspec> for the --no-patch case and <paths> for the --patch case?

Show 10 quoted lines
>  DESCRIPTION
>  -----------
> @@ -78,20 +79,13 @@ be used to detach HEAD at the tip of the branch (`git checkout
>  +
>  Omitting <branch> detaches HEAD at the tip of the current branch.
>  
> +'git checkout' [<tree-ish>] [--] <pathspec>...::
> +	Restore modified or deleted paths in the working tree by
> +	replacing with their original contents from the index, or
> +	the contents from a named <tree-ish> (most often a
This sentence is hard to read:
- "Restore ... in" reads oddly, as though this is an art conservation
  project that takes place in the working tree.  Is the intent that
  the command will bring the content of those paths back to the
  working tree, or something else?
- "replacing with" reads a little briskly and informally.  In this
  context, "replacing them with" will work better.
- "their original contents from" also reads oddly.  "Their original
  content from" would be fine, meaning their original content as
  obtained from.  I was tempted to read this as "The original contents
  of", but that was a misreading.
- Similarly, "the contents from" perhaps should be "the content of".

Stepping back, what problem is this solving in the original text? It said

	When <paths> or --patch are given, git checkout does *not*
	switch branches. It updates the named paths in the working
	tree from the index file or from a named <tree-ish> (most
	often a commit). In this case, the -b and --track options are
	meaningless and giving either of them results in an error. The
	<tree-ish> argument can be used to specify a specific tree-ish
	(i.e. commit, tag or tree) to update the index for the given
	paths before updating the working tree.

The "or --patch" would have to go, of course. Is the problem that the description focuses too much on what this form does not do? To fix that, it could say

	Replace matching paths in the working tree with content
	from the index or the named tree (most often a commit).  The
	<tree-ish> argument can be used to specify a specific tree,
	commit, or tag that will be used to update the entries for
	matching paths in the index before updating the working tree.

One thing that doesn't tell is what happens to files that are present in the worktree but deleted in the index or the named tree. Does "git checkout" delete them? I remember wishing that it would but don't remember whether it does, so it's probably worth mentioning the manpage giving an answer.

... aha, now I see the next paragraph where this text came from. I still think I like my example text based on the first paragraph better. :)

[...]
Show 10 quoted lines
> @@ -101,6 +95,14 @@ specific side of the merge can be checked out of the index by
>  using `--ours` or `--theirs`.  With `-m`, changes made to the working tree
>  file can be discarded to re-create the original conflicted merge result.
>  
> +'git checkout' (-p|--patch) [<tree-ish>] [--] [<pathspec>...]::
> +	This is similar to the "check out paths to the working tree
> +	from either the index or from a tree-ish" mode described
> +	above, but lets you use the interactive interface to show
> +	the "diff" output and choose which hunks to use in the
> +	result.
s/use/apply/, perhaps.

The options section explains --patch again. Maybe that should point back to here to avoid some duplication.

Thanks, Jonathan

Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 11 in “"man git-checkout", man page is inconsistent between SYNOPSIS and details”
  1. Robert P. J. DaySep 30, 2017
  2. Kevin DaudtSep 30, 2017
  3. Robert P. J. DaySep 30, 2017
  4. Robert P. J. DaySep 30, 2017
  5. Junio C HamanoOct 1, 2017
  6. Robert P. J. DayOct 1, 2017
  7. Junio C HamanoOct 2, 2017
  8. checkout doc: clarify command line args for "checkout paths" modeJunio C Hamano, Oct 11, 2017
  9. Jonathan NiederOct 11, 2017
  10. Junio C HamanoOct 11, 2017
  11. Jonathan NiederOct 11, 2017

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.