From: D. Ben Knoble Date: Thu, 28 Aug 2025 14:00:22 GMT Subject: Re: [PATCH 1/5] doc: git-checkout: clarify intro Message-ID: In-Reply-To: On Mon, Aug 25, 2025 at 3:09 PM Julia Evans via GitGitGadget wrote: > > From: Julia Evans > > - Many users do not understand the terms "index" or "pathspec". Clarify > in the intro by using an example, so that users can understand the > basic idea without learning the full definition of "pathspec". > - Use the terminology "Switch" and "Restore" to mirror `git switch` > and `git restore` > - Reference (and clarify) the ARGUMENT DISAMBIGUATION section > > Signed-off-by: Julia Evans > --- > Documentation/git-checkout.adoc | 31 +++++++++++++++++++------------ > 1 file changed, 19 insertions(+), 12 deletions(-) > > diff --git a/Documentation/git-checkout.adoc b/Documentation/git-checkout.adoc > index 40e02cfd6562..ddda891c0ff7 100644 > --- a/Documentation/git-checkout.adoc > +++ b/Documentation/git-checkout.adoc > @@ -20,10 +20,14 @@ git checkout (-p|--patch) [] [--] [...] > > DESCRIPTION > ----------- > -Updates files in the working tree to match the version in the index > -or the specified tree. If no pathspec was given, `git checkout` will > -also update `HEAD` to set the specified branch as the current > -branch. > +`git checkout` has two main modes: > + > +1. **Switch branches**, with `git checkout ` > +2. **Restore a different version of a file**, for example with `git > + checkout ` or `git checkout ` > + > +See ARGUMENT DISAMBIGUATION below for how Git decides which one to do. > +Here's a description of all of the modes: This looks good—I initially scratched my head thinking there were 3 modes, but unifying "update files to match index" and "update files to match specified tree" is easier to digest in this presentation. > > `git checkout []`:: > To prepare for working on __, switch to it by updating > @@ -511,14 +515,17 @@ $ git log -g -2 HEAD > ARGUMENT DISAMBIGUATION > ----------------------- > > -When there is only one argument given and it is not `--` (e.g. `git > -checkout abc`), and when the argument is both a valid __ > -(e.g. a branch `abc` exists) and a valid __ (e.g. a file > -or a directory whose name is "abc" exists), Git would usually ask > -you to disambiguate. Because checking out a branch is so common an > -operation, however, `git checkout abc` takes "abc" as a __ > -in such a situation. Use `git checkout -- ` if you want > -to checkout these paths out of the index. > +When you run `git checkout `, Git tries to guess whether > +`` is intended to be a branch, a commit, or a set of file(s), > +and then switches branches, switches commits, or restores the files. > + > +If there's a conflict, you can use the double dash `--` to distinguish > +between branches and files: > + > +* `git checkout --` will force Git to treat the parameter as a > + branch name or commit > +* `git checkout -- ` will force Git to treat the parameter as > + a set of file(s) I think we've dropped the bit about the default interpretation of "git checkout ". Maybe When you run `git checkout `, Git tries to guess whether `` is intended to be a branch, a commit, or a set of file(s), and then switches branches, switches commits, or restores the files. By default, Git interprets `` as a __. [explain what choosing a tree-ish means for the user?] [Your notes on disambiguation as before] ? > > EXAMPLES > -------- > -- > gitgitgadget > > -- D. Ben Knoble