blob: 853967dea01d0778e8d1d484afa9098ab4532ffc [file] [log] [blame]
Junio C Hamano52299462006-12-28 00:59:381git-gc(1)
2=========
3
4NAME
5----
6git-gc - Cleanup unnecessary files and optimize the local repository
7
8
9SYNOPSIS
10--------
Junio C Hamano15567bc2011-07-23 00:51:5911[verse]
Junio C Hamanob9d9d902018-05-23 07:07:4212'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
Junio C Hamano52299462006-12-28 00:59:3813
14DESCRIPTION
15-----------
16Runs a number of housekeeping tasks within the current repository,
17such as compressing file revisions (to reduce disk space and increase
Junio C Hamano85151f32018-04-10 00:52:2618performance), removing unreachable objects which may have been
19created from prior invocations of 'git add', packing refs, pruning
Junio C Hamanoa4df8ed2018-10-26 06:37:1320reflog, rerere metadata or stale working trees. May also update ancillary
21indexes such as the commit-graph.
Junio C Hamano52299462006-12-28 00:59:3822
Junio C Hamano2ba14712019-04-25 10:12:2723When 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.
Junio C Hamanod04b60c2008-03-20 08:46:0427
Junio C Hamano2ba14712019-04-25 10:12:2728Running `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.
Junio C Hamano52299462006-12-28 00:59:3833
Junio C Hamanof65d9282007-01-22 09:00:1334OPTIONS
35-------
36
Junio C Hamanof2ce2972007-05-20 19:12:0937--aggressive::
Junio C Hamano1aa40d22010-01-21 17:46:4338Usually 'git gc' runs very quickly while providing good disk
Junio C Hamano679d22d2007-06-02 21:13:4439space utilization and performance. This option will cause
Junio C Hamano1aa40d22010-01-21 17:46:4340'git gc' to more aggressively optimize the repository at the expense
Junio C Hamanof2ce2972007-05-20 19:12:0941of taking much more time. The effects of this optimization are
Junio C Hamano2ba14712019-04-25 10:12:2742mostly persistent. See the "AGGRESSIVE" section below for details.
Junio C Hamanof65d9282007-01-22 09:00:1343
Junio C Hamano1b50ce92007-10-03 12:05:5344--auto::
Junio C Hamano1aa40d22010-01-21 17:46:4345With this option, 'git gc' checks whether any housekeeping is
Junio C Hamano764a6672007-10-23 01:23:3146required; if not, it exits without performing any work.
Junio C Hamano764a6672007-10-23 01:23:3147+
Junio C Hamano2ba14712019-04-25 10:12:2748See the `gc.auto` option in the "CONFIGURATION" section below for how
49this heuristic works.
Junio C Hamano764a6672007-10-23 01:23:3150+
Junio C Hamano2ba14712019-04-25 10:12:2751Once housekeeping is triggered by exceeding the limits of
52configuration options such as `gc.auto` and `gc.autoPackLimit`, all
Junio C Hamano85151f32018-04-10 00:52:2653other housekeeping tasks (e.g. rerere, working trees, reflog...) will
54be performed as well.
55
Junio C Hamano1b50ce92007-10-03 12:05:5356
Junio C Hamano8bc410e2009-02-15 10:38:1957--prune=<date>::
58Prune loose objects older than date (default is 2 weeks ago,
Junio C Hamanoc7102962013-05-29 23:57:1759overridable by the config variable `gc.pruneExpire`).
Junio C Hamanodecc7312019-03-11 09:02:5460--prune=now prunes loose objects regardless of their age and
Junio C Hamano56ace3d2017-01-10 23:43:4161increases the risk of corruption if another process is writing to
62the repository concurrently; see "NOTES" below. --prune is on by
63default.
Junio C Hamano8bc410e2009-02-15 10:38:1964
65--no-prune::
66Do not prune any loose objects.
67
Junio C Hamano69a98582008-03-01 18:42:1868--quiet::
69Suppress all progress reports.
70
Junio C Hamano535ed7a2013-09-04 20:35:5771--force::
72Force `git gc` to run even if there may be another `git gc`
73instance running on this repository.
74
Junio C Hamanob9d9d902018-05-23 07:07:4275--keep-largest-pack::
76All packs except the largest pack and those marked with a
77`.keep` files are consolidated into a single pack. When this
78option is used, `gc.bigPackThreshold` is ignored.
79
Junio C Hamano2ba14712019-04-25 10:12:2780AGGRESSIVE
81----------
82
83When the `--aggressive` option is supplied, linkgit:git-repack[1] will
84be invoked with the `-f` flag, which in turn will pass
85`--no-reuse-delta` to linkgit:git-pack-objects[1]. This will throw
86away any existing deltas and re-compute them, at the expense of
87spending much more time on the repacking.
88
89The effects of this are mostly persistent, e.g. when packs and loose
90objects are coalesced into one another pack the existing deltas in
91that pack might get re-used, but there are also various cases where we
92might pick a sub-optimal delta from a newer pack instead.
93
94Furthermore, 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
97using a larger window size we're more likely to find more optimal
98deltas.
99
100It's probably not worth it to use this option on a given repository
101without running tailored performance benchmarks on it. It takes a lot
102more time, and the resulting space/delta optimization may or may not
103be worth it. Not using this at all is the right trade-off for most
104users and their repositories.
105
Junio C Hamanob9d9d902018-05-23 07:07:42106CONFIGURATION
Junio C Hamano52299462006-12-28 00:59:38107-------------
108
Junio C Hamano2ba14712019-04-25 10:12:27109The below documentation is the same as what's found in
110linkgit:git-config[1]:
Junio C Hamano52299462006-12-28 00:59:38111
Junio C Hamano2ba14712019-04-25 10:12:27112include::config/gc.txt[]
Junio C Hamano2f102bb2008-04-26 02:23:37113
Junio C Hamanob9d9d902018-05-23 07:07:42114NOTES
Junio C Hamano2f102bb2008-04-26 02:23:37115-----
116
Junio C Hamano56ace3d2017-01-10 23:43:41117'git gc' tries very hard not to delete objects that are referenced
Junio C Hamanoa8858312019-09-30 05:07:45118anywhere in your repository. In particular, it will keep not only
119objects referenced by your current set of branches and tags, but also
Junio C Hamanoa372d5b2021-02-26 01:34:37120objects referenced by the index, remote-tracking branches, reflogs
121(which may reference commits in branches that were later amended or
122rewound), and anything else in the refs/* namespace. Note that a note
123(of the kind created by 'git notes') attached to an object does not
124contribute in keeping the object alive. If you are expecting some
125objects to be deleted and they aren't, check all of those locations
126and decide whether it makes sense in your case to remove those
127references.
Junio C Hamano2f102bb2008-04-26 02:23:37128
Junio C Hamano56ace3d2017-01-10 23:43:41129On the other hand, when 'git gc' runs concurrently with another process,
130there is a risk of it deleting an object that the other process is using
131but hasn't created a reference to. This may just cause the other process
132to fail or may corrupt the repository if the other process later adds a
133reference to the deleted object. Git has two features that significantly
134mitigate this problem:
135
136. Any object with modification time newer than the `--prune` date is kept,
137 along with everything reachable from it.
138
139. Most operations that add an object to the database update the
140 modification time of the object if it is already present so that #1
141 applies.
142
143However, these features fall short of a complete solution, so users who
144run commands concurrently have to live with some risk of corruption (which
Junio C Hamano2ba14712019-04-25 10:12:27145seems to be low in practice).
Junio C Hamano56ace3d2017-01-10 23:43:41146
Junio C Hamano3e3aa812010-07-05 23:25:23147HOOKS
148-----
149
150The 'git gc --auto' command will run the 'pre-auto-gc' hook. See
151linkgit:githooks[5] for more information.
152
153
Junio C Hamano9049d912008-05-29 02:09:50154SEE ALSO
Junio C Hamano52299462006-12-28 00:59:38155--------
Junio C Hamano35738e82008-01-07 07:55:46156linkgit:git-prune[1]
157linkgit:git-reflog[1]
158linkgit:git-repack[1]
159linkgit:git-rerere[1]
Junio C Hamano52299462006-12-28 00:59:38160
Junio C Hamano52299462006-12-28 00:59:38161GIT
162---
Junio C Hamanof7c042d2008-06-06 22:50:53163Part of the linkgit:git[1] suite