开发者

Cleaning up binary blobs in a git repository

开发者 https://www.devze.com 2023-03-20 17:30 出处:网络
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 dependencie开发者_如何学JAVAs, wh

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 dependencie开发者_如何学JAVAs, 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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消