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

Re: how to remove unreachable objects?

From
Jeff King <peff@peff.net>
Date
Sep 19, 2011, 19:53 UTC
Message-ID
<20110919195335.GA31930@sigill.intra.peff.net>
In-Reply-To
<20110919110831.ewq03vnqos4w8cs8@webmail.edis.at>
On Mon, Sep 19, 2011 at 11:08:31AM +0200, dieter@schoen.or.at wrote:
Show 7 quoted lines
> this is my use case:
> i create a repository and produce several commits on master.
> then i go back to a certain tag and create a new branch, where i also
> commit.
> then i switch back to master and delete (-D) the other branch.
> it should now be unreachable from within git (to prove its existence,
> i remember a commit SHA1 on the dead branch).
It will still be referenced by the HEAD reflog, won't it?
> git checkout master
> git branch -D $DEAD
> git show $dead_commit
> git fsck --unreachable --full --verbose
This shows it reachable, because it is connected from the HEAD reflog.
> git fsck --unreachable HEAD \
>                     $(git for-each-ref --format="%(objectname)" refs/heads)

And this shows it as unreachable, because you are asking git to only look at the branch tips and HEAD (by default, it looks at all refs and reflogs).

I suspect you copied this straight from the git-fsck manpage. That advice is a bit outdated, I think. It blames (in some form) all the way back to the original documentation added in c64b9b8 (2005-05-05, only a few weeks after git was born). A few weeks later, fsck learned to default to looking at all refs (1024932, 2005-05-18). And then other sane defaults like reflogs got tacked on later (reflogs came around the 1.4.x era, in 2006).

Show 8 quoted lines
> git fsck --lost-found
> git prune -v $dead_commit
> git prune $(git rev-parse --all)
> git repack
> git prune-packed
> git gc --prune=now
> git gc --aggressive
> git show $dead_commit

If you really want to make it unreachable, you should expire the reflogs, too:

  git reflog expire --expire=now --all
  # will now report unreachable
  git fsck --unreachable
  # will now actually delete objects
  git prune -v
  # gives "bad object ..."
  git show $dead_commit

git-gc will do this for you, but of course the default expiration time is much longer (I think something like 90 days).

-Peff
Previous: dieter@schoen.or.atNext: Jeff King
Message 2 of 9 in “how to remove unreachable objects?”
  1. dieter@schoen.or.atSep 19, 2011
  2. Jeff KingSep 19, 2011
  3. Jeff KingSep 19, 2011
  4. Junio C HamanoSep 19, 2011
  5. Jeff KingSep 19, 2011
  6. Junio C HamanoSep 20, 2011
  7. Jeff KingSep 20, 2011
  8. Dieter SchönSep 24, 2011
  9. Andreas SchwabSep 19, 2011

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.