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

Re: purging unwanted history

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Nov 17, 2008, 02:24 UTC
Message-ID
<20081117022412.GB3911@atjola.homenet>
In-Reply-To
<93c3eada0811161626h69929cd7va3fa4007a2341bae@mail.gmail.com>
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.

HTH Björn

Previous: Geoff RussellNext: Björn Steinbrink
Message 2 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.