How to remove unreferenced blobs from my git repo

后端 未结 10 2353
轻奢々
轻奢々 2020-11-22 15:07

I have a GitHub repo that had two branches - master & release.

The release branch contained binary distribution files that were contributing to a very large repo

10条回答
  •  情深已故
    2020-11-22 15:36

    You can (as detailed in this answer) permanently remove everything that is referenced only in the reflog.

    NOTE: This will remove many objects you might want to keep: Stashes; Old history not in any current branches; etc. Read the documentation to be sure this is what you want.

    To expire the reflog, and then prune all objects not in branches:

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

    git reflog expire --expire-unreachable=now --all removes all references of unreachable commits in reflog.

    git gc --prune=now removes the commits themselves.

    Attention: Only using git gc --prune=now will not work since those commits are still referenced in the reflog. Therefore, clearing the reflog is mandatory. Also note that if you use rerere it has additional references not cleared by these commands. See git help rerere for more details. In addition, any commits referenced by local or remote branches or tags will not be removed because those are considered as valuable data by git.

提交回复
热议问题