interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-gc.adoc

191 lines · 6831 bytes Raw Blame History
1git-gc(1)
2=========
3
4NAME
5----
6git-gc - Cleanup unnecessary files and optimize the local repository
7
8
9SYNOPSIS
10--------
11[verse]
12'git gc' [--aggressive] [--auto] [--[no-]detach] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]
13
14DESCRIPTION
15-----------
16Runs a number of housekeeping tasks within the current repository,
17such as compressing file revisions (to reduce disk space and increase
18performance), removing unreachable objects which may have been
19created from prior invocations of 'git add', packing refs, pruning
20reflog, rerere metadata or stale working trees. May also update ancillary
21indexes such as the commit-graph.
22
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.
33
34OPTIONS
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 <<AGGRESSIVE,"AGGRESSIVE">>
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+
49See the `gc.auto` option in the <<CONFIGURATION,"CONFIGURATION">>
50section below for how this heuristic works.
51+
52Once housekeeping is triggered by exceeding the limits of
53configuration options such as `gc.auto` and `gc.autoPackLimit`, all
54other housekeeping tasks (e.g. rerere, working trees, reflog...) will
55be 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=<n>::
69 When packing unreachable objects into a cruft pack, limit the
70 size of new cruft packs to be at most `<n>` 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=<dir>::
76 When packing unreachable objects into a cruft pack, write a cruft
77 pack containing pruned objects (if any) to the directory `<dir>`.
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=<date>::
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 <<NOTES,"NOTES">> 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]]
107AGGRESSIVE
108----------
109
110When the `--aggressive` option is supplied, linkgit:git-repack[1] will
111be invoked with the `-f` flag, which in turn will pass
112`--no-reuse-delta` to linkgit:git-pack-objects[1]. This will throw
113away any existing deltas and re-compute them, at the expense of
114spending much more time on the repacking.
115
116The effects of this are mostly persistent, e.g. when packs and loose
117objects are coalesced into one another pack the existing deltas in
118that pack might get re-used, but there are also various cases where we
119might pick a sub-optimal delta from a newer pack instead.
120
121Furthermore, 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
124using a larger window size we're more likely to find more optimal
125deltas.
126
127It's probably not worth it to use this option on a given repository
128without running tailored performance benchmarks on it. It takes a lot
129more time, and the resulting space/delta optimization may or may not
130be worth it. Not using this at all is the right trade-off for most
131users and their repositories.
132
133[[CONFIGURATION]]
134CONFIGURATION
135-------------
136
137include::includes/cmd-config-section-all.adoc[]
138
139include::config/gc.adoc[]
140
141[[NOTES]]
142NOTES
143-----
144
145'git gc' tries very hard not to delete objects that are referenced
146anywhere in your repository. In particular, it will keep not only
147objects referenced by your current set of branches and tags, but also
148objects referenced by the index, remote-tracking branches, reflogs
149(which may reference commits in branches that were later amended or
150rewound), 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
152contribute in keeping the object alive. If you are expecting some
153objects to be deleted and they aren't, check all of those locations
154and decide whether it makes sense in your case to remove those
155references.
156
157On the other hand, when 'git gc' runs concurrently with another process,
158there is a risk of it deleting an object that the other process is using
159but hasn't created a reference to. This may just cause the other process
160to fail or may corrupt the repository if the other process later adds a
161reference to the deleted object. Git has two features that significantly
162mitigate 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
171However, these features fall short of a complete solution, so users who
172run commands concurrently have to live with some risk of corruption (which
173seems to be low in practice).
174
175HOOKS
176-----
177
178The 'git gc --auto' command will run the 'pre-auto-gc' hook. See
179linkgit:githooks[5] for more information.
180
181
182SEE ALSO
183--------
184linkgit:git-prune[1]
185linkgit:git-reflog[1]
186linkgit:git-repack[1]
187linkgit:git-rerere[1]
188
189GIT
190---
191Part of the linkgit:git[1] suite