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:
-
Recursive: All paths inside a directory are included.
-
Parent: All files immediately inside a directory are included.
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 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. 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
/*
!/*/
/A/
!/A/*/
/A/B/
!/A/B/*/
/A/B/C/
Here, order matters, so the negative patterns are overridden by the positive
patterns that appear lower in the file.
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. If they do not match, git will behave as though
core.sparseCheckoutCone was false, regardless of its setting.
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
A/B/C
If core.ignoreCase=true, then the pattern-matching algorithm will use a
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.