]>
Commit | Line | Data |
---|---|---|
94c0956b DS |
1 | git-sparse-checkout(1) |
2 | ====================== | |
3 | ||
4 | NAME | |
5 | ---- | |
6 | git-sparse-checkout - Initialize and modify the sparse-checkout | |
7 | configuration, which reduces the checkout to a set of paths | |
757ff352 | 8 | given by a list of patterns. |
94c0956b DS |
9 | |
10 | ||
11 | SYNOPSIS | |
12 | -------- | |
13 | [verse] | |
14 | 'git sparse-checkout <subcommand> [options]' | |
15 | ||
16 | ||
17 | DESCRIPTION | |
18 | ----------- | |
19 | ||
20 | Initialize and modify the sparse-checkout configuration, which reduces | |
21 | the checkout to a set of paths given by a list of patterns. | |
22 | ||
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. | |
26 | ||
27 | ||
28 | COMMANDS | |
29 | -------- | |
30 | 'list':: | |
de11951b | 31 | Describe the patterns in the sparse-checkout file. |
94c0956b | 32 | |
bab3c359 DS |
33 | 'init':: |
34 | Enable the `core.sparseCheckout` setting. If the | |
35 | sparse-checkout file does not exist, then populate it with | |
36 | patterns that match every file in the root directory and | |
37 | no other directories, then will remove all directories tracked | |
38 | by Git. Add patterns to the sparse-checkout file to | |
39 | repopulate the working directory. | |
40 | + | |
41 | To avoid interfering with other worktrees, it first enables the | |
42 | `extensions.worktreeConfig` setting and makes sure to set the | |
43 | `core.sparseCheckout` setting in the worktree-specific config file. | |
a402723e MT |
44 | + |
45 | When `--cone` is provided, the `core.sparseCheckoutCone` setting is | |
46 | also set, allowing for better performance with a limited set of | |
47 | patterns (see 'CONE PATTERN SET' below). | |
122ba1f7 DS |
48 | + |
49 | Use the `--[no-]sparse-index` option to toggle the use of the sparse | |
50 | index format. This reduces the size of the index to be more closely | |
51 | aligned with your sparse-checkout definition. This can have significant | |
52 | performance advantages for commands such as `git status` or `git add`. | |
53 | This feature is still experimental. Some commands might be slower with | |
54 | a sparse index until they are properly integrated with the feature. | |
55 | + | |
56 | **WARNING:** Using a sparse index requires modifying the index in a way | |
57 | that is not completely understood by external tools. If you have trouble | |
58 | with this compatibility, then run `git sparse-checkout init --no-sparse-index` | |
59 | to rewrite your index to not be sparse. Older versions of Git will not | |
60 | understand the sparse directory entries index extension and may fail to | |
61 | interact with your repository until it is disabled. | |
94c0956b | 62 | |
f6039a94 DS |
63 | 'set':: |
64 | Write a set of patterns to the sparse-checkout file, as given as | |
65 | a list of arguments following the 'set' subcommand. Update the | |
66 | working directory to match the new patterns. Enable the | |
67 | core.sparseCheckout config setting if it is not already enabled. | |
7bffca95 DS |
68 | + |
69 | When the `--stdin` option is provided, the patterns are read from | |
70 | standard in as a newline-delimited list instead of from the arguments. | |
d2e65f4c DS |
71 | + |
72 | When `core.sparseCheckoutCone` is enabled, the input list is considered a | |
73 | list of directories instead of sparse-checkout patterns. The command writes | |
74 | patterns to the sparse-checkout file to include all files contained in those | |
75 | directories (recursively) as well as files that are siblings of ancestor | |
76 | directories. The input format matches the output of `git ls-tree --name-only`. | |
77 | This includes interpreting pathnames that begin with a double quote (") as | |
78 | C-style quoted strings. | |
f6039a94 | 79 | |
2631dc87 DS |
80 | 'add':: |
81 | Update the sparse-checkout file to include additional patterns. | |
82 | By default, these patterns are read from the command-line arguments, | |
83 | but they can be read from stdin using the `--stdin` option. When | |
84 | `core.sparseCheckoutCone` is enabled, the given patterns are interpreted | |
85 | as directory names as in the 'set' subcommand. | |
86 | ||
e2643353 | 87 | 'reapply':: |
5644ca28 EN |
88 | Reapply the sparsity pattern rules to paths in the working tree. |
89 | Commands like merge or rebase can materialize paths to do their | |
90 | work (e.g. in order to show you a conflict), and other | |
91 | sparse-checkout commands might fail to sparsify an individual file | |
92 | (e.g. because it has unstaged changes or conflicts). In such | |
93 | cases, it can make sense to run `git sparse-checkout reapply` later | |
94 | after cleaning up affected paths (e.g. resolving conflicts, undoing | |
95 | or committing changes, etc.). | |
96 | ||
72918c1a | 97 | 'disable':: |
99dfa6f9 DS |
98 | Disable the `core.sparseCheckout` config setting, and restore the |
99 | working directory to include all files. Leaves the sparse-checkout | |
100 | file intact so a later 'git sparse-checkout init' command may | |
101 | return the working directory to the same state. | |
72918c1a | 102 | |
94c0956b DS |
103 | SPARSE CHECKOUT |
104 | --------------- | |
105 | ||
106 | "Sparse checkout" allows populating the working directory sparsely. | |
107 | It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell | |
108 | Git whether a file in the working directory is worth looking at. If | |
109 | the skip-worktree bit is set, then the file is ignored in the working | |
110 | directory. Git will not populate the contents of those files, which | |
111 | makes a sparse checkout helpful when working in a repository with many | |
112 | files, but only a few are important to the current user. | |
113 | ||
114 | The `$GIT_DIR/info/sparse-checkout` file is used to define the | |
115 | skip-worktree reference bitmap. When Git updates the working | |
116 | directory, it updates the skip-worktree bits in the index based | |
117 | on this file. The files matching the patterns in the file will | |
118 | appear in the working directory, and the rest will not. | |
119 | ||
72918c1a DS |
120 | To enable the sparse-checkout feature, run `git sparse-checkout init` to |
121 | initialize a simple sparse-checkout file and enable the `core.sparseCheckout` | |
122 | config setting. Then, run `git sparse-checkout set` to modify the patterns in | |
123 | the sparse-checkout file. | |
124 | ||
125 | To repopulate the working directory with all files, use the | |
126 | `git sparse-checkout disable` command. | |
127 | ||
879321eb DS |
128 | |
129 | FULL PATTERN SET | |
130 | ---------------- | |
94c0956b DS |
131 | |
132 | By default, the sparse-checkout file uses the same syntax as `.gitignore` | |
133 | files. | |
134 | ||
135 | While `$GIT_DIR/info/sparse-checkout` is usually used to specify what | |
136 | files are included, you can also specify what files are _not_ included, | |
137 | using negative patterns. For example, to remove the file `unwanted`: | |
138 | ||
139 | ---------------- | |
140 | /* | |
141 | !unwanted | |
142 | ---------------- | |
143 | ||
94c0956b | 144 | |
879321eb DS |
145 | CONE PATTERN SET |
146 | ---------------- | |
147 | ||
148 | The full pattern set allows for arbitrary pattern matches and complicated | |
149 | inclusion/exclusion rules. These can result in O(N*M) pattern matches when | |
150 | updating the index, where N is the number of patterns and M is the number | |
151 | of paths in the index. To combat this performance issue, a more restricted | |
7aa9ef2f | 152 | pattern set is allowed when `core.sparseCheckoutCone` is enabled. |
879321eb DS |
153 | |
154 | The accepted patterns in the cone pattern set are: | |
155 | ||
156 | 1. *Recursive:* All paths inside a directory are included. | |
157 | ||
158 | 2. *Parent:* All files immediately inside a directory are included. | |
159 | ||
160 | In addition to the above two patterns, we also expect that all files in the | |
161 | root directory are included. If a recursive pattern is added, then all | |
162 | leading directories are added as parent patterns. | |
163 | ||
164 | By default, when running `git sparse-checkout init`, the root directory is | |
165 | added as a parent pattern. At this point, the sparse-checkout file contains | |
166 | the following patterns: | |
167 | ||
168 | ---------------- | |
169 | /* | |
170 | !/*/ | |
171 | ---------------- | |
172 | ||
173 | This says "include everything in root, but nothing two levels below root." | |
d2e65f4c DS |
174 | |
175 | When in cone mode, the `git sparse-checkout set` subcommand takes a list of | |
176 | directories instead of a list of sparse-checkout patterns. In this mode, | |
177 | the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as | |
178 | a recursive pattern, the directories `A` and `A/B` are added as parent | |
179 | patterns. The resulting sparse-checkout file is now | |
879321eb DS |
180 | |
181 | ---------------- | |
182 | /* | |
183 | !/*/ | |
184 | /A/ | |
185 | !/A/*/ | |
186 | /A/B/ | |
187 | !/A/B/*/ | |
188 | /A/B/C/ | |
189 | ---------------- | |
190 | ||
191 | Here, order matters, so the negative patterns are overridden by the positive | |
192 | patterns that appear lower in the file. | |
193 | ||
194 | If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file | |
195 | expecting patterns of these types. Git will warn if the patterns do not match. | |
196 | If the patterns do match the expected format, then Git will use faster hash- | |
197 | based algorithms to compute inclusion in the sparse-checkout. | |
198 | ||
de11951b DS |
199 | In the cone mode case, the `git sparse-checkout list` subcommand will list the |
200 | directories that define the recursive patterns. For the example sparse-checkout | |
201 | file above, the output is as follows: | |
202 | ||
203 | -------------------------- | |
204 | $ git sparse-checkout list | |
205 | A/B/C | |
206 | -------------------------- | |
207 | ||
190a65f9 DS |
208 | If `core.ignoreCase=true`, then the pattern-matching algorithm will use a |
209 | case-insensitive check. This corrects for case mismatched filenames in the | |
210 | 'git sparse-checkout set' command to reflect the expected cone in the working | |
211 | directory. | |
212 | ||
4fd683b6 DS |
213 | |
214 | SUBMODULES | |
215 | ---------- | |
216 | ||
e7d7c732 EN |
217 | If your repository contains one or more submodules, then submodules |
218 | are populated based on interactions with the `git submodule` command. | |
219 | Specifically, `git submodule init -- <path>` will ensure the submodule | |
220 | at `<path>` is present, while `git submodule deinit [-f] -- <path>` | |
221 | will remove the files for the submodule at `<path>` (including any | |
222 | untracked files, uncommitted changes, and unpushed history). Similar | |
223 | to how sparse-checkout removes files from the working tree but still | |
224 | leaves entries in the index, deinitialized submodules are removed from | |
225 | the working directory but still have an entry in the index. | |
226 | ||
227 | Since submodules may have unpushed changes or untracked files, | |
228 | removing them could result in data loss. Thus, changing sparse | |
229 | inclusion/exclusion rules will not cause an already checked out | |
230 | submodule to be removed from the working copy. Said another way, just | |
231 | as `checkout` will not cause submodules to be automatically removed or | |
232 | initialized even when switching between branches that remove or add | |
233 | submodules, using `sparse-checkout` to reduce or expand the scope of | |
234 | "interesting" files will not cause submodules to be automatically | |
235 | deinitialized or initialized either. | |
236 | ||
237 | Further, the above facts mean that there are multiple reasons that | |
238 | "tracked" files might not be present in the working copy: sparsity | |
239 | pattern application from sparse-checkout, and submodule initialization | |
240 | state. Thus, commands like `git grep` that work on tracked files in | |
241 | the working copy may return results that are limited by either or both | |
242 | of these restrictions. | |
4fd683b6 DS |
243 | |
244 | ||
94c0956b DS |
245 | SEE ALSO |
246 | -------- | |
247 | ||
248 | linkgit:git-read-tree[1] | |
249 | linkgit:gitignore[5] | |
250 | ||
251 | GIT | |
252 | --- | |
253 | Part of the linkgit:git[1] suite |