Home Explore Blog CI



git

7th chunk of `Documentation/git-sparse-checkout.adoc`
5af1f8cedca3055874d20aa2f6eda19c834dae34dddf4ac40000000100000816
 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.

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

Title: Git Sparse Checkout: Cone Pattern Set
Summary
In cone mode, Git sparse checkout translates directory paths into gitignore-style patterns, which can be either recursive or parent patterns. The sparse-checkout file contains these patterns, and the order of patterns matters. Git will use faster hash-based algorithms if the patterns match the expected format, and will warn if they do not match, defaulting to non-cone mode behavior if necessary.