]> git.ipfire.org Git - thirdparty/git.git/blob - Documentation/git-gc.txt
gc docs: include the "gc.*" section from "config" in "gc"
[thirdparty/git.git] / Documentation / git-gc.txt
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] [--quiet] [--prune=<date> | --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 persistent, so this option only needs to be used occasionally; every
43 few hundred changesets or so.
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 "CONFIGURATION" section below for how
50 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
58 --prune=<date>::
59 Prune loose objects older than date (default is 2 weeks ago,
60 overridable by the config variable `gc.pruneExpire`).
61 --prune=now prunes loose objects regardless of their age and
62 increases the risk of corruption if another process is writing to
63 the repository concurrently; see "NOTES" below. --prune is on by
64 default.
65
66 --no-prune::
67 Do not prune any loose objects.
68
69 --quiet::
70 Suppress all progress reports.
71
72 --force::
73 Force `git gc` to run even if there may be another `git gc`
74 instance running on this repository.
75
76 --keep-largest-pack::
77 All packs except the largest pack and those marked with a
78 `.keep` files are consolidated into a single pack. When this
79 option is used, `gc.bigPackThreshold` is ignored.
80
81 CONFIGURATION
82 -------------
83
84 The below documentation is the same as what's found in
85 linkgit:git-config[1]:
86
87 include::config/gc.txt[]
88
89 NOTES
90 -----
91
92 'git gc' tries very hard not to delete objects that are referenced
93 anywhere in your repository. In
94 particular, it will keep not only objects referenced by your current set
95 of branches and tags, but also objects referenced by the index,
96 remote-tracking branches, refs saved by 'git filter-branch' in
97 refs/original/, or reflogs (which may reference commits in branches
98 that were later amended or rewound).
99 If you are expecting some objects to be deleted and they aren't, check
100 all of those locations and decide whether it makes sense in your case to
101 remove those references.
102
103 On the other hand, when 'git gc' runs concurrently with another process,
104 there is a risk of it deleting an object that the other process is using
105 but hasn't created a reference to. This may just cause the other process
106 to fail or may corrupt the repository if the other process later adds a
107 reference to the deleted object. Git has two features that significantly
108 mitigate this problem:
109
110 . Any object with modification time newer than the `--prune` date is kept,
111 along with everything reachable from it.
112
113 . Most operations that add an object to the database update the
114 modification time of the object if it is already present so that #1
115 applies.
116
117 However, these features fall short of a complete solution, so users who
118 run commands concurrently have to live with some risk of corruption (which
119 seems to be low in practice) unless they turn off automatic garbage
120 collection with 'git config gc.auto 0'.
121
122 HOOKS
123 -----
124
125 The 'git gc --auto' command will run the 'pre-auto-gc' hook. See
126 linkgit:githooks[5] for more information.
127
128
129 SEE ALSO
130 --------
131 linkgit:git-prune[1]
132 linkgit:git-reflog[1]
133 linkgit:git-repack[1]
134 linkgit:git-rerere[1]
135
136 GIT
137 ---
138 Part of the linkgit:git[1] suite