您可以刪除二元膨脹並保留其餘的歷史記錄。 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