1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
6 <meta http-equiv=
"Content-Type" content=
"application/xhtml+xml; charset=UTF-8" />
7 <meta name=
"generator" content=
"AsciiDoc 10.2.0" />
8 <title>git-sparse-checkout(
1)
</title>
9 <style type=
"text/css">
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
14 font-family: Georgia,serif;
18 h1, h2, h3, h4, h5, h6,
19 div.title, caption.title,
20 thead, p.table.header,
22 #author, #revnumber, #revdate, #revremark,
24 font-family: Arial,Helvetica,sans-serif;
28 margin:
1em
5%
1em
5%;
33 text-decoration: underline;
49 h1, h2, h3, h4, h5, h6 {
57 border-bottom:
2px solid silver;
77 border:
1px solid silver;
88 ul
> li { color: #aaa; }
89 ul
> li
> * { color: black; }
91 .monospaced, code, pre {
92 font-family:
"Courier New", Courier, monospace;
99 white-space: pre-wrap;
109 #revnumber, #revdate, #revremark {
114 border-top:
2px solid silver;
120 padding-bottom:
0.5em;
124 padding-bottom:
0.5em;
129 margin-bottom:
1.5em;
131 div.imageblock, div.exampleblock, div.verseblock,
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
133 div.admonitionblock {
135 margin-bottom:
1.5em;
137 div.admonitionblock {
139 margin-bottom:
2.0em;
144 div.content { /* Block element content. */
148 /* Block element titles. */
149 div.title, caption.title {
154 margin-bottom:
0.5em;
160 td div.title:first-child {
163 div.content div.title:first-child {
166 div.content + div.title {
170 div.sidebarblock
> div.content {
172 border:
1px solid #dddddd;
173 border-left:
4px solid #f0f0f0;
177 div.listingblock
> div.content {
178 border:
1px solid #dddddd;
179 border-left:
5px solid #f0f0f0;
184 div.quoteblock, div.verseblock {
188 border-left:
5px solid #f0f0f0;
192 div.quoteblock
> div.attribution {
197 div.verseblock
> pre.content {
198 font-family: inherit;
201 div.verseblock
> div.attribution {
205 /* DEPRECATED: Pre version
8.2.7 verse style literal block. */
206 div.verseblock + div.attribution {
210 div.admonitionblock .icon {
214 text-decoration: underline;
216 padding-right:
0.5em;
218 div.admonitionblock td.content {
220 border-left:
3px solid #dddddd;
223 div.exampleblock
> div.content {
224 border-left:
3px solid #dddddd;
228 div.imageblock div.content { padding-left:
0; }
229 span.image img { border-style: none; vertical-align: text-bottom; }
230 a.image:visited { color: white; }
234 margin-bottom:
0.8em;
247 list-style-position: outside;
250 list-style-type: decimal;
253 list-style-type: lower-alpha;
256 list-style-type: upper-alpha;
259 list-style-type: lower-roman;
262 list-style-type: upper-roman;
265 div.compact ul, div.compact ol,
266 div.compact p, div.compact p,
267 div.compact div, div.compact div {
269 margin-bottom:
0.1em;
281 margin-bottom:
0.8em;
284 padding-bottom:
15px;
286 dt.hdlist1.strong, td.hdlist1.strong {
292 padding-right:
0.8em;
298 div.hdlist.compact tr {
307 .footnote, .footnoteref {
311 span.footnote, span.footnoteref {
312 vertical-align: super;
316 margin:
20px
0 20px
0;
320 #footnotes div.footnote {
326 border-top:
1px solid silver;
335 padding-right:
0.5em;
336 padding-bottom:
0.3em;
344 #footer-badges { display: none; }
348 margin-bottom:
2.5em;
356 margin-bottom:
0.1em;
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
376 span.aqua { color: aqua; }
377 span.black { color: black; }
378 span.blue { color: blue; }
379 span.fuchsia { color: fuchsia; }
380 span.gray { color: gray; }
381 span.green { color: green; }
382 span.lime { color: lime; }
383 span.maroon { color: maroon; }
384 span.navy { color: navy; }
385 span.olive { color: olive; }
386 span.purple { color: purple; }
387 span.red { color: red; }
388 span.silver { color: silver; }
389 span.teal { color: teal; }
390 span.white { color: white; }
391 span.yellow { color: yellow; }
393 span.aqua-background { background: aqua; }
394 span.black-background { background: black; }
395 span.blue-background { background: blue; }
396 span.fuchsia-background { background: fuchsia; }
397 span.gray-background { background: gray; }
398 span.green-background { background: green; }
399 span.lime-background { background: lime; }
400 span.maroon-background { background: maroon; }
401 span.navy-background { background: navy; }
402 span.olive-background { background: olive; }
403 span.purple-background { background: purple; }
404 span.red-background { background: red; }
405 span.silver-background { background: silver; }
406 span.teal-background { background: teal; }
407 span.white-background { background: white; }
408 span.yellow-background { background: yellow; }
410 span.big { font-size:
2em; }
411 span.small { font-size:
0.6em; }
413 span.underline { text-decoration: underline; }
414 span.overline { text-decoration: overline; }
415 span.line-through { text-decoration: line-through; }
417 div.unbreakable { page-break-inside: avoid; }
427 margin-bottom:
1.5em;
429 div.tableblock
> table {
430 border:
3px solid #
527bbd;
432 thead, p.table.header {
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
440 div.tableblock
> table[
frame=
"void"] {
443 div.tableblock
> table[
frame=
"hsides"] {
444 border-left-style: none;
445 border-right-style: none;
447 div.tableblock
> table[
frame=
"vsides"] {
448 border-top-style: none;
449 border-bottom-style: none;
460 margin-bottom:
1.5em;
462 thead, p.tableblock.header {
473 border-color: #
527bbd;
474 border-collapse: collapse;
476 th.tableblock, td.tableblock {
480 border-color: #
527bbd;
483 table.tableblock.frame-topbot {
484 border-left-style: hidden;
485 border-right-style: hidden;
487 table.tableblock.frame-sides {
488 border-top-style: hidden;
489 border-bottom-style: hidden;
491 table.tableblock.frame-none {
492 border-style: hidden;
495 th.tableblock.halign-left, td.tableblock.halign-left {
498 th.tableblock.halign-center, td.tableblock.halign-center {
501 th.tableblock.halign-right, td.tableblock.halign-right {
505 th.tableblock.valign-top, td.tableblock.valign-top {
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
509 vertical-align: middle;
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
512 vertical-align: bottom;
523 padding-bottom:
0.5em;
524 border-top:
2px solid silver;
525 border-bottom:
2px solid silver;
530 body.manpage div.sectionbody {
535 body.manpage div#toc { display: none; }
540 <script type=
"text/javascript">
542 var asciidoc = { // Namespace.
544 /////////////////////////////////////////////////////////////////////
545 // Table Of Contents generator
546 /////////////////////////////////////////////////////////////////////
548 /* Author: Mihai Bazon, September
2002
549 * http://students.infoiasi.ro/~mishoo
551 * Table Of Content generator
554 * Feel free to use this script under the terms of the GNU General Public
555 * License, as long as you do not remove or alter this notice.
558 /* modified by Troy D. Hanson, September
2006. License: GPL */
559 /* modified by Stuart Rackham,
2006,
2009. License: GPL */
562 toc: function (toclevels) {
564 function getText(el) {
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
567 if (i.nodeType ==
3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
569 else if (i.firstChild != null)
575 function TocEntry(el, text, toclevel) {
578 this.toclevel = toclevel;
581 function tocEntries(el, toclevels) {
582 var result = new Array;
583 var re = new RegExp('[hH]([
1-'+(toclevels+
1)+'])');
584 // Function that scans the DOM tree for header elements (the DOM2
585 // nodeIterator API would be a better technique but not supported by all
587 var iterate = function (el) {
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
589 if (i.nodeType ==
1 /* Node.ELEMENT_NODE */) {
590 var mo = re.exec(i.tagName);
591 if (mo && (i.getAttribute(
"class") || i.getAttribute(
"className")) !=
"float") {
592 result[result.length] = new TocEntry(i, getText(i), mo[
1]-
1);
602 var toc = document.getElementById(
"toc");
607 // Delete existing TOC entries in case we're reloading the TOC.
608 var tocEntriesToRemove = [];
610 for (i =
0; i < toc.childNodes.length; i++) {
611 var entry = toc.childNodes[i];
612 if (entry.nodeName.toLowerCase() == 'div'
613 && entry.getAttribute(
"class")
614 && entry.getAttribute(
"class").match(/^toclevel/))
615 tocEntriesToRemove.push(entry);
617 for (i =
0; i < tocEntriesToRemove.length; i++) {
618 toc.removeChild(tocEntriesToRemove[i]);
621 // Rebuild TOC entries.
622 var entries = tocEntries(document.getElementById(
"content"), toclevels);
623 for (var i =
0; i < entries.length; ++i) {
624 var entry = entries[i];
625 if (entry.element.id ==
"")
626 entry.element.id =
"_toc_" + i;
627 var a = document.createElement(
"a");
628 a.href =
"#" + entry.element.id;
629 a.appendChild(document.createTextNode(entry.text));
630 var div = document.createElement(
"div");
632 div.className =
"toclevel" + entry.toclevel;
633 toc.appendChild(div);
635 if (entries.length ==
0)
636 toc.parentNode.removeChild(toc);
640 /////////////////////////////////////////////////////////////////////
641 // Footnotes generator
642 /////////////////////////////////////////////////////////////////////
644 /* Based on footnote generation code from:
645 * http://www.brandspankingnew.net/archive/
2005/
07/format_footnote.html
648 footnotes: function () {
649 // Delete existing footnote entries in case we're reloading the footnodes.
651 var noteholder = document.getElementById(
"footnotes");
655 var entriesToRemove = [];
656 for (i =
0; i < noteholder.childNodes.length; i++) {
657 var entry = noteholder.childNodes[i];
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute(
"class") ==
"footnote")
659 entriesToRemove.push(entry);
661 for (i =
0; i < entriesToRemove.length; i++) {
662 noteholder.removeChild(entriesToRemove[i]);
665 // Rebuild footnote entries.
666 var cont = document.getElementById(
"content");
667 var spans = cont.getElementsByTagName(
"span");
670 for (i=
0; i
<spans.length; i++) {
671 if (spans[i].className ==
"footnote") {
673 var note = spans[i].getAttribute(
"data-note");
675 // Use [\s\S] in place of . so multi-line matches work.
676 // Because JavaScript has no s (dotall) regex flag.
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[
1];
679 "[<a id='_footnoteref_" + n +
"' href='#_footnote_" + n +
680 "' title='View footnote' class='footnote'>" + n +
"</a>]";
681 spans[i].setAttribute(
"data-note", note);
683 noteholder.innerHTML +=
684 "<div class='footnote' id='_footnote_" + n +
"'>" +
685 "<a href='#_footnoteref_" + n +
"' title='Return to text'>" +
686 n +
"</a>. " + note +
"</div>";
687 var id =spans[i].getAttribute(
"id");
688 if (id != null) refs[
"#"+id] = n;
692 noteholder.parentNode.removeChild(noteholder);
694 // Process footnoterefs.
695 for (i=
0; i
<spans.length; i++) {
696 if (spans[i].className ==
"footnoteref") {
697 var href = spans[i].getElementsByTagName(
"a")[
0].getAttribute(
"href");
698 href = href.match(/#.*/)[
0]; // Because IE return full URL.
701 "[<a href='#_footnote_" + n +
702 "' title='View footnote' class='footnote'>" + n +
"</a>]";
708 install: function(toclevels) {
711 function reinstall() {
712 asciidoc.footnotes();
714 asciidoc.toc(toclevels);
718 function reinstallAndRemoveTimer() {
719 clearInterval(timerId);
723 timerId = setInterval(reinstall,
500);
724 if (document.addEventListener)
725 document.addEventListener(
"DOMContentLoaded", reinstallAndRemoveTimer, false);
727 window.onload = reinstallAndRemoveTimer;
735 <body class=
"manpage">
738 git-sparse-checkout(
1) Manual Page
741 <div class=
"sectionbody">
742 <p>git-sparse-checkout -
743 Reduce your working tree to a subset of tracked files
749 <h2 id=
"_synopsis">SYNOPSIS
</h2>
750 <div class=
"sectionbody">
751 <div class=
"verseblock">
752 <pre class=
"content"><em>git sparse-checkout
</em> (init | list | set | add | reapply | disable | check-rules) [
<options
>]
</pre>
753 <div class=
"attribution">
758 <h2 id=
"_description">DESCRIPTION
</h2>
759 <div class=
"sectionbody">
760 <div class=
"paragraph"><p>This command is used to create sparse checkouts, which change the
761 working tree from having all tracked files present to only having a
762 subset of those files. It can also switch which subset of files are
763 present, or undo and go back to having all tracked files present in
764 the working copy.
</p></div>
765 <div class=
"paragraph"><p>The subset of files is chosen by providing a list of directories in
766 cone mode (the default), or by providing a list of patterns in
767 non-cone mode.
</p></div>
768 <div class=
"paragraph"><p>When in a sparse-checkout, other Git commands behave a bit differently.
769 For example, switching branches will not update paths outside the
770 sparse-checkout directories/patterns, and
<code>git commit -a
</code> will not record
771 paths outside the sparse-checkout directories/patterns as deleted.
</p></div>
772 <div class=
"paragraph"><p>THIS COMMAND IS EXPERIMENTAL. ITS BEHAVIOR, AND THE BEHAVIOR OF OTHER
773 COMMANDS IN THE PRESENCE OF SPARSE-CHECKOUTS, WILL LIKELY CHANGE IN
774 THE FUTURE.
</p></div>
778 <h2 id=
"_commands">COMMANDS
</h2>
779 <div class=
"sectionbody">
780 <div class=
"dlist"><dl>
786 Describe the directories or patterns in the sparse-checkout file.
794 Enable the necessary sparse-checkout config settings
795 (
<code>core.sparseCheckout
</code>,
<code>core.sparseCheckoutCone
</code>, and
796 <code>index.sparse
</code>) if they are not already set to the desired values,
797 populate the sparse-checkout file from the list of arguments
798 following the
<em>set
</em> subcommand, and update the working directory to
801 <div class=
"paragraph"><p>To ensure that adjusting the sparse-checkout settings within a worktree
802 does not alter the sparse-checkout settings in other worktrees, the
<em>set
</em>
803 subcommand will upgrade your repository config to use worktree-specific
804 config if not already present. The sparsity defined by the arguments to
805 the
<em>set
</em> subcommand are stored in the worktree-specific sparse-checkout
806 file. See
<a href=
"git-worktree.html">git-worktree(
1)
</a> and the documentation of
807 <code>extensions.worktreeConfig
</code> in
<a href=
"git-config.html">git-config(
1)
</a> for more details.
</p></div>
808 <div class=
"paragraph"><p>When the
<code>--stdin
</code> option is provided, the directories or patterns are
809 read from standard in as a newline-delimited list instead of from the
811 <div class=
"paragraph"><p>By default, the input list is considered a list of directories, matching
812 the output of
<code>git ls-tree -d --name-only
</code>. This includes interpreting
813 pathnames that begin with a double quote (
") as C-style quoted strings.
814 Note that all files under the specified directories (at any depth) will
815 be included in the sparse checkout, as well as files that are siblings
816 of either the given directory or any of its ancestors (see <em>CONE PATTERN
817 SET</em> below for more details). In the past, this was not the default,
818 and <code>--cone</code> needed to be specified or <code>core.sparseCheckoutCone</code> needed
819 to be enabled.</p></div>
820 <div class="paragraph
"><p>When <code>--no-cone</code> is passed, the input list is considered a list of
821 patterns. This mode has a number of drawbacks, including not working
822 with some options like <code>--sparse-index</code>. As explained in the
823 "Non-cone Problems
" section below, we do not recommend using it.</p></div>
824 <div class="paragraph
"><p>Use the <code>--[no-]sparse-index</code> option to use a sparse index (the
825 default is to not use it). A sparse index reduces the size of the
826 index to be more closely aligned with your sparse-checkout
827 definition. This can have significant performance advantages for
828 commands such as <code>git status</code> or <code>git add</code>. This feature is still
829 experimental. Some commands might be slower with a sparse index until
830 they are properly integrated with the feature.</p></div>
831 <div class="paragraph
"><p><strong>WARNING:</strong> Using a sparse index requires modifying the index in a way
832 that is not completely understood by external tools. If you have trouble
833 with this compatibility, then run <code>git sparse-checkout init --no-sparse-index</code>
834 to rewrite your index to not be sparse. Older versions of Git will not
835 understand the sparse directory entries index extension and may fail to
836 interact with your repository until it is disabled.</p></div>
843 Update the sparse-checkout file to include additional directories
844 (in cone mode) or patterns (in non-cone mode). By default, these
845 directories or patterns are read from the command-line arguments,
846 but they can be read from stdin using the <code>--stdin</code> option.
854 Reapply the sparsity pattern rules to paths in the working tree.
855 Commands like merge or rebase can materialize paths to do their
856 work (e.g. in order to show you a conflict), and other
857 sparse-checkout commands might fail to sparsify an individual file
858 (e.g. because it has unstaged changes or conflicts). In such
859 cases, it can make sense to run <code>git sparse-checkout reapply</code> later
860 after cleaning up affected paths (e.g. resolving conflicts, undoing
861 or committing changes, etc.).
863 <div class="paragraph
"><p>The <code>reapply</code> command can also take <code>--[no-]cone</code> and <code>--[no-]sparse-index</code>
864 flags, with the same meaning as the flags from the <code>set</code> command, in order
865 to change which sparsity mode you are using without needing to also respecify
866 all sparsity paths.</p></div>
873 Disable the <code>core.sparseCheckout</code> config setting, and restore the
874 working directory to include all files.
882 Deprecated command that behaves like <code>set</code> with no specified paths.
883 May be removed in the future.
885 <div class="paragraph
"><p>Historically, <code>set</code> did not handle all the necessary config settings,
886 which meant that both <code>init</code> and <code>set</code> had to be called. Invoking
887 both meant the <code>init</code> step would first remove nearly all tracked files
888 (and in cone mode, ignored files too), then the <code>set</code> step would add
889 many of the tracked files (but not ignored files) back. In addition
890 to the lost files, the performance and UI of this combination was
892 <div class="paragraph
"><p>Also, historically, <code>init</code> would not actually initialize the
893 sparse-checkout file if it already existed. This meant it was
894 possible to return to a sparse-checkout without remembering which
895 paths to pass to a subsequent <em>set</em> or <em>add</em> command. However,
896 <code>--cone</code> and <code>--sparse-index</code> options would not be remembered across
897 the disable command, so the easy restore of calling a plain <code>init</code>
898 decreased in utility.</p></div>
905 Check whether sparsity rules match one or more paths.
907 <div class="paragraph
"><p>By default <code>check-rules</code> reads a list of paths from stdin and outputs only
908 the ones that match the current sparsity rules. The input is expected to consist
909 of one path per line, matching the output of <code>git ls-tree --name-only</code> including
910 that pathnames that begin with a double quote (") are interpreted as C-style
911 quoted strings.
</p></div>
912 <div class=
"paragraph"><p>When called with the
<code>--rules-file
<file
></code> flag the input files are matched
913 against the sparse checkout rules found in
<code><file
></code> instead of the current ones.
914 The rules in the files are expected to be in the same form as accepted by
<code>git
915 sparse-checkout set --stdin
</code> (in particular, they must be newline-delimited).
</p></div>
916 <div class=
"paragraph"><p>By default, the rules passed to the
<code>--rules-file
</code> option are interpreted as
917 cone mode directories. To pass non-cone mode patterns with
<code>--rules-file
</code>,
918 combine the option with the
<code>--no-cone
</code> option.
</p></div>
919 <div class=
"paragraph"><p>When called with the
<code>-z
</code> flag, the format of the paths input on stdin as well
920 as the output paths are \
0 terminated and not quoted. Note that this does not
921 apply to the format of the rules passed with the
<code>--rules-file
</code> option.
</p></div>
927 <h2 id=
"_examples">EXAMPLES
</h2>
928 <div class=
"sectionbody">
929 <div class=
"dlist"><dl>
931 <code>git sparse-checkout set MY/DIR1 SUB/DIR2
</code>
935 Change to a sparse checkout with all files (at any depth) under
936 MY/DIR1/ and SUB/DIR2/ present in the working copy (plus all
937 files immediately under MY/ and SUB/ and the toplevel
938 directory). If already in a sparse checkout, change which files
939 are present in the working copy to this new selection. Note
940 that this command will also delete all ignored files in any
941 directory that no longer has either tracked or
942 non-ignored-untracked files present.
946 <code>git sparse-checkout disable
</code>
950 Repopulate the working directory with all files, disabling sparse
955 <code>git sparse-checkout add SOME/DIR/ECTORY
</code>
959 Add all files under SOME/DIR/ECTORY/ (at any depth) to the
960 sparse checkout, as well as all files immediately under
961 SOME/DIR/ and immediately under SOME/. Must already be in a
962 sparse checkout before using this command.
966 <code>git sparse-checkout reapply
</code>
970 It is possible for commands to update the working tree in a
971 way that does not respect the selected sparsity directories.
972 This can come from tools external to Git writing files, or
973 even affect Git commands because of either special cases (such
974 as hitting conflicts when merging/rebasing), or because some
975 commands didn
’t fully support sparse checkouts (e.g. the old
976 <code>recursive
</code> merge backend had only limited support). This
977 command reapplies the existing sparse directory specifications
978 to make the working directory match.
985 <h2 id=
"_internals_8201_8212_8201_sparse_checkout">INTERNALS
 — SPARSE CHECKOUT
</h2>
986 <div class=
"sectionbody">
987 <div class=
"paragraph"><p>"Sparse checkout" allows populating the working directory sparsely. It
988 uses the skip-worktree bit (see
<a href=
"git-update-index.html">git-update-index(
1)
</a>) to tell Git
989 whether a file in the working directory is worth looking at. If the
990 skip-worktree bit is set, and the file is not present in the working tree,
991 then its absence is ignored. Git will avoid populating the contents of
992 those files, which makes a sparse checkout helpful when working in a
993 repository with many files, but only a few are important to the current
995 <div class=
"paragraph"><p>The
<code>$GIT_DIR/info/sparse-checkout
</code> file is used to define the
996 skip-worktree reference bitmap. When Git updates the working
997 directory, it updates the skip-worktree bits in the index based
998 on this file. The files matching the patterns in the file will
999 appear in the working directory, and the rest will not.
</p></div>
1003 <h2 id=
"_internals_8201_8212_8201_non_cone_problems">INTERNALS
 — NON-CONE PROBLEMS
</h2>
1004 <div class=
"sectionbody">
1005 <div class=
"paragraph"><p>The
<code>$GIT_DIR/info/sparse-checkout
</code> file populated by the
<code>set
</code> and
1006 <code>add
</code> subcommands is defined to be a bunch of patterns (one per line)
1007 using the same syntax as
<code>.gitignore
</code> files. In cone mode, these
1008 patterns are restricted to matching directories (and users only ever
1009 need supply or see directory names), while in non-cone mode any
1010 gitignore-style pattern is permitted. Using the full gitignore-style
1011 patterns in non-cone mode has a number of shortcomings:
</p></div>
1012 <div class=
"ulist"><ul>
1015 Fundamentally, it makes various worktree-updating processes (pull,
1016 merge, rebase, switch, reset, checkout, etc.) require O(N*M) pattern
1017 matches, where N is the number of patterns and M is the number of
1018 paths in the index. This scales poorly.
1023 Avoiding the scaling issue has to be done via limiting the number
1024 of patterns via specifying leading directory name or glob.
1029 Passing globs on the command line is error-prone as users may
1030 forget to quote the glob, causing the shell to expand it into all
1031 matching files and pass them all individually along to
1032 sparse-checkout set/add. While this could also be a problem with
1033 e.g.
"git grep — *.c", mistakes with grep/log/status appear in
1034 the immediate output. With sparse-checkout, the mistake gets
1035 recorded at the time the sparse-checkout command is run and might
1036 not be problematic until the user later switches branches or rebases
1037 or merges, thus putting a delay between the user
’s error and when
1038 they have a chance to catch/notice it.
1043 Related to the previous item, sparse-checkout has an
<em>add
</em>
1044 subcommand but no
<em>remove
</em> subcommand. Even if a
<em>remove
</em>
1045 subcommand were added, undoing an accidental unquoted glob runs
1046 the risk of
"removing too much", as it may remove entries that had
1047 been included before the accidental add.
1052 Non-cone mode uses gitignore-style patterns to select what to
1053 <strong>include
</strong> (with the exception of negated patterns), while
1054 .gitignore files use gitignore-style patterns to select what to
1055 <strong>exclude
</strong> (with the exception of negated patterns). The
1056 documentation on gitignore-style patterns usually does not talk in
1057 terms of matching or non-matching, but on what the user wants to
1058 "exclude". This can cause confusion for users trying to learn how
1059 to specify sparse-checkout patterns to get their desired behavior.
1064 Every other git subcommand that wants to provide
"special path
1065 pattern matching" of some sort uses pathspecs, but non-cone mode
1066 for sparse-checkout uses gitignore patterns, which feels
1072 It has edge cases where the
"right" behavior is unclear. Two examples:
1074 <div class=
"literalblock">
1075 <div class=
"content">
1076 <pre><code>First, two users are in a subdirectory, and the first runs
1077 git sparse-checkout set '/toplevel-dir/*.c'
1078 while the second runs
1079 git sparse-checkout set relative-dir
1080 Should those arguments be transliterated into
1081 current/subdirectory/toplevel-dir/*.c
1083 current/subdirectory/relative-dir
1084 before inserting into the sparse-checkout file? The user who typed
1085 the first command is probably aware that arguments to set/add are
1086 supposed to be patterns in non-cone mode, and probably would not be
1087 happy with such a transliteration. However, many gitignore-style
1088 patterns are just paths, which might be what the user who typed the
1089 second command was thinking, and they'd be upset if their argument
1090 wasn't transliterated.
</code></pre>
1092 <div class=
"literalblock">
1093 <div class=
"content">
1094 <pre><code>Second, what should bash-completion complete on for set/add commands
1095 for non-cone users? If it suggests paths, is it exacerbating the
1096 problem above? Also, if it suggests paths, what if the user has a
1097 file or directory that begins with either a '!' or '#' or has a '*',
1098 '\', '?', '[', or ']' in its name? And if it suggests paths, will
1099 it complete
"/pro" to
"/proc" (in the root filesystem) rather than to
1100 "/progress.txt" in the current directory? (Note that users are
1101 likely to want to start paths with a leading '/' in non-cone mode,
1102 for the same reason that .gitignore files often have one.)
1103 Completing on files or directories might give nasty surprises in
1104 all these cases.
</code></pre>
1109 The excessive flexibility made other extensions essentially
1110 impractical.
<code>--sparse-index
</code> is likely impossible in non-cone
1111 mode; even if it is somehow feasible, it would have been far more
1112 work to implement and may have been too slow in practice. Some
1113 ideas for adding coupling between partial clones and sparse
1114 checkouts are only practical with a more restricted set of paths
1119 <div class=
"paragraph"><p>For all these reasons, non-cone mode is deprecated. Please switch to
1120 using cone mode.
</p></div>
1124 <h2 id=
"_internals_8201_8212_8201_cone_mode_handling">INTERNALS
 — CONE MODE HANDLING
</h2>
1125 <div class=
"sectionbody">
1126 <div class=
"paragraph"><p>The
"cone mode", which is the default, lets you specify only what
1127 directories to include. For any directory specified, all paths below
1128 that directory will be included, and any paths immediately under
1129 leading directories (including the toplevel directory) will also be
1130 included. Thus, if you specified the directory
1131 Documentation/technical/
1132 then your sparse checkout would contain:
</p></div>
1133 <div class=
"ulist"><ul>
1136 all files in the toplevel-directory
1141 all files immediately under Documentation/
1146 all files at any depth under Documentation/technical/
1150 <div class=
"paragraph"><p>Also, in cone mode, even if no directories are specified, then the
1151 files in the toplevel directory will be included.
</p></div>
1152 <div class=
"paragraph"><p>When changing the sparse-checkout patterns in cone mode, Git will inspect each
1153 tracked directory that is not within the sparse-checkout cone to see if it
1154 contains any untracked files. If all of those files are ignored due to the
1155 <code>.gitignore
</code> patterns, then the directory will be deleted. If any of the
1156 untracked files within that directory is not ignored, then no deletions will
1157 occur within that directory and a warning message will appear. If these files
1158 are important, then reset your sparse-checkout definition so they are included,
1159 use
<code>git add
</code> and
<code>git commit
</code> to store them, then remove any remaining files
1160 manually to ensure Git can behave optimally.
</p></div>
1161 <div class=
"paragraph"><p>See also the
"Internals — Cone Pattern Set" section to learn how the
1162 directories are transformed under the hood into a subset of the
1163 Full Pattern Set of sparse-checkout.
</p></div>
1167 <h2 id=
"_internals_8201_8212_8201_full_pattern_set">INTERNALS
 — FULL PATTERN SET
</h2>
1168 <div class=
"sectionbody">
1169 <div class=
"paragraph"><p>The full pattern set allows for arbitrary pattern matches and complicated
1170 inclusion/exclusion rules. These can result in O(N*M) pattern matches when
1171 updating the index, where N is the number of patterns and M is the number
1172 of paths in the index. To combat this performance issue, a more restricted
1173 pattern set is allowed when
<code>core.sparseCheckoutCone
</code> is enabled.
</p></div>
1174 <div class=
"paragraph"><p>The sparse-checkout file uses the same syntax as
<code>.gitignore
</code> files;
1175 see
<a href=
"gitignore.html">gitignore(
5)
</a> for details. Here, though, the patterns are
1176 usually being used to select which files to include rather than which
1177 files to exclude. (However, it can get a bit confusing since
1178 gitignore-style patterns have negations defined by patterns which
1179 begin with a
<em>!
</em>, so you can also select files to
<em>not
</em> include.)
</p></div>
1180 <div class=
"paragraph"><p>For example, to select everything, and then to remove the file
1181 <code>unwanted
</code> (so that every file will appear in your working tree except
1182 the file named
<code>unwanted
</code>):
</p></div>
1183 <div class=
"literalblock">
1184 <div class=
"content">
1185 <pre><code>git sparse-checkout set --no-cone '/*' '!unwanted'
</code></pre>
1187 <div class=
"paragraph"><p>These patterns are just placed into the
1188 <code>$GIT_DIR/info/sparse-checkout
</code> as-is, so the contents of that file
1189 at this point would be
</p></div>
1190 <div class=
"listingblock">
1191 <div class=
"content">
1193 !unwanted
</code></pre>
1195 <div class=
"paragraph"><p>See also the
"Sparse Checkout" section of
<a href=
"git-read-tree.html">git-read-tree(
1)
</a> to
1196 learn more about the gitignore-style patterns used in sparse
1197 checkouts.
</p></div>
1201 <h2 id=
"_internals_8201_8212_8201_cone_pattern_set">INTERNALS
 — CONE PATTERN SET
</h2>
1202 <div class=
"sectionbody">
1203 <div class=
"paragraph"><p>In cone mode, only directories are accepted, but they are translated into
1204 the same gitignore-style patterns used in the full pattern set. We refer
1205 to the particular patterns used in those mode as being of one of two types:
</p></div>
1206 <div class=
"olist arabic"><ol class=
"arabic">
1209 <strong>Recursive:
</strong> All paths inside a directory are included.
1214 <strong>Parent:
</strong> All files immediately inside a directory are included.
1218 <div class=
"paragraph"><p>Since cone mode always includes files at the toplevel, when running
1219 <code>git sparse-checkout set
</code> with no directories specified, the toplevel
1220 directory is added as a parent pattern. At this point, the
1221 sparse-checkout file contains the following patterns:
</p></div>
1222 <div class=
"listingblock">
1223 <div class=
"content">
1227 <div class=
"paragraph"><p>This says
"include everything immediately under the toplevel
1228 directory, but nothing at any level below that."</p></div>
1229 <div class=
"paragraph"><p>When in cone mode, the
<code>git sparse-checkout set
</code> subcommand takes a
1230 list of directories. The command
<code>git sparse-checkout set A/B/C
</code> sets
1231 the directory
<code>A/B/C
</code> as a recursive pattern, the directories
<code>A
</code> and
1232 <code>A/B
</code> are added as parent patterns. The resulting sparse-checkout file
1234 <div class=
"listingblock">
1235 <div class=
"content">
1242 /A/B/C/
</code></pre>
1244 <div class=
"paragraph"><p>Here, order matters, so the negative patterns are overridden by the positive
1245 patterns that appear lower in the file.
</p></div>
1246 <div class=
"paragraph"><p>Unless
<code>core.sparseCheckoutCone
</code> is explicitly set to
<code>false
</code>, Git will
1247 parse the sparse-checkout file expecting patterns of these types. Git will
1248 warn if the patterns do not match. If the patterns do match the expected
1249 format, then Git will use faster hash-based algorithms to compute inclusion
1250 in the sparse-checkout. If they do not match, git will behave as though
1251 <code>core.sparseCheckoutCone
</code> was false, regardless of its setting.
</p></div>
1252 <div class=
"paragraph"><p>In the cone mode case, despite the fact that full patterns are written
1253 to the $GIT_DIR/info/sparse-checkout file, the
<code>git sparse-checkout
1254 list
</code> subcommand will list the directories that define the recursive
1255 patterns. For the example sparse-checkout file above, the output is as
1257 <div class=
"listingblock">
1258 <div class=
"content">
1259 <pre><code>$ git sparse-checkout list
1262 <div class=
"paragraph"><p>If
<code>core.ignoreCase=true
</code>, then the pattern-matching algorithm will use a
1263 case-insensitive check. This corrects for case mismatched filenames in the
1264 <em>git sparse-checkout set
</em> command to reflect the expected cone in the working
1265 directory.
</p></div>
1269 <h2 id=
"_internals_8201_8212_8201_submodules">INTERNALS
 — SUBMODULES
</h2>
1270 <div class=
"sectionbody">
1271 <div class=
"paragraph"><p>If your repository contains one or more submodules, then submodules
1272 are populated based on interactions with the
<code>git submodule
</code> command.
1273 Specifically,
<code>git submodule init --
<path
></code> will ensure the submodule
1274 at
<code><path
></code> is present, while
<code>git submodule deinit [-f] --
<path
></code>
1275 will remove the files for the submodule at
<code><path
></code> (including any
1276 untracked files, uncommitted changes, and unpushed history). Similar
1277 to how sparse-checkout removes files from the working tree but still
1278 leaves entries in the index, deinitialized submodules are removed from
1279 the working directory but still have an entry in the index.
</p></div>
1280 <div class=
"paragraph"><p>Since submodules may have unpushed changes or untracked files,
1281 removing them could result in data loss. Thus, changing sparse
1282 inclusion/exclusion rules will not cause an already checked out
1283 submodule to be removed from the working copy. Said another way, just
1284 as
<code>checkout
</code> will not cause submodules to be automatically removed or
1285 initialized even when switching between branches that remove or add
1286 submodules, using
<code>sparse-checkout
</code> to reduce or expand the scope of
1287 "interesting" files will not cause submodules to be automatically
1288 deinitialized or initialized either.
</p></div>
1289 <div class=
"paragraph"><p>Further, the above facts mean that there are multiple reasons that
1290 "tracked" files might not be present in the working copy: sparsity
1291 pattern application from sparse-checkout, and submodule initialization
1292 state. Thus, commands like
<code>git grep
</code> that work on tracked files in
1293 the working copy may return results that are limited by either or both
1294 of these restrictions.
</p></div>
1298 <h2 id=
"_see_also">SEE ALSO
</h2>
1299 <div class=
"sectionbody">
1300 <div class=
"paragraph"><p><a href=
"git-read-tree.html">git-read-tree(
1)
</a>
1301 <a href=
"gitignore.html">gitignore(
5)
</a></p></div>
1305 <h2 id=
"_git">GIT
</h2>
1306 <div class=
"sectionbody">
1307 <div class=
"paragraph"><p>Part of the
<a href=
"git.html">git(
1)
</a> suite
</p></div>
1311 <div id=
"footnotes"><hr /></div>
1313 <div id=
"footer-text">
1315 2023-
06-
23 13:
24:
09 PDT