Yuval Adam
Yuval Adam

Reputation: 165282

Cleaning up binary blobs in a git repository

We have a certain binary file in our git repository. Usually it's around 2MB in size.

One of our developers accidentally committed this file bundled with all of its dependencies, which bumped up the file to around 40MB.

Of course we committed a fixed version, but the main repository still has that useless chunk of 40MB of binary data we do not need. I can guarantee we will never need that file's history for that specific commit (or for any other commit for that matter - it's a compiled binary, we have the source versioned anyway).

How can I remove that blob of data to restore the repo size? A simple git gc doesn't suffice, and I think I need some lower-level hacking I am not familiar with.

Upvotes: 3

Views: 1224

Answers (2)

svick
svick

Reputation: 244928

If you can create the file from the source code, it most likely doesn't belong to the repository at all.

If you want to remove that version of the file from the repository, you would have to rebase the repo, ideally using git rebase -i. Problem with that is that it's rewriting history and you really shouldn't do that for commits that are already public (that is, shared between multiple users). See Recovering from upstream rebase for how to make this work if you really want to.

After you do that rebase, the file will stay in the repository for a while, but it will be removed automatically eventually. And it won't be transmitted at all, if you use git clone or git pull.

Upvotes: 5

Sheena
Sheena

Reputation: 16242

If you checkout then the file will arrive in your local copy of the repo. then use git rm to get it out. Or, to make it look like it was never added check this out: Completely remove file from all Git repository commit history

Upvotes: 0

Related Questions