Skip to content

Commit 647a1bc

Browse files
committed
Merge branch 'mm/gc-safety-doc' into maint
Doc update. * mm/gc-safety-doc: git-gc.txt: expand discussion of races with other processes
2 parents f976c89 + f1350d0 commit 647a1bc

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
@@ -1409,7 +1409,9 @@ gc.pruneExpire::
14091409
Override the grace period with this config variable. The value
14101410
"now" may be used to disable this grace period and always prune
14111411
unreachable objects immediately, or "never" may be used to
1412-
suppress pruning.
1412+
suppress pruning. This feature helps prevent corruption when
1413+
'git gc' runs concurrently with another process writing to the
1414+
repository; see the "NOTES" section of linkgit:git-gc[1].
14131415

14141416
gc.worktreePruneExpire::
14151417
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)