Fix typos
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-gc.xml
blob98628194d8bf44aa6bf09b29935e56b65ba712f8
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-gc(1)">\r
5     <title>git-gc(1)</title>\r
6     <date>2023-11-02</date>\r
7 <revhistory><revision><date>2023-11-02</date></revision></revhistory>\r
8 <indexterm>\r
9 <primary>git-gc(1)</primary>\r
10 </indexterm>\r
11 <simplesect id="git-gc(1)__name">\r
12 <title>NAME</title>\r
13 <simpara>git-gc - Cleanup unnecessary files and optimize the local repository</simpara>\r
14 </simplesect>\r
15 <simplesect id="git-gc(1)__synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git gc</emphasis> [--aggressive] [--auto] [--quiet] [--prune=&lt;date&gt; | --no-prune] [--force] [--keep-largest-pack]</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="git-gc(1)__description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Runs a number of housekeeping tasks within the current repository,\r
24 such as compressing file revisions (to reduce disk space and increase\r
25 performance), removing unreachable objects which may have been\r
26 created from prior invocations of <emphasis>git add</emphasis>, packing refs, pruning\r
27 reflog, rerere metadata or stale working trees. May also update ancillary\r
28 indexes such as the commit-graph.</simpara>\r
29 <simpara>When common porcelain operations that create objects are run, they\r
30 will check whether the repository has grown substantially since the\r
31 last maintenance, and if so run <emphasis>git gc</emphasis> automatically. See <emphasis>gc.auto</emphasis>\r
32 below for how to disable this behavior.</simpara>\r
33 <simpara>Running <emphasis>git gc</emphasis> manually should only be needed when adding objects to\r
34 a repository without regularly running such porcelain commands, to do\r
35 a one-off repository optimization, or e.g. to clean up a suboptimal\r
36 mass-import. See the "PACKFILE OPTIMIZATION" section in\r
37 <xref linkend="git-fast-import(1)" /> for more details on the import case.</simpara>\r
38 </simplesect>\r
39 <simplesect id="git-gc(1)__options">\r
40 <title>OPTIONS</title>\r
41 <variablelist>\r
42 <varlistentry>\r
43 <term>\r
44 --aggressive\r
45 </term>\r
46 <listitem>\r
47 <simpara>\r
48         Usually <emphasis>git gc</emphasis> runs very quickly while providing good disk\r
49         space utilization and performance.  This option will cause\r
50         <emphasis>git gc</emphasis> to more aggressively optimize the repository at the expense\r
51         of taking much more time.  The effects of this optimization are\r
52         mostly persistent. See the "AGGRESSIVE" section below for details.\r
53 </simpara>\r
54 </listitem>\r
55 </varlistentry>\r
56 <varlistentry>\r
57 <term>\r
58 --auto\r
59 </term>\r
60 <listitem>\r
61 <simpara>\r
62         With this option, <emphasis>git gc</emphasis> checks whether any housekeeping is\r
63         required; if not, it exits without performing any work.\r
64 </simpara>\r
65 <simpara>See the <emphasis>gc.auto</emphasis> option in the "CONFIGURATION" section below for how\r
66 this heuristic works.</simpara>\r
67 <simpara>Once housekeeping is triggered by exceeding the limits of\r
68 configuration options such as <emphasis>gc.auto</emphasis> and <emphasis>gc.autoPackLimit</emphasis>, all\r
69 other housekeeping tasks (e.g. rerere, working trees, reflog&#8230;) will\r
70 be performed as well.</simpara>\r
71 </listitem>\r
72 </varlistentry>\r
73 <varlistentry>\r
74 <term>\r
75 --[no-]cruft\r
76 </term>\r
77 <listitem>\r
78 <simpara>\r
79         When expiring unreachable objects, pack them separately into a\r
80         cruft pack instead of storing them as loose objects. <emphasis>--cruft</emphasis>\r
81         is on by default.\r
82 </simpara>\r
83 </listitem>\r
84 </varlistentry>\r
85 <varlistentry>\r
86 <term>\r
87 --prune=&lt;date&gt;\r
88 </term>\r
89 <listitem>\r
90 <simpara>\r
91         Prune loose objects older than date (default is 2 weeks ago,\r
92         overridable by the config variable <emphasis>gc.pruneExpire</emphasis>).\r
93         --prune=now prunes loose objects regardless of their age and\r
94         increases the risk of corruption if another process is writing to\r
95         the repository concurrently; see "NOTES" below. --prune is on by\r
96         default.\r
97 </simpara>\r
98 </listitem>\r
99 </varlistentry>\r
100 <varlistentry>\r
101 <term>\r
102 --no-prune\r
103 </term>\r
104 <listitem>\r
105 <simpara>\r
106         Do not prune any loose objects.\r
107 </simpara>\r
108 </listitem>\r
109 </varlistentry>\r
110 <varlistentry>\r
111 <term>\r
112 --quiet\r
113 </term>\r
114 <listitem>\r
115 <simpara>\r
116         Suppress all progress reports.\r
117 </simpara>\r
118 </listitem>\r
119 </varlistentry>\r
120 <varlistentry>\r
121 <term>\r
122 --force\r
123 </term>\r
124 <listitem>\r
125 <simpara>\r
126         Force <emphasis>git gc</emphasis> to run even if there may be another <emphasis>git gc</emphasis>\r
127         instance running on this repository.\r
128 </simpara>\r
129 </listitem>\r
130 </varlistentry>\r
131 <varlistentry>\r
132 <term>\r
133 --keep-largest-pack\r
134 </term>\r
135 <listitem>\r
136 <simpara>\r
137         All packs except the largest non-cruft pack, any packs marked\r
138         with a <emphasis>.keep</emphasis> file, and any cruft pack(s) are consolidated into\r
139         a single pack. When this option is used, <emphasis>gc.bigPackThreshold</emphasis>\r
140         is ignored.\r
141 </simpara>\r
142 </listitem>\r
143 </varlistentry>\r
144 </variablelist>\r
145 </simplesect>\r
146 <simplesect id="git-gc(1)__aggressive">\r
147 <title>AGGRESSIVE</title>\r
148 <simpara>When the <emphasis>--aggressive</emphasis> option is supplied, <xref linkend="git-repack(1)" /> will\r
149 be invoked with the <emphasis>-f</emphasis> flag, which in turn will pass\r
150 <emphasis>--no-reuse-delta</emphasis> to <xref linkend="git-pack-objects(1)" />. This will throw\r
151 away any existing deltas and re-compute them, at the expense of\r
152 spending much more time on the repacking.</simpara>\r
153 <simpara>The effects of this are mostly persistent, e.g. when packs and loose\r
154 objects are coalesced into one another pack the existing deltas in\r
155 that pack might get re-used, but there are also various cases where we\r
156 might pick a sub-optimal delta from a newer pack instead.</simpara>\r
157 <simpara>Furthermore, supplying <emphasis>--aggressive</emphasis> will tweak the <emphasis>--depth</emphasis> and\r
158 <emphasis>--window</emphasis> options passed to <xref linkend="git-repack(1)" />. See the\r
159 <emphasis>gc.aggressiveDepth</emphasis> and <emphasis>gc.aggressiveWindow</emphasis> settings below. By\r
160 using a larger window size we're more likely to find more optimal\r
161 deltas.</simpara>\r
162 <simpara>It's probably not worth it to use this option on a given repository\r
163 without running tailored performance benchmarks on it. It takes a lot\r
164 more time, and the resulting space/delta optimization may or may not\r
165 be worth it. Not using this at all is the right trade-off for most\r
166 users and their repositories.</simpara>\r
167 </simplesect>\r
168 <simplesect id="git-gc(1)__configuration">\r
169 <title>CONFIGURATION</title>\r
170 <simpara>Everything below this line in this section is selectively included\r
171 from the <xref linkend="git-config(1)" /> documentation. The content is the same\r
172 as what's found there:</simpara>\r
173 <variablelist>\r
174 <varlistentry>\r
175 <term>\r
176 gc.aggressiveDepth\r
177 </term>\r
178 <listitem>\r
179 <simpara>\r
180         The depth parameter used in the delta compression\r
181         algorithm used by <emphasis>git gc --aggressive</emphasis>.  This defaults\r
182         to 50, which is the default for the <emphasis>--depth</emphasis> option when\r
183         <emphasis>--aggressive</emphasis> isn't in use.\r
184 </simpara>\r
185 <simpara>See the documentation for the <emphasis>--depth</emphasis> option in\r
186 <xref linkend="git-repack(1)" /> for more details.</simpara>\r
187 </listitem>\r
188 </varlistentry>\r
189 <varlistentry>\r
190 <term>\r
191 gc.aggressiveWindow\r
192 </term>\r
193 <listitem>\r
194 <simpara>\r
195         The window size parameter used in the delta compression\r
196         algorithm used by <emphasis>git gc --aggressive</emphasis>.  This defaults\r
197         to 250, which is a much more aggressive window size than\r
198         the default <emphasis>--window</emphasis> of 10.\r
199 </simpara>\r
200 <simpara>See the documentation for the <emphasis>--window</emphasis> option in\r
201 <xref linkend="git-repack(1)" /> for more details.</simpara>\r
202 </listitem>\r
203 </varlistentry>\r
204 <varlistentry>\r
205 <term>\r
206 gc.auto\r
207 </term>\r
208 <listitem>\r
209 <simpara>\r
210         When there are approximately more than this many loose\r
211         objects in the repository, <emphasis>git gc --auto</emphasis> will pack them.\r
212         Some Porcelain commands use this command to perform a\r
213         light-weight garbage collection from time to time.  The\r
214         default value is 6700.\r
215 </simpara>\r
216 <simpara>Setting this to 0 disables not only automatic packing based on the\r
217 number of loose objects, but any other heuristic <emphasis>git gc --auto</emphasis> will\r
218 otherwise use to determine if there's work to do, such as\r
219 <emphasis>gc.autoPackLimit</emphasis>.</simpara>\r
220 </listitem>\r
221 </varlistentry>\r
222 <varlistentry>\r
223 <term>\r
224 gc.autoPackLimit\r
225 </term>\r
226 <listitem>\r
227 <simpara>\r
228         When there are more than this many packs that are not\r
229         marked with <emphasis>*.keep</emphasis> file in the repository, <emphasis>git gc\r
230         --auto</emphasis> consolidates them into one larger pack.  The\r
231         default value is 50.  Setting this to 0 disables it.\r
232         Setting <emphasis>gc.auto</emphasis> to 0 will also disable this.\r
233 </simpara>\r
234 <simpara>See the <emphasis>gc.bigPackThreshold</emphasis> configuration variable below. When in\r
235 use, it'll affect how the auto pack limit works.</simpara>\r
236 </listitem>\r
237 </varlistentry>\r
238 <varlistentry>\r
239 <term>\r
240 gc.autoDetach\r
241 </term>\r
242 <listitem>\r
243 <simpara>\r
244         Make <emphasis>git gc --auto</emphasis> return immediately and run in background\r
245         if the system supports it. Default is true.\r
246 </simpara>\r
247 </listitem>\r
248 </varlistentry>\r
249 <varlistentry>\r
250 <term>\r
251 gc.bigPackThreshold\r
252 </term>\r
253 <listitem>\r
254 <simpara>\r
255         If non-zero, all non-cruft packs larger than this limit are kept\r
256         when <emphasis>git gc</emphasis> is run. This is very similar to\r
257         <emphasis>--keep-largest-pack</emphasis> except that all non-cruft packs that meet\r
258         the threshold are kept, not just the largest pack. Defaults to\r
259         zero. Common unit suffixes of <emphasis>k</emphasis>, <emphasis>m</emphasis>, or <emphasis>g</emphasis> are supported.\r
260 </simpara>\r
261 <simpara>Note that if the number of kept packs is more than gc.autoPackLimit,\r
262 this configuration variable is ignored, all packs except the base pack\r
263 will be repacked. After this the number of packs should go below\r
264 gc.autoPackLimit and gc.bigPackThreshold should be respected again.</simpara>\r
265 <simpara>If the amount of memory estimated for <emphasis>git repack</emphasis> to run smoothly is\r
266 not available and <emphasis>gc.bigPackThreshold</emphasis> is not set, the largest pack\r
267 will also be excluded (this is the equivalent of running <emphasis>git gc</emphasis> with\r
268 <emphasis>--keep-largest-pack</emphasis>).</simpara>\r
269 </listitem>\r
270 </varlistentry>\r
271 <varlistentry>\r
272 <term>\r
273 gc.writeCommitGraph\r
274 </term>\r
275 <listitem>\r
276 <simpara>\r
277         If true, then gc will rewrite the commit-graph file when\r
278         <xref linkend="git-gc(1)" /> is run. When using <emphasis>git gc --auto</emphasis>\r
279         the commit-graph will be updated if housekeeping is\r
280         required. Default is true. See <xref linkend="git-commit-graph(1)" />\r
281         for details.\r
282 </simpara>\r
283 </listitem>\r
284 </varlistentry>\r
285 <varlistentry>\r
286 <term>\r
287 gc.logExpiry\r
288 </term>\r
289 <listitem>\r
290 <simpara>\r
291         If the file gc.log exists, then <emphasis>git gc --auto</emphasis> will print\r
292         its content and exit with status zero instead of running\r
293         unless that file is more than <emphasis>gc.logExpiry</emphasis> old.  Default is\r
294         "1.day".  See <emphasis>gc.pruneExpire</emphasis> for more ways to specify its\r
295         value.\r
296 </simpara>\r
297 </listitem>\r
298 </varlistentry>\r
299 <varlistentry>\r
300 <term>\r
301 gc.packRefs\r
302 </term>\r
303 <listitem>\r
304 <simpara>\r
305         Running <emphasis>git pack-refs</emphasis> in a repository renders it\r
306         unclonable by Git versions prior to 1.5.1.2 over dumb\r
307         transports such as HTTP.  This variable determines whether\r
308         <emphasis>git gc</emphasis> runs <emphasis>git pack-refs</emphasis>. This can be set to <emphasis>notbare</emphasis>\r
309         to enable it within all non-bare repos or it can be set to a\r
310         boolean value.  The default is <emphasis>true</emphasis>.\r
311 </simpara>\r
312 </listitem>\r
313 </varlistentry>\r
314 <varlistentry>\r
315 <term>\r
316 gc.cruftPacks\r
317 </term>\r
318 <listitem>\r
319 <simpara>\r
320         Store unreachable objects in a cruft pack (see\r
321         <xref linkend="git-repack(1)" />) instead of as loose objects. The default\r
322         is <emphasis>true</emphasis>.\r
323 </simpara>\r
324 </listitem>\r
325 </varlistentry>\r
326 <varlistentry>\r
327 <term>\r
328 gc.pruneExpire\r
329 </term>\r
330 <listitem>\r
331 <simpara>\r
332         When <emphasis>git gc</emphasis> is run, it will call <emphasis>prune --expire 2.weeks.ago</emphasis>\r
333         (and <emphasis>repack --cruft --cruft-expiration 2.weeks.ago</emphasis> if using\r
334         cruft packs via <emphasis>gc.cruftPacks</emphasis> or <emphasis>--cruft</emphasis>).  Override the\r
335         grace period with this config variable.  The value "now" may be\r
336         used to disable this grace period and always prune unreachable\r
337         objects immediately, or "never" may be used to suppress pruning.\r
338         This feature helps prevent corruption when <emphasis>git gc</emphasis> runs\r
339         concurrently with another process writing to the repository; see\r
340         the "NOTES" section of <xref linkend="git-gc(1)" />.\r
341 </simpara>\r
342 </listitem>\r
343 </varlistentry>\r
344 <varlistentry>\r
345 <term>\r
346 gc.worktreePruneExpire\r
347 </term>\r
348 <listitem>\r
349 <simpara>\r
350         When <emphasis>git gc</emphasis> is run, it calls\r
351         <emphasis>git worktree prune --expire 3.months.ago</emphasis>.\r
352         This config variable can be used to set a different grace\r
353         period. The value "now" may be used to disable the grace\r
354         period and prune <emphasis>$GIT_DIR/worktrees</emphasis> immediately, or "never"\r
355         may be used to suppress pruning.\r
356 </simpara>\r
357 </listitem>\r
358 </varlistentry>\r
359 <varlistentry>\r
360 <term>\r
361 gc.reflogExpire\r
362 </term>\r
363 <term>\r
364 gc.&lt;pattern&gt;.reflogExpire\r
365 </term>\r
366 <listitem>\r
367 <simpara>\r
368         <emphasis>git reflog expire</emphasis> removes reflog entries older than\r
369         this time; defaults to 90 days. The value "now" expires all\r
370         entries immediately, and "never" suppresses expiration\r
371         altogether. With "&lt;pattern&gt;" (e.g.\r
372         "refs/stash") in the middle the setting applies only to\r
373         the refs that match the &lt;pattern&gt;.\r
374 </simpara>\r
375 </listitem>\r
376 </varlistentry>\r
377 <varlistentry>\r
378 <term>\r
379 gc.reflogExpireUnreachable\r
380 </term>\r
381 <term>\r
382 gc.&lt;pattern&gt;.reflogExpireUnreachable\r
383 </term>\r
384 <listitem>\r
385 <simpara>\r
386         <emphasis>git reflog expire</emphasis> removes reflog entries older than\r
387         this time and are not reachable from the current tip;\r
388         defaults to 30 days. The value "now" expires all entries\r
389         immediately, and "never" suppresses expiration altogether.\r
390         With "&lt;pattern&gt;" (e.g. "refs/stash")\r
391         in the middle, the setting applies only to the refs that\r
392         match the &lt;pattern&gt;.\r
393 </simpara>\r
394 <simpara>These types of entries are generally created as a result of using <emphasis>git\r
395 commit --amend</emphasis> or <emphasis>git rebase</emphasis> and are the commits prior to the amend\r
396 or rebase occurring.  Since these changes are not part of the current\r
397 project most users will want to expire them sooner, which is why the\r
398 default is more aggressive than <emphasis>gc.reflogExpire</emphasis>.</simpara>\r
399 </listitem>\r
400 </varlistentry>\r
401 <varlistentry>\r
402 <term>\r
403 gc.recentObjectsHook\r
404 </term>\r
405 <listitem>\r
406 <simpara>\r
407         When considering whether or not to remove an object (either when\r
408         generating a cruft pack or storing unreachable objects as\r
409         loose), use the shell to execute the specified command(s).\r
410         Interpret their output as object IDs which Git will consider as\r
411         "recent", regardless of their age. By treating their mtimes as\r
412         "now", any objects (and their descendants) mentioned in the\r
413         output will be kept regardless of their true age.\r
414 </simpara>\r
415 <simpara>Output must contain exactly one hex object ID per line, and nothing\r
416 else. Objects which cannot be found in the repository are ignored.\r
417 Multiple hooks are supported, but all must exit successfully, else the\r
418 operation (either generating a cruft pack or unpacking unreachable\r
419 objects) will be halted.</simpara>\r
420 </listitem>\r
421 </varlistentry>\r
422 <varlistentry>\r
423 <term>\r
424 gc.rerereResolved\r
425 </term>\r
426 <listitem>\r
427 <simpara>\r
428         Records of conflicted merge you resolved earlier are\r
429         kept for this many days when <emphasis>git rerere gc</emphasis> is run.\r
430         You can also use more human-readable "1.month.ago", etc.\r
431         The default is 60 days.  See <xref linkend="git-rerere(1)" />.\r
432 </simpara>\r
433 </listitem>\r
434 </varlistentry>\r
435 <varlistentry>\r
436 <term>\r
437 gc.rerereUnresolved\r
438 </term>\r
439 <listitem>\r
440 <simpara>\r
441         Records of conflicted merge you have not resolved are\r
442         kept for this many days when <emphasis>git rerere gc</emphasis> is run.\r
443         You can also use more human-readable "1.month.ago", etc.\r
444         The default is 15 days.  See <xref linkend="git-rerere(1)" />.\r
445 </simpara>\r
446 </listitem>\r
447 </varlistentry>\r
448 </variablelist>\r
449 </simplesect>\r
450 <simplesect id="git-gc(1)__notes">\r
451 <title>NOTES</title>\r
452 <simpara><emphasis>git gc</emphasis> tries very hard not to delete objects that are referenced\r
453 anywhere in your repository. In particular, it will keep not only\r
454 objects referenced by your current set of branches and tags, but also\r
455 objects referenced by the index, remote-tracking branches, reflogs\r
456 (which may reference commits in branches that were later amended or\r
457 rewound), and anything else in the refs/* namespace. Note that a note\r
458 (of the kind created by <emphasis>git notes</emphasis>) attached to an object does not\r
459 contribute in keeping the object alive. If you are expecting some\r
460 objects to be deleted and they aren't, check all of those locations\r
461 and decide whether it makes sense in your case to remove those\r
462 references.</simpara>\r
463 <simpara>On the other hand, when <emphasis>git gc</emphasis> runs concurrently with another process,\r
464 there is a risk of it deleting an object that the other process is using\r
465 but hasn't created a reference to. This may just cause the other process\r
466 to fail or may corrupt the repository if the other process later adds a\r
467 reference to the deleted object. Git has two features that significantly\r
468 mitigate this problem:</simpara>\r
469 <orderedlist numeration="arabic">\r
470 <listitem>\r
471 <simpara>\r
472 Any object with modification time newer than the <emphasis>--prune</emphasis> date is kept,\r
473   along with everything reachable from it.\r
474 </simpara>\r
475 </listitem>\r
476 <listitem>\r
477 <simpara>\r
478 Most operations that add an object to the database update the\r
479   modification time of the object if it is already present so that #1\r
480   applies.\r
481 </simpara>\r
482 </listitem>\r
483 </orderedlist>\r
484 <simpara>However, these features fall short of a complete solution, so users who\r
485 run commands concurrently have to live with some risk of corruption (which\r
486 seems to be low in practice).</simpara>\r
487 </simplesect>\r
488 <simplesect id="git-gc(1)__hooks">\r
489 <title>HOOKS</title>\r
490 <simpara>The <emphasis>git gc --auto</emphasis> command will run the <emphasis>pre-auto-gc</emphasis> hook.  See\r
491 <xref linkend="githooks(5)" /> for more information.</simpara>\r
492 </simplesect>\r
493 <simplesect id="git-gc(1)__see_also">\r
494 <title>SEE ALSO</title>\r
495 <simpara><xref linkend="git-prune(1)" />\r
496 <xref linkend="git-reflog(1)" />\r
497 <xref linkend="git-repack(1)" />\r
498 <xref linkend="git-rerere(1)" /></simpara>\r
499 </simplesect>\r
500 <simplesect id="git-gc(1)__git">\r
501 <title>GIT</title>\r
502 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
503 </simplesect>\r
504 </sect2>\r