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

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

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 7, 2016, 11:19 UTC
Message-ID
<20160907111941.2342-3-pclouds@gmail.com>
In-Reply-To
<20160907111941.2342-1-pclouds@gmail.com>

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.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-checkout.txt | 9 +++++++++
 1 file changed, 9 insertions(+)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 7a2201b..94eb238 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -419,6 +419,15 @@ $ git reflog -2 HEAD # or
 $ git log -g -2 HEAD
 ------------
 
+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.
+
 EXAMPLES
 --------
 
-- 
2.8.2.524.g6ff3d78
Previous: Nguyễn Thái Ngọc DuyNext: Junio C Hamano
Message 8 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.