Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-gc.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-gc.adoc` 191 lines ยท 6831 bytes Raw Blame History 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 -------- 11 [verse] 12 'git gc' [--aggressive] [--auto] [--[no-]detach] [--quiet] [--prune= | --no-prune] [--force] [--keep-largest-pack] 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 18 performance), removing unreachable objects which may have been 19 created from prior invocations of 'git add', packing refs, pruning 20 reflog, rerere metadata or stale working trees. May also update ancillary 21 indexes such as the commit-graph. 22 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. 33 34 OPTIONS 35 ------- 36 37 --aggressive:: 38 Usually 'git gc' runs very quickly while providing good disk 39 space utilization and performance. This option will cause 40 'git gc' to more aggressively optimize the repository at the expense 41 of taking much more time. The effects of this optimization are 42 mostly persistent. See the <> 43 section below for details. 44 45 --auto:: 46 With this option, 'git gc' checks whether any housekeeping is 47 required; if not, it exits without performing any work. 48 + 49 See the `gc.auto` option in the <> 50 section below for how this heuristic works. 51 + 52 Once housekeeping is triggered by exceeding the limits of 53 configuration options such as `gc.auto` and `gc.autoPackLimit`, all 54 other housekeeping tasks (e.g. rerere, working trees, reflog...) will 55 be performed as well. 56 57 --detach:: 58 --no-detach:: 59 Run in the background if the system supports it. This option overrides 60 the `gc.autoDetach` config. 61 62 --cruft:: 63 --no-cruft:: 64 When expiring unreachable objects, pack them separately into a 65 cruft pack instead of storing them as loose objects. `--cruft` 66 is on by default. 67 68 --max-cruft-size=:: 69 When packing unreachable objects into a cruft pack, limit the 70 size of new cruft packs to be at most `` bytes. Overrides any 71 value specified via the `gc.maxCruftSize` configuration. See 72 the `--max-cruft-size` option of linkgit:git-repack[1] for 73 more. 74 75 --expire-to=:: 76 When packing unreachable objects into a cruft pack, write a cruft 77 pack containing pruned objects (if any) to the directory ``. 78 This option only has an effect when used together with `--cruft`. 79 See the `--expire-to` option of linkgit:git-repack[1] for 80 more information. 81 82 --prune=:: 83 Prune loose objects older than date (default is 2 weeks ago, 84 overridable by the config variable `gc.pruneExpire`). 85 --prune=now prunes loose objects regardless of their age and 86 increases the risk of corruption if another process is writing to 87 the repository concurrently; see <> below. --prune is on by 88 default. 89 90 --no-prune:: 91 Do not prune any loose objects. 92 93 --quiet:: 94 Suppress all progress reports. 95 96 --force:: 97 Force `git gc` to run even if there may be another `git gc` 98 instance running on this repository. 99 100 --keep-largest-pack:: 101 All packs except the largest non-cruft pack, any packs marked 102 with a `.keep` file, and any cruft pack(s) are consolidated into 103 a single pack. When this option is used, `gc.bigPackThreshold` 104 is ignored. 105 106 [[AGGRESSIVE]] 107 AGGRESSIVE 108 ---------- 109 110 When the `--aggressive` option is supplied, linkgit:git-repack[1] will 111 be invoked with the `-f` flag, which in turn will pass 112 `--no-reuse-delta` to linkgit:git-pack-objects[1]. This will throw 113 away any existing deltas and re-compute them, at the expense of 114 spending much more time on the repacking. 115 116 The effects of this are mostly persistent, e.g. when packs and loose 117 objects are coalesced into one another pack the existing deltas in 118 that pack might get re-used, but there are also various cases where we 119 might pick a sub-optimal delta from a newer pack instead. 120 121 Furthermore, supplying `--aggressive` will tweak the `--depth` and 122 `--window` options passed to linkgit:git-repack[1]. See the 123 `gc.aggressiveDepth` and `gc.aggressiveWindow` settings below. By 124 using a larger window size we're more likely to find more optimal 125 deltas. 126 127 It's probably not worth it to use this option on a given repository 128 without running tailored performance benchmarks on it. It takes a lot 129 more time, and the resulting space/delta optimization may or may not 130 be worth it. Not using this at all is the right trade-off for most 131 users and their repositories. 132 133 [[CONFIGURATION]] 134 CONFIGURATION 135 ------------- 136 137 include::includes/cmd-config-section-all.adoc[] 138 139 include::config/gc.adoc[] 140 141 [[NOTES]] 142 NOTES 143 ----- 144 145 'git gc' tries very hard not to delete objects that are referenced 146 anywhere in your repository. In particular, it will keep not only 147 objects referenced by your current set of branches and tags, but also 148 objects referenced by the index, remote-tracking branches, reflogs 149 (which may reference commits in branches that were later amended or 150 rewound), and anything else in the refs/* namespace. Note that a note 151 (of the kind created by 'git notes') attached to an object does not 152 contribute in keeping the object alive. If you are expecting some 153 objects to be deleted and they aren't, check all of those locations 154 and decide whether it makes sense in your case to remove those 155 references. 156 157 On the other hand, when 'git gc' runs concurrently with another process, 158 there is a risk of it deleting an object that the other process is using 159 but hasn't created a reference to. This may just cause the other process 160 to fail or may corrupt the repository if the other process later adds a 161 reference to the deleted object. Git has two features that significantly 162 mitigate this problem: 163 164 . Any object with modification time newer than the `--prune` date is kept, 165 along with everything reachable from it. 166 167 . Most operations that add an object to the database update the 168 modification time of the object if it is already present so that #1 169 applies. 170 171 However, these features fall short of a complete solution, so users who 172 run commands concurrently have to live with some risk of corruption (which 173 seems to be low in practice). 174 175 HOOKS 176 ----- 177 178 The 'git gc --auto' command will run the 'pre-auto-gc' hook. See 179 linkgit:githooks[5] for more information. 180 181 182 SEE ALSO 183 -------- 184 linkgit:git-prune[1] 185 linkgit:git-reflog[1] 186 linkgit:git-repack[1] 187 linkgit:git-rerere[1] 188 189 GIT 190 --- 191 Part of the linkgit:git[1] suite