]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-gc.txt
builtin/gc.c: make `gc.cruftPacks` enabled by default
[thirdparty/git.git] / Documentation / git-gc.txt
CommitLineData
30f610b7
SP
1git-gc(1)
2=========
3
4NAME
5----
6git-gc - Cleanup unnecessary files and optimize the local repository
7
8
9SYNOPSIS
10--------
7791a1d9 11[verse]
ae4e89e5 12'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
30f610b7
SP
13
14DESCRIPTION
15-----------
16Runs a number of housekeeping tasks within the current repository,
17such as compressing file revisions (to reduce disk space and increase
b586a96a
NTND
18performance), removing unreachable objects which may have been
19created from prior invocations of 'git add', packing refs, pruning
c7e8ce6d
ÆAB
20reflog, rerere metadata or stale working trees. May also update ancillary
21indexes such as the commit-graph.
30f610b7 22
b11e8560
ÆAB
23When common porcelain operations that create objects are run, they
24will check whether the repository has grown substantially since the
25last maintenance, and if so run `git gc` automatically. See `gc.auto`
26below for how to disable this behavior.
27
28Running `git gc` manually should only be needed when adding objects to
29a repository without regularly running such porcelain commands, to do
30a one-off repository optimization, or e.g. to clean up a suboptimal
31mass-import. See the "PACKFILE OPTIMIZATION" section in
32linkgit:git-fast-import[1] for more details on the import case.
30f610b7 33
e3ff4b24
JH
34OPTIONS
35-------
36
0d7566a5 37--aggressive::
0b444cdb 38 Usually 'git gc' runs very quickly while providing good disk
5049012f 39 space utilization and performance. This option will cause
0b444cdb 40 'git gc' to more aggressively optimize the repository at the expense
0d7566a5 41 of taking much more time. The effects of this optimization are
22d4e3bd 42 mostly persistent. See the "AGGRESSIVE" section below for details.
e9831e83
JH
43
44--auto::
0b444cdb 45 With this option, 'git gc' checks whether any housekeeping is
d7e56dbc 46 required; if not, it exits without performing any work.
d7e56dbc 47+
b6a8d09f
ÆAB
48See the `gc.auto` option in the "CONFIGURATION" section below for how
49this heuristic works.
d7e56dbc 50+
b6a8d09f
ÆAB
51Once housekeeping is triggered by exceeding the limits of
52configuration options such as `gc.auto` and `gc.autoPackLimit`, all
b586a96a
NTND
53other housekeeping tasks (e.g. rerere, working trees, reflog...) will
54be performed as well.
55
e3ff4b24 56
e3e24de1 57--[no-]cruft::
5b92477f 58 When expiring unreachable objects, pack them separately into a
e3e24de1
TB
59 cruft pack instead of storing them as loose objects. `--cruft`
60 is on by default.
5b92477f 61
58e9d9d4
JS
62--prune=<date>::
63 Prune loose objects older than date (default is 2 weeks ago,
61929404 64 overridable by the config variable `gc.pruneExpire`).
716a5af8 65 --prune=now prunes loose objects regardless of their age and
f1350d0c
MM
66 increases the risk of corruption if another process is writing to
67 the repository concurrently; see "NOTES" below. --prune is on by
68 default.
58e9d9d4
JS
69
70--no-prune::
71 Do not prune any loose objects.
72
a0c14cbb
FL
73--quiet::
74 Suppress all progress reports.
75
64a99eb4
NTND
76--force::
77 Force `git gc` to run even if there may be another `git gc`
78 instance running on this repository.
79
ae4e89e5 80--keep-largest-pack::
05b9013b
TB
81 All packs except the largest non-cruft pack, any packs marked
82 with a `.keep` file, and any cruft pack(s) are consolidated into
83 a single pack. When this option is used, `gc.bigPackThreshold`
84 is ignored.
ae4e89e5 85
22d4e3bd
ÆAB
86AGGRESSIVE
87----------
88
89When the `--aggressive` option is supplied, linkgit:git-repack[1] will
90be invoked with the `-f` flag, which in turn will pass
91`--no-reuse-delta` to linkgit:git-pack-objects[1]. This will throw
92away any existing deltas and re-compute them, at the expense of
93spending much more time on the repacking.
94
95The effects of this are mostly persistent, e.g. when packs and loose
96objects are coalesced into one another pack the existing deltas in
97that pack might get re-used, but there are also various cases where we
98might pick a sub-optimal delta from a newer pack instead.
99
100Furthermore, supplying `--aggressive` will tweak the `--depth` and
101`--window` options passed to linkgit:git-repack[1]. See the
102`gc.aggressiveDepth` and `gc.aggressiveWindow` settings below. By
103using a larger window size we're more likely to find more optimal
104deltas.
105
106It's probably not worth it to use this option on a given repository
107without running tailored performance benchmarks on it. It takes a lot
108more time, and the resulting space/delta optimization may or may not
109be worth it. Not using this at all is the right trade-off for most
110users and their repositories.
111
76a8788c 112CONFIGURATION
30f610b7
SP
113-------------
114
18d89fe2 115include::includes/cmd-config-section-all.txt[]
b586a96a 116
b6a8d09f 117include::config/gc.txt[]
3ffb58be 118
76a8788c 119NOTES
3ffb58be
JK
120-----
121
f1350d0c 122'git gc' tries very hard not to delete objects that are referenced
9df53c5d
EN
123anywhere in your repository. In particular, it will keep not only
124objects referenced by your current set of branches and tags, but also
fa9ab027
MZ
125objects referenced by the index, remote-tracking branches, reflogs
126(which may reference commits in branches that were later amended or
127rewound), and anything else in the refs/* namespace. Note that a note
128(of the kind created by 'git notes') attached to an object does not
129contribute in keeping the object alive. If you are expecting some
130objects to be deleted and they aren't, check all of those locations
131and decide whether it makes sense in your case to remove those
132references.
3ffb58be 133
f1350d0c
MM
134On the other hand, when 'git gc' runs concurrently with another process,
135there is a risk of it deleting an object that the other process is using
136but hasn't created a reference to. This may just cause the other process
137to fail or may corrupt the repository if the other process later adds a
138reference to the deleted object. Git has two features that significantly
139mitigate this problem:
140
141. Any object with modification time newer than the `--prune` date is kept,
142 along with everything reachable from it.
143
144. Most operations that add an object to the database update the
145 modification time of the object if it is already present so that #1
146 applies.
147
148However, these features fall short of a complete solution, so users who
149run commands concurrently have to live with some risk of corruption (which
0044f770 150seems to be low in practice).
f1350d0c 151
66bd8ab8
CP
152HOOKS
153-----
154
155The 'git gc --auto' command will run the 'pre-auto-gc' hook. See
156linkgit:githooks[5] for more information.
157
158
56ae8df5 159SEE ALSO
30f610b7 160--------
5162e697
DM
161linkgit:git-prune[1]
162linkgit:git-reflog[1]
163linkgit:git-repack[1]
164linkgit:git-rerere[1]
30f610b7 165
30f610b7
SP
166GIT
167---
9e1f0a85 168Part of the linkgit:git[1] suite