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

Re: "man git-checkout", man page is inconsistent between SYNOPSIS and details

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 1, 2017, 03:49 UTC
Message-ID
<xmqqo9prv86l.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<alpine.LFD.2.21.1709301800060.7869@localhost.localdomain>
"Robert P. J. Day" <rpjday@crashcourse.ca> writes:
>   it's simply a matter of the forms not matching between the SYNOPSIS
> and the DESCRIPTION sections. am i making sense?

I think the whole thing is wrong and the root cause is because the (relatively newer) description of the "--patch" mode lazily tried to piggy-back the description of existing "check out from the index or tree-ish" mode, ending up in a confusing description.

"git checkout [<tree-ish>] -- <pathspec>..." is a way to overwrite the working tree files with what is in the object store. When you give <tree-ish>, the paths that match the <pathspec> are grabbed from the tree-ish, added to the index, and overwrites the working tree files. In this mode, you need to have at least one pathspec element on the command line, so <pathspec> is mandatory. With no pathspec, if <tree-ish> happens to be a commit-ish, then the operation is "check out the commit, so that we can prepare to make a new commit as its child".

"git checkout -p/--patch [<tree-ish>]" is quite different. It can be used without any <pathspec> to pick and choose from all changes treewide, but you can use <pathspec> to limit the changes you need to choose from.

Something like the following may be a good starting point. As I didn't spend many brain-cycles to come up with a description for the "--patch" mode, that paragraph needs a total rewrite on top, but I think the structure to separate the normal "per-path" checkout mode and "patch" mode and describe it separately should make it a lot clearer to see what is being described.

Short of such a fundamental correction,
	git checkout [-p|--patch] [<tree-ish>] -- [<pathspec>...]

would allow you to give none of -p/--patch/<pathspec>, which is totally a different operation from what is being described in the text.

 Documentation/git-checkout.txt | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index d6399c0af8..3d88f703e9 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' [-p|--patch] [<tree-ish>] [--] [<paths>...]
+'git checkout' [<tree-ish>] [--] <pathspec>...
+'git checkout' (-p|--patch) [<tree-ish>] [--] [<paths>...]
 
 DESCRIPTION
 -----------
@@ -78,10 +79,9 @@ 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' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
+'git checkout' [<tree-ish>] [--] <pathspec>...::
 
-	When <paths> or `--patch` are given, 'git checkout' does *not*
-	switch branches.  It updates the named paths in the working tree
+	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
@@ -89,7 +89,7 @@ Omitting <branch> detaches HEAD at the tip of the current branch.
 	(i.e.  commit, tag or tree) to update the index for the given
 	paths before updating the working tree.
 +
-'git checkout' with <paths> or `--patch` is used to restore modified or
+'git checkout' with <paths> is used to restore modified or
 deleted paths to their original contents from the index or replace paths
 with the contents from a named <tree-ish> (most often a commit-ish).
 +
@@ -101,6 +101,13 @@ 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"
+	mode described above, but lets you use the interactive
+	interface show the "diff" output and choose which hunks to
+	use in the result.
+
+
 OPTIONS
 -------
 -q::
Previous: Robert P. J. DayNext: Robert P. J. Day
Message 5 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.