# delete deprecated refs to release disk space

4 messages from 2011-11-13 to 2011-11-16. Participants: Peter Vereshagin, Ævar Arnfjörð Bjarmason.
Thread: https://gitlist.dev/t/28925

## Peter Vereshagin, 2011-11-13 15:10

Subject: delete deprecated refs to release disk space
Message-ID: <20111113151033.GD16065@external.screwed.box>
URL: https://gitlist.dev/e/20111113151033.GD16065%40external.screwed.box

```
Hello.

I use git for sql database backups:

    http://gitweb.vereshagin.org/endvance/blob_plain/HEAD:/endvance/README

Am wondering if there is a way to remove the expired revisions? Following that
scenario:

    https://gist.github.com/1362183

I think there should be the way to decrease the space that .git takes. Without
compression, of course.

No problem if this involves the overwriting of the history like  filter-branch
does.  But filter-branch doesn't seem to be able to remove the old  info  from
repository based on expiration time, does it?

Thank you.

--
Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627 

```

## Ævar Arnfjörð Bjarmason, 2011-11-13 17:01

Subject: Re: delete deprecated refs to release disk space
Message-ID: <CACBZZX5kBqM1eye40_Vw0W=8qnNsUQBVCE0q9JrixYomGPuZbg@mail.gmail.com>
URL: https://gitlist.dev/e/CACBZZX5kBqM1eye40_Vw0W%3D8qnNsUQBVCE0q9JrixYomGPuZbg%40mail.gmail.com
In-Reply-To: <20111113151033.GD16065@external.screwed.box>

```
2011/11/13 Peter Vereshagin <peter@vereshagin.org>:
> Hello.
>
> I use git for sql database backups:
>
>    http://gitweb.vereshagin.org/endvance/blob_plain/HEAD:/endvance/README
>
> Am wondering if there is a way to remove the expired revisions? Following that
> scenario:
>
>    https://gist.github.com/1362183
>
> I think there should be the way to decrease the space that .git takes. Without
> compression, of course.
>
> No problem if this involves the overwriting of the history like  filter-branch
> does.  But filter-branch doesn't seem to be able to remove the old  info  from
> repository based on expiration time, does it?

What you're looking for is git-filter-branch + the graft facility. I
can't remember the exact invocation, but you echo the sha1 of the
commit you want to be the oldest commit to .git/info/grafts, then run
git-filter-branch.

You can use whatever you like to discover that sha1, e.g. keep N
revisions (which might be committed once per day) around, or have some
custom time limit etc.

```

## Peter Vereshagin, 2011-11-14 14:25

Subject: Re: delete deprecated refs to release disk space
Message-ID: <20111114142525.GB8641@external.screwed.box>
URL: https://gitlist.dev/e/20111114142525.GB8641%40external.screwed.box
In-Reply-To: <CACBZZX5kBqM1eye40_Vw0W=8qnNsUQBVCE0q9JrixYomGPuZbg@mail.gmail.com>

```
Hello.

2011/11/13 18:01:18 +0100 ??var Arnfj??r?? Bjarmason <avarab@gmail.com> => To Peter Vereshagin :
vArB> What you're looking for is git-filter-branch + the graft facility. I
vArB> can't remember the exact invocation, but you echo the sha1 of the
vArB> commit you want to be the oldest commit to .git/info/grafts, then run
vArB> git-filter-branch.

Seem to work for me ( with 'gc' and 'prune' thereafter ) but with these quirks:
*) the git-filter-branch(1) tells that there must be two ids:

    echo "$commit-id $graft-id" >> .git/info/grafts

This works for me if only one is put there.
*) I'd like to have a command for this. Is this a '--parent-filter' to make
the same thing?

N commits ago is a fine setting for me as it's a cron job backup. Thanks?

--
Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627 

```

## Peter Vereshagin, 2011-11-16 23:44

Subject: Re: delete deprecated refs to release disk space
Message-ID: <20111116234422.GA5131@external.screwed.box>
URL: https://gitlist.dev/e/20111116234422.GA5131%40external.screwed.box
In-Reply-To: <20111114142525.GB8641@external.screwed.box>

```
Hello.

2011/11/14 18:25:25 +0400 Peter Vereshagin <peter@vereshagin.org> => To ??var Arnfj??r?? Bjarmason :
PV> N commits ago is a fine setting for me as it's a cron job backup. Thanks?

* = Thanks!

Here is the PoC QnD code that releases disk space for me by far:

    git rev-list --all --timestamp |\
        perl -Mstrict -MTime::ParseDate -wE \
            'my $match = 0; my $expire = parsedate( "3 days ago" ); while (<>)
                { chomp; my ( $tstamp => $graft_id ) = split /\s+/;
                    if ( not( $match ) and $tstamp < $expire )
                        { say $graft_id; $match = 1; } }
            ' > .git/info/grafts && \
    git filter-branch -f

for case a one shall seek for it.

--
Peter Vereshagin <peter@vereshagin.org> (http://vereshagin.org) pgp: A0E26627 

```
