rickvug
rickvug

Reputation: 33

Git: delete the contents of a folder for good across multiple branches

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.

Upvotes: 1

Views: 1421

Answers (2)

Cascabel
Cascabel

Reputation: 497192

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.

Upvotes: 1

Debilski
Debilski

Reputation: 67878

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.

Upvotes: 0

Related Questions