2019-11-21 23:04:33 +01:00
|
|
|
git-sparse-checkout(1)
|
|
|
|
======================
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
|
|
|
git-sparse-checkout - Initialize and modify the sparse-checkout
|
|
|
|
configuration, which reduces the checkout to a set of paths
|
2020-01-02 23:51:40 +01:00
|
|
|
given by a list of patterns.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
|
|
|
[verse]
|
|
|
|
'git sparse-checkout <subcommand> [options]'
|
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
|
|
|
|
Initialize and modify the sparse-checkout configuration, which reduces
|
|
|
|
the checkout to a set of paths given by a list of patterns.
|
|
|
|
|
|
|
|
THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
|
|
|
|
COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN
|
|
|
|
THE FUTURE.
|
|
|
|
|
|
|
|
|
|
|
|
COMMANDS
|
|
|
|
--------
|
|
|
|
'list'::
|
2019-12-30 16:33:12 +01:00
|
|
|
Describe the patterns in the sparse-checkout file.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
2019-11-21 23:04:34 +01:00
|
|
|
'init'::
|
|
|
|
Enable the `core.sparseCheckout` setting. If the
|
|
|
|
sparse-checkout file does not exist, then populate it with
|
|
|
|
patterns that match every file in the root directory and
|
|
|
|
no other directories, then will remove all directories tracked
|
|
|
|
by Git. Add patterns to the sparse-checkout file to
|
|
|
|
repopulate the working directory.
|
|
|
|
+
|
|
|
|
To avoid interfering with other worktrees, it first enables the
|
|
|
|
`extensions.worktreeConfig` setting and makes sure to set the
|
|
|
|
`core.sparseCheckout` setting in the worktree-specific config file.
|
2020-01-23 20:00:02 +01:00
|
|
|
+
|
|
|
|
When `--cone` is provided, the `core.sparseCheckoutCone` setting is
|
|
|
|
also set, allowing for better performance with a limited set of
|
|
|
|
patterns (see 'CONE PATTERN SET' below).
|
2021-03-30 15:11:00 +02:00
|
|
|
+
|
|
|
|
Use the `--[no-]sparse-index` option to toggle the use of the sparse
|
|
|
|
index format. This reduces the size of the index to be more closely
|
|
|
|
aligned with your sparse-checkout definition. This can have significant
|
|
|
|
performance advantages for commands such as `git status` or `git add`.
|
|
|
|
This feature is still experimental. Some commands might be slower with
|
|
|
|
a sparse index until they are properly integrated with the feature.
|
|
|
|
+
|
|
|
|
**WARNING:** Using a sparse index requires modifying the index in a way
|
|
|
|
that is not completely understood by external tools. If you have trouble
|
|
|
|
with this compatibility, then run `git sparse-checkout init --no-sparse-index`
|
|
|
|
to rewrite your index to not be sparse. Older versions of Git will not
|
|
|
|
understand the sparse directory entries index extension and may fail to
|
|
|
|
interact with your repository until it is disabled.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
2019-11-21 23:04:36 +01:00
|
|
|
'set'::
|
|
|
|
Write a set of patterns to the sparse-checkout file, as given as
|
|
|
|
a list of arguments following the 'set' subcommand. Update the
|
|
|
|
working directory to match the new patterns. Enable the
|
|
|
|
core.sparseCheckout config setting if it is not already enabled.
|
2019-11-21 23:04:37 +01:00
|
|
|
+
|
|
|
|
When the `--stdin` option is provided, the patterns are read from
|
|
|
|
standard in as a newline-delimited list instead of from the arguments.
|
2020-01-31 21:16:14 +01:00
|
|
|
+
|
|
|
|
When `core.sparseCheckoutCone` is enabled, the input list is considered a
|
|
|
|
list of directories instead of sparse-checkout patterns. The command writes
|
|
|
|
patterns to the sparse-checkout file to include all files contained in those
|
|
|
|
directories (recursively) as well as files that are siblings of ancestor
|
|
|
|
directories. The input format matches the output of `git ls-tree --name-only`.
|
|
|
|
This includes interpreting pathnames that begin with a double quote (") as
|
|
|
|
C-style quoted strings.
|
2019-11-21 23:04:36 +01:00
|
|
|
|
2020-02-11 16:02:23 +01:00
|
|
|
'add'::
|
|
|
|
Update the sparse-checkout file to include additional patterns.
|
|
|
|
By default, these patterns are read from the command-line arguments,
|
|
|
|
but they can be read from stdin using the `--stdin` option. When
|
|
|
|
`core.sparseCheckoutCone` is enabled, the given patterns are interpreted
|
|
|
|
as directory names as in the 'set' subcommand.
|
|
|
|
|
2020-05-17 20:52:21 +02:00
|
|
|
'reapply'::
|
2020-03-27 01:49:01 +01:00
|
|
|
Reapply the sparsity pattern rules to paths in the working tree.
|
|
|
|
Commands like merge or rebase can materialize paths to do their
|
|
|
|
work (e.g. in order to show you a conflict), and other
|
|
|
|
sparse-checkout commands might fail to sparsify an individual file
|
|
|
|
(e.g. because it has unstaged changes or conflicts). In such
|
|
|
|
cases, it can make sense to run `git sparse-checkout reapply` later
|
|
|
|
after cleaning up affected paths (e.g. resolving conflicts, undoing
|
|
|
|
or committing changes, etc.).
|
|
|
|
|
2019-11-21 23:04:38 +01:00
|
|
|
'disable'::
|
2019-11-21 23:04:47 +01:00
|
|
|
Disable the `core.sparseCheckout` config setting, and restore the
|
|
|
|
working directory to include all files. Leaves the sparse-checkout
|
|
|
|
file intact so a later 'git sparse-checkout init' command may
|
|
|
|
return the working directory to the same state.
|
2019-11-21 23:04:38 +01:00
|
|
|
|
2019-11-21 23:04:33 +01:00
|
|
|
SPARSE CHECKOUT
|
|
|
|
---------------
|
|
|
|
|
|
|
|
"Sparse checkout" allows populating the working directory sparsely.
|
|
|
|
It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
|
|
|
|
Git whether a file in the working directory is worth looking at. If
|
|
|
|
the skip-worktree bit is set, then the file is ignored in the working
|
|
|
|
directory. Git will not populate the contents of those files, which
|
|
|
|
makes a sparse checkout helpful when working in a repository with many
|
|
|
|
files, but only a few are important to the current user.
|
|
|
|
|
|
|
|
The `$GIT_DIR/info/sparse-checkout` file is used to define the
|
|
|
|
skip-worktree reference bitmap. When Git updates the working
|
|
|
|
directory, it updates the skip-worktree bits in the index based
|
|
|
|
on this file. The files matching the patterns in the file will
|
|
|
|
appear in the working directory, and the rest will not.
|
|
|
|
|
2019-11-21 23:04:38 +01:00
|
|
|
To enable the sparse-checkout feature, run `git sparse-checkout init` to
|
|
|
|
initialize a simple sparse-checkout file and enable the `core.sparseCheckout`
|
|
|
|
config setting. Then, run `git sparse-checkout set` to modify the patterns in
|
|
|
|
the sparse-checkout file.
|
|
|
|
|
|
|
|
To repopulate the working directory with all files, use the
|
|
|
|
`git sparse-checkout disable` command.
|
|
|
|
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
FULL PATTERN SET
|
|
|
|
----------------
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
----------------
|
|
|
|
|
|
|
|
|
2019-11-21 23:04:40 +01:00
|
|
|
CONE PATTERN SET
|
|
|
|
----------------
|
|
|
|
|
|
|
|
The full pattern set allows for arbitrary pattern matches and complicated
|
|
|
|
inclusion/exclusion rules. These can result in O(N*M) pattern matches when
|
|
|
|
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
|
2020-01-24 22:19:35 +01:00
|
|
|
pattern set is allowed when `core.sparseCheckoutCone` is enabled.
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
The accepted patterns in the cone pattern set are:
|
|
|
|
|
|
|
|
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 init`, the root 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."
|
2020-01-31 21:16:14 +01:00
|
|
|
|
|
|
|
When in cone mode, the `git sparse-checkout set` subcommand takes a list of
|
|
|
|
directories instead of a list of sparse-checkout patterns. 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
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
----------------
|
|
|
|
/*
|
|
|
|
!/*/
|
|
|
|
/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.
|
|
|
|
|
|
|
|
If `core.sparseCheckoutCone=true`, then 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.
|
|
|
|
|
2019-12-30 16:33:12 +01:00
|
|
|
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:
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
$ git sparse-checkout list
|
|
|
|
A/B/C
|
|
|
|
--------------------------
|
|
|
|
|
sparse-checkout: respect core.ignoreCase in cone mode
When a user uses the sparse-checkout feature in cone mode, they
add patterns using "git sparse-checkout set <dir1> <dir2> ..."
or by using "--stdin" to provide the directories line-by-line over
stdin. This behaviour naturally looks a lot like the way a user
would type "git add <dir1> <dir2> ..."
If core.ignoreCase is enabled, then "git add" will match the input
using a case-insensitive match. Do the same for the sparse-checkout
feature.
Perform case-insensitive checks while updating the skip-worktree
bits during unpack_trees(). This is done by changing the hash
algorithm and hashmap comparison methods to optionally use case-
insensitive methods.
When this is enabled, there is a small performance cost in the
hashing algorithm. To tease out the worst possible case, the
following was run on a repo with a deep directory structure:
git ls-tree -d -r --name-only HEAD |
git sparse-checkout set --stdin
The 'set' command was timed with core.ignoreCase disabled or
enabled. For the repo with a deep history, the numbers were
core.ignoreCase=false: 62s
core.ignoreCase=true: 74s (+19.3%)
For reproducibility, the equivalent test on the Linux kernel
repository had these numbers:
core.ignoreCase=false: 3.1s
core.ignoreCase=true: 3.6s (+16%)
Now, this is not an entirely fair comparison, as most users
will define their sparse cone using more shallow directories,
and the performance improvement from eb42feca97 ("unpack-trees:
hash less in cone mode" 2019-11-21) can remove most of the
hash cost. For a more realistic test, drop the "-r" from the
ls-tree command to store only the first-level directories.
In that case, the Linux kernel repository takes 0.2-0.25s in
each case, and the deep repository takes one second, plus or
minus 0.05s, in each case.
Thus, we _can_ demonstrate a cost to this change, but it is
unlikely to matter to any reasonable sparse-checkout cone.
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-12-13 19:09:53 +01:00
|
|
|
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.
|
|
|
|
|
2019-12-30 16:33:13 +01:00
|
|
|
|
|
|
|
SUBMODULES
|
|
|
|
----------
|
|
|
|
|
git-sparse-checkout: clarify interactions with submodules
Ignoring the sparse-checkout feature momentarily, if one has a submodule and
creates local branches within it with unpushed changes and maybe adds some
untracked files to it, then we would want to avoid accidentally removing such
a submodule. So, for example with git.git, if you run
git checkout v2.13.0
then the sha1collisiondetection/ submodule is NOT removed even though it
did not exist as a submodule until v2.14.0. Similarly, if you only had
v2.13.0 checked out previously and ran
git checkout v2.14.0
the sha1collisiondetection/ submodule would NOT be automatically
initialized despite being part of v2.14.0. In both cases, git requires
submodules to be initialized or deinitialized separately. Further, we
also have special handling for submodules in other commands such as
clean, which requires two --force flags to delete untracked submodules,
and some commands have a --recurse-submodules flag.
sparse-checkout is very similar to checkout, as evidenced by the similar
name -- it adds and removes files from the working copy. However, for
the same avoid-data-loss reasons we do not want to remove a submodule
from the working copy with checkout, we do not want to do it with
sparse-checkout either. So submodules need to be separately initialized
or deinitialized; changing sparse-checkout rules should not
automatically trigger the removal or vivification of submodules.
I believe the previous wording in git-sparse-checkout.txt about
submodules was only about this particular issue. Unfortunately, the
previous wording could be interpreted to imply that submodules should be
considered active regardless of sparsity patterns. Update the wording
to avoid making such an implication. It may be helpful to consider two
example situations where the differences in wording become important:
In the future, we want users to be able to run commands like
git clone --sparse=moduleA --recurse-submodules $REPO_URL
and have sparsity paths automatically set up and have submodules *within
the sparsity paths* be automatically initialized. We do not want all
submodules in any path to be automatically initialized with that
command.
Similarly, we want to be able to do things like
git -c sparse.restrictCmds grep --recurse-submodules $REV $PATTERN
and search through $REV for $PATTERN within the recorded sparsity
patterns. We want it to recurse into submodules within those sparsity
patterns, but do not want to recurse into directories that do not match
the sparsity patterns in search of a possible submodule.
Signed-off-by: Elijah Newren <newren@gmail.com>
Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-06-11 01:16:49 +02:00
|
|
|
If your repository contains one or more submodules, then submodules
|
|
|
|
are populated based on interactions with the `git submodule` command.
|
|
|
|
Specifically, `git submodule init -- <path>` will ensure the submodule
|
|
|
|
at `<path>` is present, while `git submodule deinit [-f] -- <path>`
|
|
|
|
will remove the files for the submodule at `<path>` (including any
|
|
|
|
untracked files, uncommitted changes, and unpushed history). Similar
|
|
|
|
to how sparse-checkout removes files from the working tree but still
|
|
|
|
leaves entries in the index, deinitialized submodules are removed from
|
|
|
|
the working directory but still have an entry in the index.
|
|
|
|
|
|
|
|
Since submodules may have unpushed changes or untracked files,
|
|
|
|
removing them could result in data loss. Thus, changing sparse
|
|
|
|
inclusion/exclusion rules will not cause an already checked out
|
|
|
|
submodule to be removed from the working copy. Said another way, just
|
|
|
|
as `checkout` will not cause submodules to be automatically removed or
|
|
|
|
initialized even when switching between branches that remove or add
|
|
|
|
submodules, using `sparse-checkout` to reduce or expand the scope of
|
|
|
|
"interesting" files will not cause submodules to be automatically
|
|
|
|
deinitialized or initialized either.
|
|
|
|
|
|
|
|
Further, the above facts mean that there are multiple reasons that
|
|
|
|
"tracked" files might not be present in the working copy: sparsity
|
|
|
|
pattern application from sparse-checkout, and submodule initialization
|
|
|
|
state. Thus, commands like `git grep` that work on tracked files in
|
|
|
|
the working copy may return results that are limited by either or both
|
|
|
|
of these restrictions.
|
2019-12-30 16:33:13 +01:00
|
|
|
|
|
|
|
|
2019-11-21 23:04:33 +01:00
|
|
|
SEE ALSO
|
|
|
|
--------
|
|
|
|
|
|
|
|
linkgit:git-read-tree[1]
|
|
|
|
linkgit:gitignore[5]
|
|
|
|
|
|
|
|
GIT
|
|
|
|
---
|
|
|
|
Part of the linkgit:git[1] suite
|