git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: repository corruption when pushing commits to a repository running 'git gc --prune='

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 14, 2015, 17:37 UTC
Message-ID
<xmqqoag18i6w.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<vpq4mhtbjma.fsf@grenoble-inp.fr>
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 8 quoted lines
> I think this is the expected behavior. push will create new objects that
> are not referenced until the ref is updated (at the very end). prune can
> run concurrently since creating and deleting objects is done in a
> lockless way (only the ref update needs a lock).
>
> Still, this is not the *documented* behavior, and an easy way to corrupt
> a repo should be very explicitly documented as very dangerous, and the
> precautions to take when using it should be explained clearly.

Yeah, I think this paragraph in the user-manual is the only thing that mentions it:

    Anyway, once you are sure that you're not interested in any dangling
    state, you can just prune all unreachable objects:
    ------------------------------------------------
    $ git prune
    ------------------------------------------------
    and they'll be gone. (You should only run `git prune` on a quiescent
    repository--it's kind of like doing a filesystem fsck recovery: you
    don't want to do that while the filesystem is mounted.
Something along this line, perhaps?
 Documentation/git-gc.txt | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt
index 5223498..fa15104 100644
--- a/Documentation/git-gc.txt
+++ b/Documentation/git-gc.txt
@@ -63,8 +63,11 @@ automatic consolidation of packs.
 --prune=<date>::
 	Prune loose objects older than date (default is 2 weeks ago,
 	overridable by the config variable `gc.pruneExpire`).
-	--prune=all prunes loose objects regardless of their age.
-	--prune is on by default.
+	--prune=all prunes loose objects regardless of their age (do
+	not use --prune=all unless you know exactly what you are doing.
+	Unless the repository is quiescent, you will lose newly created
+	objects that haven't been anchored with the refs and end up
+	corrupting your repository).  --prune is on by default.
 
 --no-prune::
 	Do not prune any loose objects.
Previous: Matthieu MoyNext: Matthieu Moy
Message 3 of 10 in “repository corruption when pushing commits to a repository running 'git gc --prune='”
  1. Jan SmetsOct 14, 2015
  2. Matthieu MoyOct 14, 2015
  3. Junio C HamanoOct 14, 2015
  4. Matthieu MoyOct 14, 2015
  5. Junio C HamanoOct 14, 2015
  6. Matthieu MoyOct 14, 2015
  7. Junio C HamanoOct 14, 2015
  8. Matthieu MoyOct 14, 2015
  9. Junio C HamanoOct 14, 2015
  10. Matthieu MoyOct 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.