Skip to content

Commit 72fa58e

Browse files
newrengitster
authored andcommitted
git-sparse-checkout.txt: flesh out pattern set sections a bit
The "Internals -- Cone Pattern Set" section starts off discussing patterns, despite the fact that cone mode is about avoiding the patterns. This made sense back when non-cone mode was the default and we started by discussing the full pattern set, but now that we are changing the default, it makes more sense to discuss cone-mode first and avoid the full discussion of patterns. Split this section into two, the first with details about how cone mode operates, and the second following the full pattern set section and discussing how the cone mode patterns used under the hood relate to the full pattern set. While at it, flesh out the "Internals -- Full Pattern Set" section a bit to include more examples as well. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5d295dc commit 72fa58e

File tree

1 file changed

+85
-44
lines changed

1 file changed

+85
-44
lines changed

Documentation/git-sparse-checkout.txt

Lines changed: 85 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,40 @@ on this file. The files matching the patterns in the file will
192192
appear in the working directory, and the rest will not.
193193

194194

195-
INTERNALS -- CONE PATTERN SET
195+
INTERNALS -- CONE MODE HANDLING
196+
-------------------------------
197+
198+
The "cone mode", which is the default, lets you specify only what
199+
directories to include. For any directory specified, all paths below
200+
that directory will be included, and any paths immediately under
201+
leading directories (including the toplevel directory) will also be
202+
included. Thus, if you specified the directory
203+
Documentation/technical/
204+
then your sparse checkout would contain:
205+
206+
* all files in the toplevel-directory
207+
* all files immediately under Documentation/
208+
* all files at any depth under Documentation/technical/
209+
210+
Also, in cone mode, even if no directories are specified, then the
211+
files in the toplevel directory will be included.
212+
213+
When changing the sparse-checkout patterns in cone mode, Git will inspect each
214+
tracked directory that is not within the sparse-checkout cone to see if it
215+
contains any untracked files. If all of those files are ignored due to the
216+
`.gitignore` patterns, then the directory will be deleted. If any of the
217+
untracked files within that directory is not ignored, then no deletions will
218+
occur within that directory and a warning message will appear. If these files
219+
are important, then reset your sparse-checkout definition so they are included,
220+
use `git add` and `git commit` to store them, then remove any remaining files
221+
manually to ensure Git can behave optimally.
222+
223+
See also the "Internals -- Cone Pattern Set" section to learn how the
224+
directories are transformed under the hood into a subset of the
225+
Full Pattern Set of sparse-checkout.
226+
227+
228+
INTERNALS -- FULL PATTERN SET
196229
-----------------------------
197230

198231
The full pattern set allows for arbitrary pattern matches and complicated
@@ -201,31 +234,62 @@ updating the index, where N is the number of patterns and M is the number
201234
of paths in the index. To combat this performance issue, a more restricted
202235
pattern set is allowed when `core.sparseCheckoutCone` is enabled.
203236

204-
The accepted patterns in the cone pattern set are:
237+
The sparse-checkout file uses the same syntax as `.gitignore` files;
238+
see linkgit:gitignore[5] for details. Here, though, the patterns are
239+
usually being used to select which files to include rather than which
240+
files to exclude. (However, it can get a bit confusing since
241+
gitignore-style patterns have negations defined by patterns which
242+
begin with a '!', so you can also select files to _not_ include.)
243+
244+
For example, to select everything, and then to remove the file
245+
`unwanted` (so that every file will appear in your working tree except
246+
the file named `unwanted`):
247+
248+
git sparse-checkout set --no-cone '/*' '!unwanted'
249+
250+
These patterns are just placed into the
251+
`$GIT_DIR/info/sparse-checkout` as-is, so the contents of that file
252+
at this point would be
253+
254+
----------------
255+
/*
256+
!unwanted
257+
----------------
258+
259+
See also the "Sparse Checkout" section of linkgit:git-read-tree[1] to
260+
learn more about the gitignore-style patterns used in sparse
261+
checkouts.
262+
263+
264+
INTERNALS -- CONE PATTERN SET
265+
-----------------------------
266+
267+
In cone mode, only directories are accepted, but they are translated into
268+
the same gitignore-style patterns used in the full pattern set. We refer
269+
to the particular patterns used in those mode as being of one of two types:
205270

206271
1. *Recursive:* All paths inside a directory are included.
207272

208273
2. *Parent:* All files immediately inside a directory are included.
209274

210-
In addition to the above two patterns, we also expect that all files in the
211-
root directory are included. If a recursive pattern is added, then all
212-
leading directories are added as parent patterns.
213-
214-
By default, when running `git sparse-checkout set` with no directories
215-
specified, the root directory is added as a parent pattern. At this
216-
point, the sparse-checkout file contains the following patterns:
275+
Since cone mode always includes files at the toplevel, when running
276+
`git sparse-checkout set` with no directories specified, the toplevel
277+
directory is added as a parent pattern. At this point, the
278+
sparse-checkout file contains the following patterns:
217279

218280
----------------
219281
/*
220282
!/*/
221283
----------------
222284

