From: Björn Steinbrink Date: Mon, 17 Nov 2008 02:24:12 GMT Subject: Re: purging unwanted history 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