您可以删除二元膨胀并保留其余的历史记录。 Git允许你在提交之前重新排序和“挤压”,所以你可以只提交添加和删除你的大二进制文件的提交。如果增加全部在一个提交中完成,并且在另一个提交中完成,那么这比处理每个文件要容易得多。
$ git log --stat # list all commits and commit messages
搜索这对于添加和删除您的二进制文件,并注意其SHA1s,在提交说2bcdef
和3cdef3
。
然后要编辑回购的历史记录,请使用rebase -i
命令及其交互选项,从提交您的二进制文件的提交的父级开始。这将启动$ EDITOR,你会看到开始2bcdef
提交列表:
$ git rebase -i 2bcdef^ # generate a pick list of all commits starting with 2bcdef
# Rebasing zzzzzz onto yyyyyyy
#
# Commands:
# pick = use commit
# edit = use commit, but stop for amending
# squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
pick 2bcdef Add binary files and other edits
pick xxxxxx Another change
.
.
pick 3cdef3 Remove binary files; link to them as external resources
.
.
插入squash 3cdef3
作为第二线,并删除它说pick 3cdef3
从列表行。您现在有一个交互式rebase
的操作列表,它将提交中添加和删除二进制文件的提交组合为一个提交,其差异仅仅是这些提交中的任何其他更改。然后,它会重新应用所有后续提交的为了,当你告诉它来完成:
$ git rebase --continue
这将需要一两分钟。
您现在有一个不再有二进制文件进入或退出的回购。但是他们仍然会占用空间,因为默认情况下,Git会保留30天左右的变化,然后才能进行垃圾回收,这样您就可以改变主意。 如果要立即将其删除:
$ git reflog expire --expire=1.minute refs/heads/master
#all deletions up to 1 minute ago available to be garbage-collected
$ git fsck --unreachable # lists all the blobs(files) that will be garbage-collected
$ git prune
$ git gc
现在你已经删除了膨胀,但保持你的历史的其余部分。
好,并通过回答。 – JesperE 2008-11-02 17:01:10
你只需要记住,如果其他人已经从该存储库中取出,重写历史会混淆他们的拉。 git-rebase手册介绍了如何恢复其他回购协议。 http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html – Otto 2009-01-24 16:26:17