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