8

I'm using

git filter-branch --subdirectory-filter dir/name -- --all

to build a repo that only has history relating to that dir/name. Before I do the filter, I clone the original repo (which is very much bigger) into a tmp dir. After the filter-branch, the repo looks just how I want it, with one exception: It seems to still contain all the objects from the original repo even though they're not shown in "git log."

How can I remove all those unwanted objects completely?

I've tried things like:

git reflog expire --expire=now --all
git gc --aggressive --prune=now

It's clear to me that I don't know why they're still there or what it means to remove them, but I'd sure like to. A bit of possibly related information working against me is that I had done a git repack -a on my source repo a while back and it seems to copy that packfile over to the new repo. Seems like I should still be able to do what I want though.

jettero
  • 835
  • 2
  • 13
  • 26

1 Answers1

11

filter-branch also keeps backup refs in .git/refs/original, which you'll also have to remove before gc'ing

Pieter
  • 4,010
  • 1
  • 18
  • 15
  • 3
    If it's that simple I'm going to be kinda miffed. Do I literally just rm .git/refs/original ? – jettero Apr 02 '09 at 12:08
  • Well, rm-ing does indeed work (even if there's a better way) and this totally answers my question, thanks. – jettero Apr 02 '09 at 12:09
  • 2
    `rm` works only if GC was not performed, since GC moves `refs` to `packed-refs`. The right way to remove the original refs backed up by git-filter-branch would be `git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d`, as stated in the [git-filter-branch documentation](http://git-scm.com/docs/git-filter-branch). @jettero – user Mar 31 '15 at 13:44