223-
This says "include everything in root, but nothing two levels below root."
285+
This says "include everything immediately under the toplevel
286+
directory, but nothing at any level below that."
224287

225-
When in cone mode, the `git sparse-checkout set` subcommand takes a list of
226-
directories. In this mode, the command `git sparse-checkout set A/B/C` sets
227-
the directory `A/B/C` as a recursive pattern, the directories `A` and `A/B`
228-
are added as parent patterns. The resulting sparse-checkout file is now
288+
When in cone mode, the `git sparse-checkout set` subcommand takes a
289+
list of directories. The command `git sparse-checkout set A/B/C` sets
290+
the directory `A/B/C` as a recursive pattern, the directories `A` and
291+
`A/B` are added as parent patterns. The resulting sparse-checkout file
292+
is now
229293

230294
----------------
231295
/*
@@ -244,11 +308,14 @@ Unless `core.sparseCheckoutCone` is explicitly set to `false`, Git will
244308
parse the sparse-checkout file expecting patterns of these types. Git will
245309
warn if the patterns do not match. If the patterns do match the expected
246310
format, then Git will use faster hash-based algorithms to compute inclusion
247-
in the sparse-checkout.
311+
in the sparse-checkout. If they do not match, git will behave as though
312+
`core.sparseCheckoutCone` was false, regardless of its setting.
248313

249-
In the cone mode case, the `git sparse-checkout list` subcommand will list the
250-
directories that define the recursive patterns. For the example sparse-checkout
251-
file above, the output is as follows:
314+
In the cone mode case, despite the fact that full patterns are written
315+
to the $GIT_DIR/info/sparse-checkout file, the `git sparse-checkout
316+
list` subcommand will list the directories that define the recursive
317+
patterns. For the example sparse-checkout file above, the output is as
318+
follows:
252319

253320
--------------------------
254321
$ git sparse-checkout list
@@ -260,32 +327,6 @@ case-insensitive check. This corrects for case mismatched filenames in the
260327
'git sparse-checkout set' command to reflect the expected cone in the working
261328
directory.
262329

263-
When changing the sparse-checkout patterns in cone mode, Git will inspect each
264-
tracked directory that is not within the sparse-checkout cone to see if it
265-
contains any untracked files. If all of those files are ignored due to the
266-
`.gitignore` patterns, then the directory will be deleted. If any of the
267-
untracked files within that directory is not ignored, then no deletions will
268-
occur within that directory and a warning message will appear. If these files
269-
are important, then reset your sparse-checkout definition so they are included,
270-
use `git add` and `git commit` to store them, then remove any remaining files
271-
manually to ensure Git can behave optimally.
272-
273-
274-
INTERNALS -- FULL PATTERN SET
275-
-----------------------------
276-
277-
By default, the sparse-checkout file uses the same syntax as `.gitignore`
278-
files.
279-
280-
While `$GIT_DIR/info/sparse-checkout` is usually used to specify what
281-
files are included, you can also specify what files are _not_ included,
282-
using negative patterns. For example, to remove the file `unwanted`:
283-
284-
----------------
285-
/*
286-
!unwanted
287-
----------------
288-
289330

290331
INTERNALS -- SUBMODULES
291332
-----------------------

0 commit comments

Comments
 (0)