Skip to content

Commit f1350d0

Browse files
mattmccutchengitster
authored andcommitted
git-gc.txt: expand discussion of races with other processes
In general, "git gc" may delete objects that another concurrent process is using but hasn't created a reference to. Git has some mitigations, but they fall short of a complete solution. Document this in the git-gc(1) man page and add a reference from the documentation of the gc.pruneExpire config variable. Based on a write-up by Jeff King: http://marc.info/?l=git&m=147922960131779&w=2 Signed-off-by: Matt McCutchen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit f1350d0

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,9 @@ gc.pruneExpire::
13411341
Override the grace period with this config variable. The value
13421342
"now" may be used to disable this grace period and always prune
13431343
unreachable objects immediately, or "never" may be used to
1344-
suppress pruning.
1344+
suppress pruning. This feature helps prevent corruption when
1345+
'git gc' runs concurrently with another process writing to the
1346+
repository; see the "NOTES" section of linkgit:git-gc[1].
13451347

13461348
gc.worktreePruneExpire::
13471349
When 'git gc' is run, it calls

Documentation/git-gc.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ automatic consolidation of packs.
6363
--prune=<date>::
6464
Prune loose objects older than date (default is 2 weeks ago,
6565
overridable by the config variable `gc.pruneExpire`).
66-
--prune=all prunes loose objects regardless of their age (do
67-
not use --prune=all unless you know exactly what you are doing.
68-
Unless the repository is quiescent, you will lose newly created
69-
objects that haven't been anchored with the refs and end up
70-
corrupting your repository). --prune is on by default.
66+
--prune=all prunes loose objects regardless of their age and
67+
increases the risk of corruption if another process is writing to
68+
the repository concurrently; see "NOTES" below. --prune is on by
69+
default.
7170

7271
--no-prune::
7372
Do not prune any loose objects.
@@ -138,17 +137,36 @@ default is "2 weeks ago".
138137
Notes
139138
-----
140139

141-
'git gc' tries very hard to be safe about the garbage it collects. In
140+
'git gc' tries very hard not to delete objects that are referenced
141+
anywhere in your repository. In
142142
particular, it will keep not only objects referenced by your current set
143143
of branches and tags, but also objects referenced by the index,
144144
remote-tracking branches, refs saved by 'git filter-branch' in
145145
refs/original/, or reflogs (which may reference commits in branches
146146
that were later amended or rewound).
147-
148-
If you are expecting some objects to be collected and they aren't, check
147+
If you are expecting some objects to be deleted and they aren't, check
149148
all of those locations and decide whether it makes sense in your case to
150149
remove those references.
151150

151+
On the other hand, when 'git gc' runs concurrently with another process,
152+
there is a risk of it deleting an object that the other process is using
153+
but hasn't created a reference to. This may just cause the other process
154+
to fail or may corrupt the repository if the other process later adds a
155+
reference to the deleted object. Git has two features that significantly
156+
mitigate this problem:
157+
158+
. Any object with modification time newer than the `--prune` date is kept,
159+
along with everything reachable from it.
160+
161+
. Most operations that add an object to the database update the
162+
modification time of the object if it is already present so that #1
163+
applies.
164+
165+
However, these features fall short of a complete solution, so users who
166+
run commands concurrently have to live with some risk of corruption (which
167+
seems to be low in practice) unless they turn off automatic garbage
168+
collection with 'git config gc.auto 0'.
169+
152170
HOOKS
153171
-----
154172

0 commit comments

Comments
 (0)