# Purging old history

4 messages from 2012-03-31 to 2012-03-31. Participants: John M. Dlugosz, Ramkumar Ramachandra, Jakub Narebski, Phil Hord.
Thread: https://gitlist.dev/t/30116

## John M. Dlugosz, 2012-03-31 04:25

Subject: Purging old history
Message-ID: <17650-1333167969-40275@sneakemail.com>
URL: https://gitlist.dev/e/17650-1333167969-40275%40sneakemail.com

```
Is there a simple way to delete old commits, say beyond a certain age, before putting it 
on the server?  The ancient stuff is not relevant and there are a lot of binaries.  Some 
users may have trouble with an extensive download when syncing the first time.

—John

```

## Ramkumar Ramachandra, 2012-03-31 04:43

Subject: Re: Purging old history
Message-ID: <CALkWK0=mcQR3CBMpa5P1f+JwqNMqUs3D4=tVPx4c_4R+TXCKbw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0%3DmcQR3CBMpa5P1f%2BJwqNMqUs3D4%3DtVPx4c_4R%2BTXCKbw%40mail.gmail.com
In-Reply-To: <17650-1333167969-40275@sneakemail.com>

```
Hi John,

John M. Dlugosz wrote:
> Is there a simple way to delete old commits, say beyond a certain age,
> before putting it on the server?  The ancient stuff is not relevant and
> there are a lot of binaries.  Some users may have trouble with an extensive
> download when syncing the first time.

Yes, although your terminology is wrong: it's not about "deleting"
commits; simply create a fresh root commit and rebase your work on top
of it.  As an example, let's say you want to squash history from the
67afe1 (the old root) to 7ef42b on the master branch:

$ git checkout -b newroot 7ef42b
$ git reset 67afe1
$ git add .
$ git commit --amend
$ git checkout master
$ git rebase --onto newroot 7ef42b

    Ram

```

## Jakub Narebski, 2012-03-31 08:25

Subject: Re: Purging old history
Message-ID: <m37gy1b2j0.fsf@localhost.localdomain>
URL: https://gitlist.dev/e/m37gy1b2j0.fsf%40localhost.localdomain
In-Reply-To: <CALkWK0=mcQR3CBMpa5P1f+JwqNMqUs3D4=tVPx4c_4R+TXCKbw@mail.gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:
> John M. Dlugosz wrote:

> > Is there a simple way to delete old commits, say beyond a certain age,
> > before putting it on the server?  The ancient stuff is not relevant and
> > there are a lot of binaries.  Some users may have trouble with an extensive
> > download when syncing the first time.

It seems that you have XY problem.

One solution to extensive initial download is to create a git-bundle
of all commits up to e.g. some tag, and host it using HTTP, FTP
(which are resumable), or even P2P like BitTorrent.
 
Another solution would be to educate users to use shallow clones,
i.e. use "--depth" option to git-clone... and help git developers make
shallow clones better (there are some unncessary limitations in using
shallow clones).

> Yes, although your terminology is wrong: it's not about "deleting"
> commits; simply create a fresh root commit and rebase your work on top
> of it.  As an example, let's say you want to squash history from the
> 67afe1 (the old root) to 7ef42b on the master branch:
> 
> $ git checkout -b newroot 7ef42b
> $ git reset 67afe1
> $ git add .
> $ git commit --amend
> $ git checkout master
> $ git rebase --onto newroot 7ef42b

A simpler solution, one that would work also in presence of merges, is
to use grafts mechanism (see gitrepository-layout(5)) to cauterize
history, check using git-log or gitk that shortened history is
correct, make grafts permanent altering history with
git-filter-branch, and finally removing grafts.

P.S. Please read first all the warnings about rewriting history, and
about all its disadvantages for downstream.

-- 
Jakub Narebski

```

## Phil Hord, 2012-03-31 20:20

Subject: Re: Purging old history
Message-ID: <CABURp0oYJOYvxK54A7e3J2N1V-0pDS_AAoRErXhg6pJ6ZW962Q@mail.gmail.com>
URL: https://gitlist.dev/e/CABURp0oYJOYvxK54A7e3J2N1V-0pDS_AAoRErXhg6pJ6ZW962Q%40mail.gmail.com
In-Reply-To: <17650-1333167969-40275@sneakemail.com>

```
On Sat, Mar 31, 2012 at 12:25 AM, John M. Dlugosz
<ngnr63q02@sneakemail.com> wrote:
> Is there a simple way to delete old commits, say beyond a certain age,
> before putting it on the server?  The ancient stuff is not relevant and
> there are a lot of binaries.  Some users may have trouble with an extensive
> download when syncing the first time.

You may also choose to absolve the old commits of past sins (binaries
and secrets) while keeping them in the history.  See 'git help
filter-branch' for the manual and some pertinent examples.

Phil

```
