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