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

[PATCH 3/3] doc: update doc for strict usage of -- checkout

From
DLDannier Castro L <danniercl@gmail.com>
Date
May 13, 2018, 02:23 UTC
Message-ID
<1526178214-30956-3-git-send-email-danniercl@gmail.com>
In-Reply-To
<1526178214-30956-1-git-send-email-danniercl@gmail.com>

The flag '--' must always be before any file path when <checkout> command is used.

The main documentation about the usage of <checkout> command is updated to include the strict usage of the flag '--' so that the user can specify file names over branch names.

Signed-off-by: Dannier Castro L <danniercl@gmail.com>:
---
 Documentation/git-checkout.txt | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index ca5fc9c..8360a98 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -12,9 +12,9 @@ SYNOPSIS
 'git checkout' [-q] [-f] [-m] --detach [<branch>]
 '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' [<tree-ish>] [--] <pathspec>...
-'git checkout' (-p|--patch) [<tree-ish>] [--] [<paths>...]
+'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] -- <paths>...
+'git checkout' [<tree-ish>] -- <pathspec>...
+'git checkout' (-p|--patch) [<tree-ish>] [-- <paths>...]
 
 DESCRIPTION
 -----------
@@ -79,7 +79,7 @@ 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' [<tree-ish>] [--] <pathspec>...::
+'git checkout' [<tree-ish>] -- <pathspec>...::
 
 	Overwrite paths in the working tree by replacing with the
 	contents in the index or in the <tree-ish> (most often a
@@ -95,7 +95,7 @@ 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>...]::
+'git checkout' (-p|--patch) [<tree-ish>] [-- <pathspec>...]::
 	This is similar to the "check out paths to the working tree
 	from either the index or from a tree-ish" mode described
 	above, but lets you use the interactive interface to show
@@ -453,7 +453,7 @@ mistake, and gets it back from the index.
 $ git checkout master             <1>
 $ git checkout master~2 Makefile  <2>
 $ rm -f hello.c
-$ git checkout hello.c            <3>
+$ git checkout -- hello.c         <3>
 ------------
 +
 <1> switch branch
@@ -471,14 +471,6 @@ Note the quotes around `*.c`.  The file `hello.c` will also be
 checked out, even though it is no longer in the working tree,
 because the file globbing is used to match entries in the index
 (not in the working tree by the shell).
-+
-If you have an unfortunate branch that is named `hello.c`, this
-step would be confused as an instruction to switch to that branch.
-You should instead write:
-+
-------------
-$ git checkout -- hello.c
-------------
 
 . After working in the wrong branch, switching to the correct
 branch would be done using:
-- 
2.7.4
Previous: Dannier Castro LNext: Duy Nguyen
Message 3 of 11 in “checkout.c: add strict usage of -- before file_path”
  1. 1/3 checkout.c: add strict usage of -- before file_pathDannier Castro L, May 13, 2018
  2. 2/3 test: update tests for strict usage of -- checkoutDannier Castro L, May 13, 2018
  3. 3/3 doc: update doc for strict usage of -- checkoutDannier Castro L, May 13, 2018
  4. Duy NguyenMay 13, 2018
  5. Dannier Castro LMay 13, 2018
  6. SZEDER GáborMay 13, 2018
  7. Philip OakleyMay 13, 2018
  8. Junio C HamanoMay 14, 2018
  9. Kevin DaudtMay 13, 2018
  10. Duy NguyenMay 14, 2018
  11. Duy NguyenMay 14, 2018

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.