Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 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 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 12 | 'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack] |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 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 |
Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 18 | performance), removing unreachable objects which may have been |
| 19 | created from prior invocations of 'git add', packing refs, pruning |
Junio C Hamano | a4df8ed | 2018-10-26 06:37:13 | [diff] [blame] | 20 | reflog, rerere metadata or stale working trees. May also update ancillary |
| 21 | indexes such as the commit-graph. |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 22 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 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. |
Junio C Hamano | d04b60c | 2008-03-20 08:46:04 | [diff] [blame] | 27 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 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. |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 33 | |
Junio C Hamano | f65d928 | 2007-01-22 09:00:13 | [diff] [blame] | 34 | OPTIONS |
| 35 | ------- |
| 36 | |
Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 37 | --aggressive:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 38 | Usually 'git gc' runs very quickly while providing good disk |
Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 39 | space utilization and performance. This option will cause |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 40 | 'git gc' to more aggressively optimize the repository at the expense |
Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 41 | of taking much more time. The effects of this optimization are |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 42 | mostly persistent. See the "AGGRESSIVE" section below for details. |
Junio C Hamano | f65d928 | 2007-01-22 09:00:13 | [diff] [blame] | 43 | |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 44 | --auto:: |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 45 | With this option, 'git gc' checks whether any housekeeping is |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 46 | required; if not, it exits without performing any work. |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 47 | + |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 48 | See the `gc.auto` option in the "CONFIGURATION" section below for how |
| 49 | this heuristic works. |
Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 50 | + |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 51 | Once housekeeping is triggered by exceeding the limits of |
| 52 | configuration options such as `gc.auto` and `gc.autoPackLimit`, all |
Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 53 | other housekeeping tasks (e.g. rerere, working trees, reflog...) will |
| 54 | be performed as well. |
| 55 | |
Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 56 | |
Junio C Hamano | 8bc410e | 2009-02-15 10:38:19 | [diff] [blame] | 57 | --prune=<date>:: |
| 58 | Prune loose objects older than date (default is 2 weeks ago, |
Junio C Hamano | c710296 | 2013-05-29 23:57:17 | [diff] [blame] | 59 | overridable by the config variable `gc.pruneExpire`). |
Junio C Hamano | decc731 | 2019-03-11 09:02:54 | [diff] [blame] | 60 | --prune=now prunes loose objects regardless of their age and |
Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 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. |
Junio C Hamano | 8bc410e | 2009-02-15 10:38:19 | [diff] [blame] | 64 | |
| 65 | --no-prune:: |
| 66 | Do not prune any loose objects. |
| 67 | |
Junio C Hamano | 69a9858 | 2008-03-01 18:42:18 | [diff] [blame] | 68 | --quiet:: |
| 69 | Suppress all progress reports. |
| 70 | |
Junio C Hamano | 535ed7a | 2013-09-04 20:35:57 | [diff] [blame] | 71 | --force:: |
| 72 | Force `git gc` to run even if there may be another `git gc` |
| 73 | instance running on this repository. |
| 74 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 75 | --keep-largest-pack:: |
| 76 | All packs except the largest pack and those marked with a |
| 77 | `.keep` files are consolidated into a single pack. When this |
| 78 | option is used, `gc.bigPackThreshold` is ignored. |
| 79 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 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 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 106 | CONFIGURATION |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 107 | ------------- |
| 108 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 109 | The below documentation is the same as what's found in |
| 110 | linkgit:git-config[1]: |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 111 | |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 112 | include::config/gc.txt[] |
Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 113 | |
Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 114 | NOTES |
Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 115 | ----- |
| 116 | |
Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 117 | 'git gc' tries very hard not to delete objects that are referenced |
Junio C Hamano | a885831 | 2019-09-30 05:07:45 | [diff] [blame] | 118 | anywhere in your repository. In particular, it will keep not only |
| 119 | objects referenced by your current set of branches and tags, but also |
Junio C Hamano | a372d5b | 2021-02-26 01:34:37 | [diff] [blame] | 120 | objects referenced by the index, remote-tracking branches, reflogs |
| 121 | (which may reference commits in branches that were later amended or |
| 122 | rewound), 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 |
| 124 | contribute in keeping the object alive. If you are expecting some |
| 125 | objects to be deleted and they aren't, check all of those locations |
| 126 | and decide whether it makes sense in your case to remove those |
| 127 | references. |
Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 128 | |
Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 129 | On the other hand, when 'git gc' runs concurrently with another process, |
| 130 | there is a risk of it deleting an object that the other process is using |
| 131 | but hasn't created a reference to. This may just cause the other process |
| 132 | to fail or may corrupt the repository if the other process later adds a |
| 133 | reference to the deleted object. Git has two features that significantly |
| 134 | mitigate 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 | |
| 143 | However, these features fall short of a complete solution, so users who |
| 144 | run commands concurrently have to live with some risk of corruption (which |
Junio C Hamano | 2ba1471 | 2019-04-25 10:12:27 | [diff] [blame] | 145 | seems to be low in practice). |
Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 146 | |
Junio C Hamano | 3e3aa81 | 2010-07-05 23:25:23 | [diff] [blame] | 147 | HOOKS |
| 148 | ----- |
| 149 | |
| 150 | The 'git gc --auto' command will run the 'pre-auto-gc' hook. See |
| 151 | linkgit:githooks[5] for more information. |
| 152 | |
| 153 | |
Junio C Hamano | 9049d91 | 2008-05-29 02:09:50 | [diff] [blame] | 154 | SEE ALSO |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 155 | -------- |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 156 | linkgit:git-prune[1] |
| 157 | linkgit:git-reflog[1] |
| 158 | linkgit:git-repack[1] |
| 159 | linkgit:git-rerere[1] |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 160 | |
Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 161 | GIT |
| 162 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 163 | Part of the linkgit:git[1] suite |