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

Re: [PATCH 2/3] checkout.txt: document a common case that ignores ambiguation rules

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 8, 2016, 20:03 UTC
Message-ID
<xmqq7famgnwo.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160907111941.2342-3-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 5 quoted lines
> Normally we err on the safe side: if something can be seen as both an
> SHA1 and a pathspec, we stop and scream. In checkout, there is one
> exception added in 859fdab (git-checkout: improve error messages, detect
> ambiguities. - 2008-07-23), to allow the common case "git checkout
> branch". Let's document this exception.
Good idea, but...
Show 8 quoted lines
> +ARGUMENT AMBIGUATION
> +--------------------
> +
> +When there is only one argument given and it is not `--` (e.g. "git
> +checkout abc"), "abc" could be seen as either a `<tree-ish>` or a
> +`<pathspec>`, but Git will assume the argument is a `<tree-ish>`, which is
> +a common case for switching branches. Use `git checkout -- <pathspec>`
> +form if you mean it to be a pathspec.

... this is far from reasonable. I'd read "but Git will assume the argument is a tree-ish" to mean "git checkout Makefile" would attempt to checkout the Makefile branch and fail.

    When there is only one argument given and it is not `--` (e.g. "git
    checkout abc"), and when the argument is both a valid `<tree-ish>`
    (e.g. a branch "abc" exists) and a valid `<pathspec>` (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 `<tree-ish>`
    in such situation.  Use `git checkout -- <pathspec>` if you want to
    checkout these paths out of the index.
or something like that?
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 9 of 12 in “checkout: swap the order of ambiguity check for :/ syntax”
  1. checkout: swap the order of ambiguity check for :/ syntaxNguyễn Thái Ngọc Duy, Aug 22, 2016
  2. Junio C HamanoAug 24, 2016
  3. Duy NguyenAug 25, 2016
  4. Junio C HamanoAug 25, 2016
  5. Duy NguyenAug 26, 2016
  6. 0/3 fix checkout ambiguation in subdirNguyễn Thái Ngọc Duy, Sep 7, 2016
  7. 1/3 checkout: add some spaces between code and commentNguyễn Thái Ngọc Duy, Sep 7, 2016
  8. 2/3 checkout.txt: document a common case that ignores ambiguation rulesNguyễn Thái Ngọc Duy, Sep 7, 2016
  9. Junio C HamanoSep 8, 2016
  10. Junio C HamanoSep 9, 2016
  11. 3/3 checkout: fix ambiguity check in subdirNguyễn Thái Ngọc Duy, Sep 7, 2016
  12. Junio C HamanoSep 8, 2016

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.