Skip to content

Commit b59698a

Browse files
committed
checkout doc: clarify command line args for "checkout paths" mode
There are "git checkout [-p][<tree-ish>][--][<paths>...]" in the SYNOPSIS section, and "git checkout [-p][<tree-ish>][--]<paths>..." as the header for the section that explains the "check out paths from index/tree-ish" mode. It is unclear if we require at least one path, or it is entirely optional. Actually, both are wrong. Without the "-p(atch)" option, you must have <pathspec> (otherwise, with a commit that is a <tree-ish>, you would be checking out that commit to build a new history on top of it). With it, it is already clear that you are checking out paths, it is optional. In other words, you cannot omit both. 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. Let's split the entry into two, and describe the regular mode and the patch mode separately. This allows us to make it clear that the regular mode MUST be given at least one pathspec, that the patch mode can be invoked with either '-p' or '--patch' but one of these must be given, and that the pathspec is entirely optional in the patch mode. Also, revamp the explanation of "checkout paths" by removing extraneous description at the beginning, that says "checking out paths is not checking out a branch". Explaining what it is for and when the user wants to use it upfront is the most direct way to help the readers. Noticed-by: Robert P J Day Helped-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4010f1d commit b59698a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Documentation/git-checkout.txt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ SYNOPSIS
1313
'git checkout' [-q] [-f] [-m] [--detach] <commit>
1414
'git checkout' [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]
1515
'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
16-
'git checkout' [-p|--patch] [<tree-ish>] [--] [<paths>...]
16+
'git checkout' [<tree-ish>] [--] <pathspec>...
17+
'git checkout' (-p|--patch) [<tree-ish>] [--] [<paths>...]
1718

1819
DESCRIPTION
1920
-----------
@@ -78,20 +79,13 @@ be used to detach HEAD at the tip of the branch (`git checkout
7879
+
7980
Omitting <branch> detaches HEAD at the tip of the current branch.
8081

81-
'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
82+
'git checkout' [<tree-ish>] [--] <pathspec>...::
8283

83-
When <paths> or `--patch` are given, 'git checkout' does *not*
84-
switch branches. It updates the named paths in the working tree
85-
from the index file or from a named <tree-ish> (most often a
86-
commit). In this case, the `-b` and `--track` options are
87-
meaningless and giving either of them results in an error. The
88-
<tree-ish> argument can be used to specify a specific tree-ish
89-
(i.e. commit, tag or tree) to update the index for the given
90-
paths before updating the working tree.
91-
+
92-
'git checkout' with <paths> or `--patch` is used to restore modified or
93-
deleted paths to their original contents from the index or replace paths
94-
with the contents from a named <tree-ish> (most often a commit-ish).
84+
Overwrite paths in the working tree by replacing with the
85+
contents in the index or in the <tree-ish> (most often a
86+
commit). When a <tree-ish> is given, the paths that
87+
match the <pathspec> are updated both in the index and in
88+
the working tree.
9589
+
9690
The index may contain unmerged entries because of a previous failed merge.
9791
By default, if you try to check out such an entry from the index, the
@@ -101,6 +95,14 @@ specific side of the merge can be checked out of the index by
10195
using `--ours` or `--theirs`. With `-m`, changes made to the working tree
10296
file can be discarded to re-create the original conflicted merge result.
10397

98+
'git checkout' (-p|--patch) [<tree-ish>] [--] [<pathspec>...]::
99+
This is similar to the "check out paths to the working tree
100+
from either the index or from a tree-ish" mode described
101+
above, but lets you use the interactive interface to show
102+
the "diff" output and choose which hunks to use in the
103+
result. See below for the description of `--patch` option.
104+
105+
104106
OPTIONS
105107
-------
106108
-q::

0 commit comments

Comments
 (0)