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

[PATCH v3 7/9] git-sparse-checkout.txt: flesh out pattern set sections a bit

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 22, 2022, 02:32 UTC
Message-ID
<546ae3d67326435c2b4a689f9217639bce660d88.1650594746.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1148.v3.git.1650594746.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

The "Internals -- Cone Pattern Set" section starts off discussing patterns, despite the fact that cone mode is about avoiding the patterns. This made sense back when non-cone mode was the default and we started by discussing the full pattern set, but now that we are changing the default, it makes more sense to discuss cone-mode first and avoid the full discussion of patterns. Split this section into two, the first with details about how cone mode operates, and the second following the full pattern set section and discussing how the cone mode patterns used under the hood relate to the full pattern set.

While at it, flesh out the "Internals -- Full Pattern Set" section a bit to include more examples as well.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 Documentation/git-sparse-checkout.txt | 129 +++++++++++++++++---------
 1 file changed, 85 insertions(+), 44 deletions(-)
diff --git a/Documentation/git-sparse-checkout.txt b/Documentation/git-sparse-checkout.txt
index c54437428bb..6e32034511d 100644
--- a/Documentation/git-sparse-checkout.txt
+++ b/Documentation/git-sparse-checkout.txt
@@ -192,7 +192,40 @@ on this file. The files matching the patterns in the file will
 appear in the working directory, and the rest will not.
 
 
-INTERNALS -- CONE PATTERN SET
+INTERNALS -- CONE MODE HANDLING
+-------------------------------
+
+The "cone mode", which is the default, lets you specify only what
+directories to include.  For any directory specified, all paths below
+that directory will be included, and any paths immediately under
+leading directories (including the toplevel directory) will also be
+included.  Thus, if you specified the directory
+    Documentation/technical/
+then your sparse checkout would contain:
+
+  * all files in the toplevel-directory
+  * all files immediately under Documentation/
+  * all files at any depth under Documentation/technical/
+
+Also, in cone mode, even if no directories are specified, then the
+files in the toplevel directory will be included.
+
+When changing the sparse-checkout patterns in cone mode, Git will inspect each
+tracked directory that is not within the sparse-checkout cone to see if it
+contains any untracked files. If all of those files are ignored due to the
+`.gitignore` patterns, then the directory will be deleted. If any of the
+untracked files within that directory is not ignored, then no deletions will
+occur within that directory and a warning message will appear. If these files
+are important, then reset your sparse-checkout definition so they are included,
+use `git add` and `git commit` to store them, then remove any remaining files
+manually to ensure Git can behave optimally.
+
+See also the "Internals -- Cone Pattern Set" section to learn how the
+directories are transformed under the hood into a subset of the
+Full Pattern Set of sparse-checkout.
+
+
+INTERNALS -- FULL PATTERN SET
 -----------------------------
 
 The full pattern set allows for arbitrary pattern matches and complicated
@@ -201,31 +234,62 @@ updating the index, where N is the number of patterns and M is the number
 of paths in the index. To combat this performance issue, a more restricted
 pattern set is allowed when `core.sparseCheckoutCone` is enabled.
 
-The accepted patterns in the cone pattern set are:
+The sparse-checkout file uses the same syntax as `.gitignore` files;
+see linkgit:gitignore[5] for details.  Here, though, the patterns are
+usually being used to select which files to include rather than which
+files to exclude.  (However, it can get a bit confusing since
+gitignore-style patterns have negations defined by patterns which
+begin with a '!', so you can also select files to _not_ include.)
+
+For example, to select everything, and then to remove the file
+`unwanted` (so that every file will appear in your working tree except
+the file named `unwanted`):
+
+    git sparse-checkout set --no-cone '/*' '!unwanted'
+
+These patterns are just placed into the
+`$GIT_DIR/info/sparse-checkout` as-is, so the contents of that file
+at this point would be
+
+----------------
+/*
+!unwanted
+----------------
+
+See also the "Sparse Checkout" section of linkgit:git-read-tree[1] to
+learn more about the gitignore-style patterns used in sparse
+checkouts.
+
+
+INTERNALS -- CONE PATTERN SET
+-----------------------------
+
+In cone mode, only directories are accepted, but they are translated into
+the same gitignore-style patterns used in the full pattern set.  We refer
+to the particular patterns used in those mode as being of one of two types:
 
 1. *Recursive:* All paths inside a directory are included.
 
 2. *Parent:* All files immediately inside a directory are included.
 
-In addition to the above two patterns, we also expect that all files in the
-root directory are included. If a recursive pattern is added, then all
-leading directories are added as parent patterns.
-
-By default, when running `git sparse-checkout set` with no directories
-specified, the root directory is added as a parent pattern. At this
-point, the sparse-checkout file contains the following patterns:
+Since cone mode always includes files at the toplevel, when running
+`git sparse-checkout set` with no directories specified, the toplevel
+directory is added as a parent pattern.  At this point, the
+sparse-checkout file contains the following patterns:
 
 ----------------
 /*
 !/*/
 ----------------
 
