2019-11-21 23:04:33 +01:00
|
|
|
git-sparse-checkout(1)
|
|
|
|
======================
|
|
|
|
|
|
|
|
NAME
|
|
|
|
----
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
git-sparse-checkout - Reduce your working tree to a subset of tracked files
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
--------
|
|
|
|
[verse]
|
2021-11-06 19:48:51 +01:00
|
|
|
'git sparse-checkout <subcommand> [<options>]'
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
-----------
|
|
|
|
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
This command is used to create sparse checkouts, which means that it
|
|
|
|
changes the working tree from having all tracked files present, to only
|
|
|
|
have a subset of them. It can also switch which subset of files are
|
|
|
|
present, or undo and go back to having all tracked files present in the
|
|
|
|
working copy.
|
|
|
|
|
|
|
|
The subset of files is chosen by providing a list of directories in
|
2022-04-22 04:32:19 +02:00
|
|
|
cone mode (the default), or by providing a list of patterns in
|
|
|
|
non-cone mode.
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
|
|
|
|
When in a sparse-checkout, other Git commands behave a bit differently.
|
|
|
|
For example, switching branches will not update paths outside the
|
|
|
|
sparse-checkout directories/patterns, and `git commit -a` will not record
|
|
|
|
paths outside the sparse-checkout directories/patterns as deleted.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
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'::
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
Describe the directories or patterns in the sparse-checkout file.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
2021-12-14 05:09:10 +01:00
|
|
|
'set'::
|
sparse-checkout: set worktree-config correctly
`git sparse-checkout set/init` enables worktree-specific
configuration[*] by setting extensions.worktreeConfig=true, but neglects
to perform the additional necessary bookkeeping of relocating
`core.bare=true` and `core.worktree` from $GIT_COMMON_DIR/config to
$GIT_COMMON_DIR/config.worktree, as documented in git-worktree.txt. As a
result of this oversight, these settings, which are nonsensical for
secondary worktrees, can cause Git commands to incorrectly consider a
worktree bare (in the case of `core.bare`) or operate on the wrong
worktree (in the case of `core.worktree`). Fix this problem by taking
advantage of the recently-added init_worktree_config() which enables
`extensions.worktreeConfig` and takes care of necessary bookkeeping.
While at it, for backward-compatibility reasons, also stop upgrading the
repository format to "1" since doing so is (unintentionally) not
required to take advantage of `extensions.worktreeConfig`, as explained
by 11664196ac ("Revert "check_repository_format_gently(): refuse
extensions for old repositories"", 2020-07-15).
[*] The main reason to use worktree-specific config for the
sparse-checkout builtin was to avoid enabling sparse-checkout patterns
in one and causing a loss of files in another. If a worktree does not
have a sparse-checkout patterns file, then the sparse-checkout logic
will not kick in on that worktree.
Reported-by: Sean Allred <allred.sean@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-07 22:33:01 +01:00
|
|
|
Enable the necessary sparse-checkout config settings
|
|
|
|
(`core.sparseCheckout`, `core.sparseCheckoutCone`, and
|
|
|
|
`index.sparse`) if they are not already set to the desired values,
|
2022-04-22 04:32:20 +02:00
|
|
|
populate the sparse-checkout file from the list of arguments
|
|
|
|
following the 'set' subcommand, and update the working directory to
|
|
|
|
match.
|
2019-11-21 23:04:34 +01:00
|
|
|
+
|
sparse-checkout: set worktree-config correctly
`git sparse-checkout set/init` enables worktree-specific
configuration[*] by setting extensions.worktreeConfig=true, but neglects
to perform the additional necessary bookkeeping of relocating
`core.bare=true` and `core.worktree` from $GIT_COMMON_DIR/config to
$GIT_COMMON_DIR/config.worktree, as documented in git-worktree.txt. As a
result of this oversight, these settings, which are nonsensical for
secondary worktrees, can cause Git commands to incorrectly consider a
worktree bare (in the case of `core.bare`) or operate on the wrong
worktree (in the case of `core.worktree`). Fix this problem by taking
advantage of the recently-added init_worktree_config() which enables
`extensions.worktreeConfig` and takes care of necessary bookkeeping.
While at it, for backward-compatibility reasons, also stop upgrading the
repository format to "1" since doing so is (unintentionally) not
required to take advantage of `extensions.worktreeConfig`, as explained
by 11664196ac ("Revert "check_repository_format_gently(): refuse
extensions for old repositories"", 2020-07-15).
[*] The main reason to use worktree-specific config for the
sparse-checkout builtin was to avoid enabling sparse-checkout patterns
in one and causing a loss of files in another. If a worktree does not
have a sparse-checkout patterns file, then the sparse-checkout logic
will not kick in on that worktree.
Reported-by: Sean Allred <allred.sean@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-02-07 22:33:01 +01:00
|
|
|
To ensure that adjusting the sparse-checkout settings within a worktree
|
|
|
|
does not alter the sparse-checkout settings in other worktrees, the 'set'
|
|
|
|
subcommand will upgrade your repository config to use worktree-specific
|
|
|
|
config if not already present. The sparsity defined by the arguments to
|
|
|
|
the 'set' subcommand are stored in the worktree-specific sparse-checkout
|
|
|
|
file. See linkgit:git-worktree[1] and the documentation of
|
|
|
|
`extensions.worktreeConfig` in linkgit:git-config[1] for more details.
|
|
|
|
+
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
When the `--stdin` option is provided, the directories or patterns are
|
|
|
|
read from standard in as a newline-delimited list instead of from the
|
|
|
|
arguments.
|
2020-01-23 20:00:02 +01:00
|
|
|
+
|
2022-04-22 04:32:20 +02:00
|
|
|
By default, the input list is considered a list of directories, matching
|
|
|
|
the output of `git ls-tree -d --name-only`. This includes interpreting
|
|
|
|
pathnames that begin with a double quote (") as C-style quoted strings.
|
|
|
|
Note that all files under the specified directories (at any depth) will
|
|
|
|
be included in the sparse checkout, as well as files that are siblings
|
|
|
|
of either the given directory or any of its ancestors (see 'CONE PATTERN
|
|
|
|
SET' below for more details). In the past, this was not the default,
|
|
|
|
and `--cone` needed to be specified or `core.sparseCheckoutCone` needed
|
|
|
|
to be enabled.
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
+
|
2022-04-22 04:32:21 +02:00
|
|
|
When `--no-cone` is passed, the input list is considered a list of
|
2022-04-22 04:32:25 +02:00
|
|
|
patterns. This mode has a number of drawbacks, including not working
|
|
|
|
with some options like `--sparse-index`. As explained in the
|
|
|
|
"Non-cone Problems" section below, we do not recommend using it.
|
2021-03-30 15:11:00 +02:00
|
|
|
+
|
2021-12-14 05:09:10 +01:00
|
|
|
Use the `--[no-]sparse-index` option to use a sparse index (the
|
|
|
|
default is to not use it). A sparse index 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.
|
2021-03-30 15:11:00 +02:00
|
|
|
+
|
|
|
|
**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
|
|
|
|
2020-02-11 16:02:23 +01:00
|
|
|
'add'::
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
Update the sparse-checkout file to include additional directories
|
|
|
|
(in cone mode) or patterns (in non-cone mode). By default, these
|
|
|
|
directories or patterns are read from the command-line arguments,
|
|
|
|
but they can be read from stdin using the `--stdin` option.
|
2020-02-11 16:02:23 +01:00
|
|
|
|
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.).
|
2021-12-14 05:09:10 +01:00
|
|
|
+
|
|
|
|
The `reapply` command can also take `--[no-]cone` and `--[no-]sparse-index`
|
|
|
|
flags, with the same meaning as the flags from the `set` command, in order
|
|
|
|
to change which sparsity mode you are using without needing to also respecify
|
|
|
|
all sparsity paths.
|
2020-03-27 01:49:01 +01:00
|
|
|
|
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
|
2021-12-14 05:09:10 +01:00
|
|
|
working directory to include all files.
|
|
|
|
|
|
|
|
'init'::
|
|
|
|
Deprecated command that behaves like `set` with no specified paths.
|
|
|
|
May be removed in the future.
|
|
|
|
+
|
|
|
|
Historically, `set` did not handle all the necessary config settings,
|
|
|
|
which meant that both `init` and `set` had to be called. Invoking
|
|
|
|
both meant the `init` step would first remove nearly all tracked files
|
|
|
|
(and in cone mode, ignored files too), then the `set` step would add
|
|
|
|
many of the tracked files (but not ignored files) back. In addition
|
|
|
|
to the lost files, the performance and UI of this combination was
|
|
|
|
poor.
|
|
|
|
+
|
|
|
|
Also, historically, `init` would not actually initialize the
|
|
|
|
sparse-checkout file if it already existed. This meant it was
|
|
|
|
possible to return to a sparse-checkout without remembering which
|
|
|
|
paths to pass to a subsequent 'set' or 'add' command. However,
|
|
|
|
`--cone` and `--sparse-index` options would not be remembered across
|
|
|
|
the disable command, so the easy restore of calling a plain `init`
|
|
|
|
decreased in utility.
|
2019-11-21 23:04:38 +01:00
|
|
|
|
2022-04-22 04:32:23 +02:00
|
|
|
EXAMPLES
|
|
|
|
--------
|
|
|
|
`git sparse-checkout set MY/DIR1 SUB/DIR2`::
|
|
|
|
|
|
|
|
Change to a sparse checkout with all files (at any depth) under
|
|
|
|
MY/DIR1/ and SUB/DIR2/ present in the working copy (plus all
|
|
|
|
files immediately under MY/ and SUB/ and the toplevel
|
|
|
|
directory). If already in a sparse checkout, change which files
|
|
|
|
are present in the working copy to this new selection. Note
|
|
|
|
that this command will also delete all ignored files in any
|
|
|
|
directory that no longer has either tracked or
|
|
|
|
non-ignored-untracked files present.
|
|
|
|
|
|
|
|
`git sparse-checkout disable`::
|
|
|
|
|
|
|
|
Repopulate the working directory with all files, disabling sparse
|
|
|
|
checkouts.
|
|
|
|
|
|
|
|
`git sparse-checkout add SOME/DIR/ECTORY`::
|
|
|
|
|
|
|
|
Add all files under SOME/DIR/ECTORY/ (at any depth) to the
|
|
|
|
sparse checkout, as well as all files immediately under
|
|
|
|
SOME/DIR/ and immediately under SOME/. Must already be in a
|
|
|
|
sparse checkout before using this command.
|
|
|
|
|
|
|
|
`git sparse-checkout reapply`::
|
|
|
|
|
|
|
|
It is possible for commands to update the working tree in a
|
|
|
|
way that does not respect the selected sparsity directories.
|
|
|
|
This can come from tools external to Git writing files, or
|
|
|
|
even affect Git commands because of either special cases (such
|
|
|
|
as hitting conflicts when merging/rebasing), or because some
|
|
|
|
commands didn't fully support sparse checkouts (e.g. the old
|
|
|
|
`recursive` merge backend had only limited support). This
|
|
|
|
command reapplies the existing sparse directory specifications
|
|
|
|
to make the working directory match.
|
|
|
|
|
2022-04-22 04:32:22 +02:00
|
|
|
INTERNALS -- SPARSE CHECKOUT
|
|
|
|
----------------------------
|
2019-11-21 23:04:33 +01:00
|
|
|
|
Update documentation related to sparsity and the skip-worktree bit
Make several small updates, to address a few documentation issues
I spotted:
* sparse-checkout focused on "patterns" even though the inputs (and
outputs in the case of `list`) are directories in cone-mode
* The description section of the sparse-checkout documentation
was a bit sparse (no pun intended), and focused more on internal
mechanics rather than end user usage. This made sense in the
early days when the command was even more experimental, but let's
adjust a bit to try to make it more approachable to end users who
may want to consider using it. Keep the scary backward
compatibility warning, though; we're still hard at work trying to
fix up commands to behave reasonably in sparse checkouts.
* both read-tree and update-index tried to describe how to use the
skip-worktree bit, but both predated the sparse-checkout command.
The sparse-checkout command is a far easier mechanism to use and
for users trying to reduce the size of their working tree, we
should recommend users to look at it instead.
* The update-index documentation pointed out that assume-unchanged
and skip-worktree sounded similar but had different purposes.
However, it made no attempt to explain the differences, only to
point out that they were different. Explain the differences.
* The update-index documentation focused much more on (internal?)
implementation details than on end-user usage. Try to explain
its purpose better for users of update-index, rather than
fellow developers trying to work with the SKIP_WORKTREE bit.
* Clarify that when core.sparseCheckout=true, we treat a file's
presence in the working tree as being an override to the
SKIP_WORKTREE bit (i.e. in sparse checkouts when the file is
present we ignore the SKIP_WORKTREE bit).
Note that this commit, like many touching documentation, is best viewed
with the `--color-words` option to diff/log.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-14 16:59:42 +01:00
|
|
|
"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, and the file is not present in the working tree,
|
|
|
|
then its absence is ignored. Git will avoid populating 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.
|
2019-11-21 23:04:33 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2022-04-22 04:32:25 +02:00
|
|
|
INTERNALS -- NON-CONE PROBLEMS
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
The `$GIT_DIR/info/sparse-checkout` file populated by the `set` and
|
|
|
|
`add` subcommands is defined to be a bunch of patterns (one per line)
|
|
|
|
using the same syntax as `.gitignore` files. In cone mode, these
|
|
|
|
patterns are restricted to matching directories (and users only ever
|
|
|
|
need supply or see directory names), while in non-cone mode any
|
|
|
|
gitignore-style pattern is permitted. Using the full gitignore-style
|
|
|
|
patterns in non-cone mode has a number of shortcomings:
|
|
|
|
|
|
|
|
* Fundamentally, it makes various worktree-updating processes (pull,
|
|
|
|
merge, rebase, switch, reset, checkout, etc.) require O(N*M) pattern
|
|
|
|
matches, where N is the number of patterns and M is the number of
|
|
|
|
paths in the index. This scales poorly.
|
|
|
|
|
|
|
|
* Avoiding the scaling issue has to be done via limiting the number
|
|
|
|
of patterns via specifying leading directory name or glob.
|
|
|
|
|
|
|
|
* Passing globs on the command line is error-prone as users may
|
|
|
|
forget to quote the glob, causing the shell to expand it into all
|
|
|
|
matching files and pass them all individually along to
|
|
|
|
sparse-checkout set/add. While this could also be a problem with
|
|
|
|
e.g. "git grep -- *.c", mistakes with grep/log/status appear in
|
|
|
|
the immediate output. With sparse-checkout, the mistake gets
|
|
|
|
recorded at the time the sparse-checkout command is run and might
|
|
|
|
not be problematic until the user later switches branches or rebases
|
|
|
|
or merges, thus putting a delay between the user's error and when
|
|
|
|
they have a chance to catch/notice it.
|
|
|
|
|
|
|
|
* Related to the previous item, sparse-checkout has an 'add'
|
|
|
|
subcommand but no 'remove' subcommand. Even if a 'remove'
|
|
|
|
subcommand were added, undoing an accidental unquoted glob runs
|
|
|
|
the risk of "removing too much", as it may remove entries that had
|
|
|
|
been included before the accidental add.
|
|
|
|
|
|
|
|
* Non-cone mode uses gitignore-style patterns to select what to
|
|
|
|
*include* (with the exception of negated patterns), while
|
|
|
|
.gitignore files use gitignore-style patterns to select what to
|
|
|
|
*exclude* (with the exception of negated patterns). The
|
|
|
|
documentation on gitignore-style patterns usually does not talk in
|
|
|
|
terms of matching or non-matching, but on what the user wants to
|
|
|
|
"exclude". This can cause confusion for users trying to learn how
|
|
|
|
to specify sparse-checkout patterns to get their desired behavior.
|
|
|
|
|
|
|
|
* Every other git subcommand that wants to provide "special path
|
|
|
|
pattern matching" of some sort uses pathspecs, but non-cone mode
|
|
|
|
for sparse-checkout uses gitignore patterns, which feels
|
|
|
|
inconsistent.
|
|
|
|
|
|
|
|
* It has edge cases where the "right" behavior is unclear. Two examples:
|
|
|
|
|
|
|
|
First, two users are in a subdirectory, and the first runs
|
|
|
|
git sparse-checkout set '/toplevel-dir/*.c'
|
|
|
|
while the second runs
|
|
|
|
git sparse-checkout set relative-dir
|
|
|
|
Should those arguments be transliterated into
|
|
|
|
current/subdirectory/toplevel-dir/*.c
|
|
|
|
and
|
|
|
|
current/subdirectory/relative-dir
|
|
|
|
before inserting into the sparse-checkout file? The user who typed
|
|
|
|
the first command is probably aware that arguments to set/add are
|
|
|
|
supposed to be patterns in non-cone mode, and probably would not be
|
|
|
|
happy with such a transliteration. However, many gitignore-style
|
|
|
|
patterns are just paths, which might be what the user who typed the
|
|
|
|
second command was thinking, and they'd be upset if their argument
|
|
|
|
wasn't transliterated.
|
|
|
|
|
|
|
|
Second, what should bash-completion complete on for set/add commands
|
|
|
|
for non-cone users? If it suggests paths, is it exacerbating the
|
|
|
|
problem above? Also, if it suggests paths, what if the user has a
|
|
|
|
file or directory that begins with either a '!' or '#' or has a '*',
|
|
|
|
'\', '?', '[', or ']' in its name? And if it suggests paths, will
|
|
|
|
it complete "/pro" to "/proc" (in the root filesytem) rather than to
|
|
|
|
"/progress.txt" in the current directory? (Note that users are
|
|
|
|
likely to want to start paths with a leading '/' in non-cone mode,
|
|
|
|
for the same reason that .gitignore files often have one.)
|
|
|
|
Completing on files or directories might give nasty surprises in
|
|
|
|
all these cases.
|
|
|
|
|
|
|
|
* The excessive flexibility made other extensions essentially
|
|
|
|
impractical. `--sparse-index` is likely impossible in non-cone
|
|
|
|
mode; even if it is somehow feasible, it would have been far more
|
|
|
|
work to implement and may have been too slow in practice. Some
|
|
|
|
ideas for adding coupling between partial clones and sparse
|
|
|
|
checkouts are only practical with a more restricted set of paths
|
|
|
|
as well.
|
|
|
|
|
|
|
|
For all these reasons, non-cone mode is deprecated. Please switch to
|
|
|
|
using cone mode.
|
|
|
|
|
2019-11-21 23:04:40 +01:00
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
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
|
2022-04-22 04:32:22 +02:00
|
|
|
-----------------------------
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
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:
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
1. *Recursive:* All paths inside a directory are included.
|
|
|
|
|
|
|
|
2. *Parent:* All files immediately inside a directory are included.
|
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
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:
|
2019-11-21 23:04:40 +01:00
|
|
|
|
|
|
|
----------------
|
|
|
|
/*
|
|
|
|
!/*/
|
|
|
|
----------------
|
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
This says "include everything immediately under the toplevel
|
|
|
|
directory, but nothing at any level below that."
|
2020-01-31 21:16:14 +01:00
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
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
|
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.
|
|
|
|
|
2022-04-22 04:32:19 +02:00
|
|
|
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
|
2022-04-22 04:32:24 +02:00
|
|
|
in the sparse-checkout. If they do not match, git will behave as though
|
|
|
|
`core.sparseCheckoutCone` was false, regardless of its setting.
|
2019-11-21 23:04:40 +01:00
|
|
|
|
2022-04-22 04:32:24 +02:00
|
|
|
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:
|
2019-12-30 16:33:12 +01:00
|
|
|
|
|
|
|
--------------------------
|
|
|
|
$ 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.
|
|
|
|
|
2022-04-22 04:32:22 +02:00
|
|
|
|
|
|
|
INTERNALS -- SUBMODULES
|
|
|
|
-----------------------
|
2019-12-30 16:33:13 +01:00
|
|
|
|
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
|