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