-This says "include everything in root, but nothing two levels below root."
+This says "include everything immediately under the toplevel
+directory, but nothing at any level below that."
 
-When in cone mode, the `git sparse-checkout set` subcommand takes a list of
-directories. In this mode, the command `git sparse-checkout set A/B/C` sets
-the directory `A/B/C` as a recursive pattern, the directories `A` and `A/B`
-are added as parent patterns. The resulting sparse-checkout file is now
+When in cone mode, the `git sparse-checkout set` subcommand takes a
+list of directories.  The command `git sparse-checkout set A/B/C` sets
+the directory `A/B/C` as a recursive pattern, the directories `A` and
+`A/B` are added as parent patterns. The resulting sparse-checkout file
+is now
 
 ----------------
 /*
@@ -244,11 +308,14 @@ Unless `core.sparseCheckoutCone` is explicitly set to `false`, Git will
 parse the sparse-checkout file expecting patterns of these types. Git will
 warn if the patterns do not match.  If the patterns do match the expected
 format, then Git will use faster hash-based algorithms to compute inclusion
-in the sparse-checkout.
+in the sparse-checkout.  If they do not match, git will behave as though
+`core.sparseCheckoutCone` was false, regardless of its setting.
 
-In the cone mode case, the `git sparse-checkout list` subcommand will list the
-directories that define the recursive patterns. For the example sparse-checkout
-file above, the output is as follows:
+In the cone mode case, despite the fact that full patterns are written
+to the $GIT_DIR/info/sparse-checkout file, the `git sparse-checkout
+list` subcommand will list the directories that define the recursive
+patterns. For the example sparse-checkout file above, the output is as
+follows:
 
 --------------------------
 $ git sparse-checkout list
@@ -260,32 +327,6 @@ case-insensitive check. This corrects for case mismatched filenames in the
 'git sparse-checkout set' command to reflect the expected cone in the working
 directory.
 
-When changing the sparse-checkout patterns in cone mode, Git will inspect each
-tracked directory that is not within the sparse-checkout cone to see if it
-contains any untracked files. If all of those files are ignored due to the
-`.gitignore` patterns, then the directory will be deleted. If any of the
-untracked files within that directory is not ignored, then no deletions will
-occur within that directory and a warning message will appear. If these files
-are important, then reset your sparse-checkout definition so they are included,
-use `git add` and `git commit` to store them, then remove any remaining files
-manually to ensure Git can behave optimally.
-
-
-INTERNALS -- FULL PATTERN SET
------------------------------
-
-By default, the sparse-checkout file uses the same syntax as `.gitignore`
-files.
-
-While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
-files are included, you can also specify what files are _not_ included,
-using negative patterns. For example, to remove the file `unwanted`:
-
-----------------
-/*
-!unwanted
-----------------
-
 
 INTERNALS -- SUBMODULES
 -----------------------
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 52 of 54 in “sparse-checkout: make cone mode the default”
  1. 0/9 sparse-checkout: make cone mode the defaultElijah Newren via GitGitGadget, Mar 8, 2022
  2. 3/9 git-sparse-checkout.txt: wording updates for the cone mode defaultElijah Newren via GitGitGadget, Mar 8, 2022
  3. 2/9 sparse-checkout: make --cone the defaultElijah Newren via GitGitGadget, Mar 8, 2022
  4. Derrick StoleeMar 8, 2022
  5. Elijah NewrenMar 12, 2022
  6. 1/9 tests: stop assuming --no-cone is the default mode for sparse-checkoutElijah Newren via GitGitGadget, Mar 8, 2022
  7. 4/9 git-sparse-checkout.txt: update docs for deprecation of 'init'Elijah Newren via GitGitGadget, Mar 8, 2022
  8. 5/9 git-sparse-checkout.txt: shuffle some sections and mark as internalElijah Newren via GitGitGadget, Mar 8, 2022
  9. 6/9 git-sparse-checkout.txt: add a new EXAMPLES sectionElijah Newren via GitGitGadget, Mar 8, 2022
  10. Derrick StoleeMar 8, 2022
  11. Elijah NewrenMar 12, 2022
  12. 7/9 git-sparse-checkout.txt: flesh out non-cone mode pattern discussion a bitElijah Newren via GitGitGadget, Mar 8, 2022
  13. 8/9 git-sparse-checkout.txt: mark non-cone mode as deprecatedElijah Newren via GitGitGadget, Mar 8, 2022
  14. 9/9 Documentation: some sparsity wording clarificationsElijah Newren via GitGitGadget, Mar 8, 2022
  15. Derrick StoleeMar 8, 2022
  16. 0/9 sparse-checkout: make cone mode the defaultElijah Newren via GitGitGadget, Mar 12, 2022
  17. 2/9 sparse-checkout: make --cone the defaultElijah Newren via GitGitGadget, Mar 12, 2022
  18. Junio C HamanoMar 14, 2022
  19. Elijah NewrenApr 22, 2022
  20. 1/9 tests: stop assuming --no-cone is the default mode for sparse-checkoutElijah Newren via GitGitGadget, Mar 12, 2022
  21. Junio C HamanoMar 14, 2022
  22. Derrick StoleeMar 15, 2022
  23. 3/9 git-sparse-checkout.txt: wording updates for the cone mode defaultElijah Newren via GitGitGadget, Mar 12, 2022
  24. Junio C HamanoMar 14, 2022
  25. 4/9 git-sparse-checkout.txt: update docs for deprecation of 'init'Elijah Newren via GitGitGadget, Mar 12, 2022
  26. Junio C HamanoMar 14, 2022
  27. Elijah NewrenApr 22, 2022
  28. Junio C HamanoApr 22, 2022
  29. 6/9 git-sparse-checkout.txt: add a new EXAMPLES sectionElijah Newren via GitGitGadget, Mar 12, 2022
  30. 5/9 git-sparse-checkout.txt: shuffle some sections and mark as internalElijah Newren via GitGitGadget, Mar 12, 2022
  31. Junio C HamanoMar 14, 2022
  32. Elijah NewrenApr 22, 2022
  33. 7/9 git-sparse-checkout.txt: flesh out non-cone mode pattern discussion a bitElijah Newren via GitGitGadget, Mar 12, 2022
  34. Junio C HamanoMar 14, 2022
  35. Elijah NewrenApr 22, 2022
  36. 8/9 git-sparse-checkout.txt: mark non-cone mode as deprecatedElijah Newren via GitGitGadget, Mar 12, 2022
  37. Junio C HamanoMar 14, 2022
  38. Elijah NewrenApr 22, 2022
  39. 9/9 Documentation: some sparsity wording clarificationsElijah Newren via GitGitGadget, Mar 12, 2022
  40. Derrick StoleeMar 14, 2022
  41. Victoria DyeMar 14, 2022
  42. Junio C HamanoMar 14, 2022
  43. Junio C HamanoMar 14, 2022
  44. 0/9 sparse-checkout: make cone mode the defaultElijah Newren via GitGitGadget, Apr 22, 2022
  45. 1/9 tests: stop assuming --no-cone is the default mode for sparse-checkoutElijah Newren via GitGitGadget, Apr 22, 2022
  46. 2/9 sparse-checkout: make --cone the defaultElijah Newren via GitGitGadget, Apr 22, 2022
  47. 3/9 git-sparse-checkout.txt: wording updates for the cone mode defaultElijah Newren via GitGitGadget, Apr 22, 2022
  48. 4/9 git-sparse-checkout.txt: update docs for deprecation of 'init'Elijah Newren via GitGitGadget, Apr 22, 2022
  49. 5/9 git-sparse-checkout.txt: shuffle some sections and mark as internalElijah Newren via GitGitGadget, Apr 22, 2022
  50. 9/9 Documentation: some sparsity wording clarificationsElijah Newren via GitGitGadget, Apr 22, 2022
  51. 8/9 git-sparse-checkout.txt: mark non-cone mode as deprecatedElijah Newren via GitGitGadget, Apr 22, 2022
  52. 7/9 git-sparse-checkout.txt: flesh out pattern set sections a bitElijah Newren via GitGitGadget, Apr 22, 2022
  53. 6/9 git-sparse-checkout.txt: add a new EXAMPLES sectionElijah Newren via GitGitGadget, Apr 22, 2022
  54. Derrick StoleeApr 25, 2022

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.