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

Re: purging unwanted history

From
Geoff Russell <geoffrey.russell@gmail.com>
Date
Nov 17, 2008, 03:03 UTC
Message-ID
<93c3eada0811161903v7b6c7abaq58cb6712190d03d5@mail.gmail.com>
In-Reply-To
<20081117022714.GC3911@atjola.homenet>
On Mon, Nov 17, 2008 at 12:57 PM, Björn Steinbrink <B.Steinbrink@gmx.de> wrote:
Show 50 quoted lines
> On 2008.11.17 03:24:12 +0100, Björn Steinbrink wrote:
>> On 2008.11.17 10:56:23 +1030, Geoff Russell wrote:
>> > I have a repository with 5 years worth of history, I only want to keep
>> > 1 year, so I want to purge the first 4 years. As it happens, the
>> > repository only has a single branch which should simplify the problem.
>>
>> Use filter-branch to drop the parents on the first commit you want to
>> keep, and then drop the old cruft.
>>
>> Let's say $drop is the hash of the latest commit you want to drop. To
>> keep things sane and simple, make sure the first commit you want to
>> keep, ie. the child of $drop, is not a merge commit. Then you can use:
>>
>> git filter-branch --parent-filter "sed -e 's/-p $drop//'" \
>>       --tag-name-filter cat -- \
>>       --all ^$drop
>>
>> The above rewrites the parents of all commits that come "after" $drop.
>>
>> Check the results with gitk.
>>
>>
>> Then, to clean out all the old cruft.
>>
>> First, the backup references from filter-branch:
>>
>> git for-each-ref --format='%(refname)' refs/original | \
>>       while read ref
>>       do
>>               git update-ref -d "$ref"
>>       done
>>
>> Then clean your reflogs:
>> git reflog expire --expire=0 --all
>>
>> And finally, repack and drop all the old unreachable objects:
>> git repack -ad
>> git prune # For objects that repack -ad might have left around
>>
>> At that point, everything leading up to and including $drop should be
>> gone.
>
> Hm, on second thought, if you have tags referencing some of the old
> history, they'll still be around, I think. Just delete those before you
> start the rewriting.
>
> And of course do the above with a copy of your repo. Just in case.
>
> Björn
>

Great, I've just tested this and it is exactly what I want. I'm still getting my head around why, but understanding will arrive with a little more thought.

Many thanks,
Geoff
-- 
6 Fifth Ave,
St Morris, S.A. 5068
Australia
Ph: 041 8805 184 / 08 8332 5069
Previous: Björn SteinbrinkNext: Marcel M. Cary
Message 4 of 5 in “purging unwanted history”
  1. Geoff RussellNov 17, 2008
  2. Björn SteinbrinkNov 17, 2008
  3. Björn SteinbrinkNov 17, 2008
  4. Geoff RussellNov 17, 2008
  5. Marcel M. CaryNov 18, 2008

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.