tags:

views:

37

answers:

2

I am transferring an SVN repository into Git and need to remove all files within a specific directory (sites/default/files/*) from all branches and tags. The reason is that all files in this directory were accidentally committed long in the past and are now making the Git repository 900+ MB in size. This repository has not been shared yet so there are no worries about changing SHAs etc.

Any help? I've tried following the instructions at http://github.com/guides/completely-remove-a-file-from-all-revisions but they don't seem to work for me.

A: 

If you have tags in your repo, you’ll have to add --tag-name-filter cat to the git filter-branch command.

And of course, to see any effect of the filtering you’ll have to prune the commits – or better yet: clone the repo to somewhere else and see if it is smaller now.

Debilski
+1  A: 

What do you mean by "don't seem to work"? It's hard to help without any specifics.

The thing that jumps out to me as most likely is that those instructions use HEAD for the ref to filter, so it'll only filter commits reachable from whatever you have checked out right now. You probably want to do this to all branches; instead of git filter-branch ... HEAD you could use git filter-branch ... -- --all. The -- indicates end of filter-branch options, and the --all means to filter all refs.

The best general advice I can give is to read the filter-branch man page. It contains some examples as well.

Finally, remember that the old objects stay around in the repo. Debilski touched on this, mentioning that you have to prune the old objects (git gc --prune=now) or reclone the repo to see the size difference. This will work fine for you locally.

To get it cleaned on the remote... well, I believe that github will eventually run git gc, but it'll be using the default prune settings, so they won't be pruned for a couple weeks. Otherwise, you could delete and recreate your project. I'm not aware of any way to force a gc on github.

Jefromi
Thanks for the help. I received similar guidance on IRC that helped. Hopefully others with this same problem will find this answer on Stack Overflow.
rickvug