t7527: test status with untracked-cache and fsmonitor--daemon
[alt-git.git] / Documentation / git-sparse-checkout.txt
blob94dad137b96849599b2485c1f454bf4305cbbee2
1 git-sparse-checkout(1)
2 ======================
4 NAME
5 ----
6 git-sparse-checkout - Initialize and modify the sparse-checkout
7 configuration, which reduces the checkout to a set of paths
8 given by a list of patterns.
11 SYNOPSIS
12 --------
13 [verse]
14 'git sparse-checkout <subcommand> [<options>]'
17 DESCRIPTION
18 -----------
20 Initialize and modify the sparse-checkout configuration, which reduces
21 the checkout to a set of paths given by a list of patterns.
23 THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
24 COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN
25 THE FUTURE.
28 COMMANDS
29 --------
30 'list'::
31         Describe the patterns in the sparse-checkout file.
33 'set'::
34         Enable the necessary sparse-checkout config settings
35         (`core.sparseCheckout`, `core.sparseCheckoutCone`, and
36         `index.sparse`) if they are not already set to the desired values,
37         and write a set of patterns to the sparse-checkout file from the
38         list of arguments following the 'set' subcommand. Update the
39         working directory to match the new patterns.
41 To ensure that adjusting the sparse-checkout settings within a worktree
42 does not alter the sparse-checkout settings in other worktrees, the 'set'
43 subcommand will upgrade your repository config to use worktree-specific
44 config if not already present. The sparsity defined by the arguments to
45 the 'set' subcommand are stored in the worktree-specific sparse-checkout
46 file. See linkgit:git-worktree[1] and the documentation of
47 `extensions.worktreeConfig` in linkgit:git-config[1] for more details.
49 When the `--stdin` option is provided, the patterns are read from
50 standard in as a newline-delimited list instead of from the arguments.
52 When `--cone` is passed or `core.sparseCheckoutCone` is enabled, the
53 input list is considered a list of directories instead of
54 sparse-checkout patterns.  This allows for better performance with a
55 limited set of patterns (see 'CONE PATTERN SET' below).  Note that the
56 set command will write patterns to the sparse-checkout file to include
57 all files contained in those directories (recursively) as well as
58 files that are siblings of ancestor directories. The input format
59 matches the output of `git ls-tree --name-only`.  This includes
60 interpreting pathnames that begin with a double quote (") as C-style
61 quoted strings.  This may become the default in the future; --no-cone
62 can be passed to request non-cone mode.
64 Use the `--[no-]sparse-index` option to use a sparse index (the
65 default is to not use it).  A sparse index reduces the size of the
66 index to be more closely aligned with your sparse-checkout
67 definition. This can have significant performance advantages for
68 commands such as `git status` or `git add`.  This feature is still
69 experimental. Some commands might be slower with a sparse index until
70 they are properly integrated with the feature.
72 **WARNING:** Using a sparse index requires modifying the index in a way
73 that is not completely understood by external tools. If you have trouble
74 with this compatibility, then run `git sparse-checkout init --no-sparse-index`
75 to rewrite your index to not be sparse. Older versions of Git will not
76 understand the sparse directory entries index extension and may fail to
77 interact with your repository until it is disabled.
79 'add'::
80         Update the sparse-checkout file to include additional patterns.
81         By default, these patterns are read from the command-line arguments,
82         but they can be read from stdin using the `--stdin` option. When
83         `core.sparseCheckoutCone` is enabled, the given patterns are interpreted
84         as directory names as in the 'set' subcommand.
86 'reapply'::
87         Reapply the sparsity pattern rules to paths in the working tree.
88         Commands like merge or rebase can materialize paths to do their
89         work (e.g. in order to show you a conflict), and other
90         sparse-checkout commands might fail to sparsify an individual file
91         (e.g. because it has unstaged changes or conflicts).  In such
92         cases, it can make sense to run `git sparse-checkout reapply` later
93         after cleaning up affected paths (e.g. resolving conflicts, undoing
94         or committing changes, etc.).
96 The `reapply` command can also take `--[no-]cone` and `--[no-]sparse-index`
97 flags, with the same meaning as the flags from the `set` command, in order
98 to change which sparsity mode you are using without needing to also respecify
99 all sparsity paths.
101 'disable'::
102         Disable the `core.sparseCheckout` config setting, and restore the
103         working directory to include all files.
105 'init'::
106         Deprecated command that behaves like `set` with no specified paths.
107         May be removed in the future.
109 Historically, `set` did not handle all the necessary config settings,
110 which meant that both `init` and `set` had to be called.  Invoking
111 both meant the `init` step would first remove nearly all tracked files
112 (and in cone mode, ignored files too), then the `set` step would add
113 many of the tracked files (but not ignored files) back.  In addition
114 to the lost files, the performance and UI of this combination was
115 poor.
117 Also, historically, `init` would not actually initialize the
118 sparse-checkout file if it already existed.  This meant it was
119 possible to return to a sparse-checkout without remembering which
120 paths to pass to a subsequent 'set' or 'add' command.  However,
121 `--cone` and `--sparse-index` options would not be remembered across
122 the disable command, so the easy restore of calling a plain `init`
123 decreased in utility.
125 SPARSE CHECKOUT
126 ---------------
128 "Sparse checkout" allows populating the working directory sparsely.
129 It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell
130 Git whether a file in the working directory is worth looking at. If
131 the skip-worktree bit is set, then the file is ignored in the working
132 directory. Git will avoid populating the contents of those files, which
133 makes a sparse checkout helpful when working in a repository with many
134 files, but only a few are important to the current user.
136 The `$GIT_DIR/info/sparse-checkout` file is used to define the
137 skip-worktree reference bitmap. When Git updates the working
138 directory, it updates the skip-worktree bits in the index based
139 on this file. The files matching the patterns in the file will
140 appear in the working directory, and the rest will not.
142 To enable the sparse-checkout feature, run `git sparse-checkout set` to
143 set the patterns you want to use.
145 To repopulate the working directory with all files, use the
146 `git sparse-checkout disable` command.
149 FULL PATTERN SET
150 ----------------
152 By default, the sparse-checkout file uses the same syntax as `.gitignore`
153 files.
155 While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
156 files are included, you can also specify what files are _not_ included,
157 using negative patterns. For example, to remove the file `unwanted`:
159 ----------------
161 !unwanted
162 ----------------
165 CONE PATTERN SET
166 ----------------
168 The full pattern set allows for arbitrary pattern matches and complicated
169 inclusion/exclusion rules. These can result in O(N*M) pattern matches when
170 updating the index, where N is the number of patterns and M is the number
171 of paths in the index. To combat this performance issue, a more restricted
172 pattern set is allowed when `core.sparseCheckoutCone` is enabled.
174 The accepted patterns in the cone pattern set are:
176 1. *Recursive:* All paths inside a directory are included.
178 2. *Parent:* All files immediately inside a directory are included.
180 In addition to the above two patterns, we also expect that all files in the
181 root directory are included. If a recursive pattern is added, then all
182 leading directories are added as parent patterns.
184 By default, when running `git sparse-checkout init`, the root directory is
185 added as a parent pattern. At this point, the sparse-checkout file contains
186 the following patterns:
188 ----------------
190 !/*/
191 ----------------
193 This says "include everything in root, but nothing two levels below root."
195 When in cone mode, the `git sparse-checkout set` subcommand takes a list of
196 directories instead of a list of sparse-checkout patterns. In this mode,
197 the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as
198 a recursive pattern, the directories `A` and `A/B` are added as parent
199 patterns. The resulting sparse-checkout file is now
201 ----------------
203 !/*/
205 !/A/*/
206 /A/B/
207 !/A/B/*/
208 /A/B/C/
209 ----------------
211 Here, order matters, so the negative patterns are overridden by the positive
212 patterns that appear lower in the file.
214 If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file
215 expecting patterns of these types. Git will warn if the patterns do not match.
216 If the patterns do match the expected format, then Git will use faster hash-
217 based algorithms to compute inclusion in the sparse-checkout.
219 In the cone mode case, the `git sparse-checkout list` subcommand will list the
220 directories that define the recursive patterns. For the example sparse-checkout
221 file above, the output is as follows:
223 --------------------------
224 $ git sparse-checkout list
225 A/B/C
226 --------------------------
228 If `core.ignoreCase=true`, then the pattern-matching algorithm will use a
229 case-insensitive check. This corrects for case mismatched filenames in the
230 'git sparse-checkout set' command to reflect the expected cone in the working
231 directory.
233 When changing the sparse-checkout patterns in cone mode, Git will inspect each
234 tracked directory that is not within the sparse-checkout cone to see if it
235 contains any untracked files. If all of those files are ignored due to the
236 `.gitignore` patterns, then the directory will be deleted. If any of the
237 untracked files within that directory is not ignored, then no deletions will
238 occur within that directory and a warning message will appear. If these files
239 are important, then reset your sparse-checkout definition so they are included,
240 use `git add` and `git commit` to store them, then remove any remaining files
241 manually to ensure Git can behave optimally.
244 SUBMODULES
245 ----------
247 If your repository contains one or more submodules, then submodules
248 are populated based on interactions with the `git submodule` command.
249 Specifically, `git submodule init -- <path>` will ensure the submodule
250 at `<path>` is present, while `git submodule deinit [-f] -- <path>`
251 will remove the files for the submodule at `<path>` (including any
252 untracked files, uncommitted changes, and unpushed history).  Similar
253 to how sparse-checkout removes files from the working tree but still
254 leaves entries in the index, deinitialized submodules are removed from
255 the working directory but still have an entry in the index.
257 Since submodules may have unpushed changes or untracked files,
258 removing them could result in data loss.  Thus, changing sparse
259 inclusion/exclusion rules will not cause an already checked out
260 submodule to be removed from the working copy.  Said another way, just
261 as `checkout` will not cause submodules to be automatically removed or
262 initialized even when switching between branches that remove or add
263 submodules, using `sparse-checkout` to reduce or expand the scope of
264 "interesting" files will not cause submodules to be automatically
265 deinitialized or initialized either.
267 Further, the above facts mean that there are multiple reasons that
268 "tracked" files might not be present in the working copy: sparsity
269 pattern application from sparse-checkout, and submodule initialization
270 state.  Thus, commands like `git grep` that work on tracked files in
271 the working copy may return results that are limited by either or both
272 of these restrictions.
275 SEE ALSO
276 --------
278 linkgit:git-read-tree[1]
279 linkgit:gitignore[5]
283 Part of the linkgit:git[1] suite