git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: dieter@schoen.or.at
Cc: git@vger.kernel.org
Subject: Re: how to remove unreachable objects?
Date: Mon, 19 Sep 2011 15:53:36 -0400	[thread overview]
Message-ID: <20110919195335.GA31930@sigill.intra.peff.net> (raw)
In-Reply-To: <20110919110831.ewq03vnqos4w8cs8@webmail.edis.at>

On Mon, Sep 19, 2011 at 11:08:31AM +0200, dieter@schoen.or.at wrote:

> 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).

> 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

  reply	other threads:[~2011-09-19 19:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-19  9:08 how to remove unreachable objects? dieter
2011-09-19 19:53 ` Jeff King [this message]
2011-09-19 20:18   ` Jeff King
2011-09-19 21:38     ` Junio C Hamano
2011-09-19 22:52       ` Jeff King
2011-09-20  0:40         ` Junio C Hamano
2011-09-20  0:51           ` Jeff King
2011-09-24 22:11   ` Dieter Schön
2011-09-19 20:36 ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110919195335.GA31930@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=dieter@schoen.or.at \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).