]>
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). | |
94c0956b | 48 | |
f6039a94 DS |
49 | 'set':: |
50 | Write a set of patterns to the sparse-checkout file, as given as | |
51 | a list of arguments following the 'set' subcommand. Update the | |
52 | working directory to match the new patterns. Enable the | |
53 | core.sparseCheckout config setting if it is not already enabled. | |
7bffca95 DS |
54 | + |
55 | When the `--stdin` option is provided, the patterns are read from | |
56 | standard in as a newline-delimited list instead of from the arguments. | |
d2e65f4c DS |
57 | + |
58 | When `core.sparseCheckoutCone` is enabled, the input list is considered a | |
59 | list of directories instead of sparse-checkout patterns. The command writes | |
60 | patterns to the sparse-checkout file to include all files contained in those | |
61 | directories (recursively) as well as files that are siblings of ancestor | |
62 | directories. The input format matches the output of `git ls-tree --name-only`. | |
63 | This includes interpreting pathnames that begin with a double quote (") as | |
64 | C-style quoted strings. | |
f6039a94 | 65 | |
2631dc87 DS |
66 | 'add':: |
67 | Update the sparse-checkout file to include additional patterns. | |
68 | By default, these patterns are read from the command-line arguments, | |
69 | but they can be read from stdin using the `--stdin` option. When | |
70 | `core.sparseCheckoutCone` is enabled, the given patterns are interpreted | |
71 | as directory names as in the 'set' subcommand. | |
72 | ||
e2643353 | 73 | 'reapply':: |
5644ca28 EN |
74 | Reapply the sparsity pattern rules to paths in the working tree. |
75 | Commands like merge or rebase can materialize paths to do their | |
76 | work (e.g. in order to show you a conflict), and other | |
77 | sparse-checkout commands might fail to sparsify an individual file | |
78 | (e.g. because it has unstaged changes or conflicts). In such | |
79 | cases, it can make sense to run `git sparse-checkout reapply` later | |
80 | after cleaning up affected paths (e.g. resolving conflicts, undoing | |
81 | or committing changes, etc.). | |
82 | ||
72918c1a | 83 | 'disable':: |
99dfa6f9 DS |
84 | Disable the `core.sparseCheckout` config setting, and restore the |
85 | working directory to include all files. Leaves the sparse-checkout | |
86 | file intact so a later 'git sparse-checkout init' command may | |
87 | return the working directory to the same state. | |
72918c1a | 88 | |
94c0956b DS |
89 | SPARSE CHECKOUT |
90 | --------------- | |
91 | ||
92 | "Sparse checkout" allows populating the working directory sparsely. | |
93 | It uses the skip-worktree bit (see linkgit:git-update-index[1]) to tell | |
94 | Git whether a file in the working directory is worth looking at. If | |
95 | the skip-worktree bit is set, then the file is ignored in the working | |
96 | directory. Git will not populate the contents of those files, which | |
97 | makes a sparse checkout helpful when working in a repository with many | |
98 | files, but only a few are important to the current user. | |
99 | ||
100 | The `$GIT_DIR/info/sparse-checkout` file is used to define the | |
101 | skip-worktree reference bitmap. When Git updates the working | |
102 | directory, it updates the skip-worktree bits in the index based | |
103 | on this file. The files matching the patterns in the file will | |
104 | appear in the working directory, and the rest will not. | |
105 | ||
72918c1a DS |
106 | To enable the sparse-checkout feature, run `git sparse-checkout init` to |
107 | initialize a simple sparse-checkout file and enable the `core.sparseCheckout` | |
108 | config setting. Then, run `git sparse-checkout set` to modify the patterns in | |
109 | the sparse-checkout file. | |
110 | ||
111 | To repopulate the working directory with all files, use the | |
112 | `git sparse-checkout disable` command. | |
113 | ||
879321eb DS |
114 | |
115 | FULL PATTERN SET | |
116 | ---------------- | |
94c0956b DS |
117 | |
118 | By default, the sparse-checkout file uses the same syntax as `.gitignore` | |
119 | files. | |
120 | ||
121 | While `$GIT_DIR/info/sparse-checkout` is usually used to specify what | |
122 | files are included, you can also specify what files are _not_ included, | |
123 | using negative patterns. For example, to remove the file `unwanted`: | |
124 | ||
125 | ---------------- | |
126 | /* | |
127 | !unwanted | |
128 | ---------------- | |
129 | ||
94c0956b | 130 | |
879321eb DS |
131 | CONE PATTERN SET |
132 | ---------------- | |
133 | ||
134 | The full pattern set allows for arbitrary pattern matches and complicated | |
135 | inclusion/exclusion rules. These can result in O(N*M) pattern matches when | |
136 | updating the index, where N is the number of patterns and M is the number | |
137 | of paths in the index. To combat this performance issue, a more restricted | |
7aa9ef2f | 138 | pattern set is allowed when `core.sparseCheckoutCone` is enabled. |
879321eb DS |
139 | |
140 | The accepted patterns in the cone pattern set are: | |
141 | ||
142 | 1. *Recursive:* All paths inside a directory are included. | |
143 | ||
144 | 2. *Parent:* All files immediately inside a directory are included. | |
145 | ||
146 | In addition to the above two patterns, we also expect that all files in the | |
147 | root directory are included. If a recursive pattern is added, then all | |
148 | leading directories are added as parent patterns. | |
149 | ||
150 | By default, when running `git sparse-checkout init`, the root directory is | |
151 | added as a parent pattern. At this point, the sparse-checkout file contains | |
152 | the following patterns: | |
153 | ||
154 | ---------------- | |
155 | /* | |
156 | !/*/ | |
157 | ---------------- | |
158 | ||
159 | This says "include everything in root, but nothing two levels below root." | |
d2e65f4c DS |
160 | |
161 | When in cone mode, the `git sparse-checkout set` subcommand takes a list of | |
162 | directories instead of a list of sparse-checkout patterns. In this mode, | |
163 | the command `git sparse-checkout set A/B/C` sets the directory `A/B/C` as | |
164 | a recursive pattern, the directories `A` and `A/B` are added as parent | |
165 | patterns. The resulting sparse-checkout file is now | |
879321eb DS |
166 | |
167 | ---------------- | |
168 | /* | |
169 | !/*/ | |
170 | /A/ | |
171 | !/A/*/ | |
172 | /A/B/ | |
173 | !/A/B/*/ | |
174 | /A/B/C/ | |
175 | ---------------- | |
176 | ||
177 | Here, order matters, so the negative patterns are overridden by the positive | |
178 | patterns that appear lower in the file. | |
179 | ||
180 | If `core.sparseCheckoutCone=true`, then Git will parse the sparse-checkout file | |
181 | expecting patterns of these types. Git will warn if the patterns do not match. | |
182 | If the patterns do match the expected format, then Git will use faster hash- | |
183 | based algorithms to compute inclusion in the sparse-checkout. | |
184 | ||
de11951b DS |
185 | In the cone mode case, the `git sparse-checkout list` subcommand will list the |
186 | directories that define the recursive patterns. For the example sparse-checkout | |
187 | file above, the output is as follows: | |
188 | ||
189 | -------------------------- | |
190 | $ git sparse-checkout list | |
191 | A/B/C | |
192 | -------------------------- | |
193 | ||
190a65f9 DS |
194 | If `core.ignoreCase=true`, then the pattern-matching algorithm will use a |
195 | case-insensitive check. This corrects for case mismatched filenames in the | |
196 | 'git sparse-checkout set' command to reflect the expected cone in the working | |
197 | directory. | |
198 | ||
4fd683b6 DS |
199 | |
200 | SUBMODULES | |
201 | ---------- | |
202 | ||
203 | If your repository contains one or more submodules, then those submodules will | |
204 | appear based on which you initialized with the `git submodule` command. If | |
205 | your sparse-checkout patterns exclude an initialized submodule, then that | |
206 | submodule will still appear in your working directory. | |
207 | ||
208 | ||
94c0956b DS |
209 | SEE ALSO |
210 | -------- | |
211 | ||
212 | linkgit:git-read-tree[1] | |
213 | linkgit:gitignore[5] | |
214 | ||
215 | GIT | |
216 | --- | |
217 | Part of the linkgit:git[1] suite |