我无意中添加、提交和推送了一个巨大的二进制文件,这是我最近一次提交 Git 存储库。
如何让 Git 删除为该提交创建的对象,从而使我的 .git
目录再次缩小到合理的大小?
编辑 : 谢谢你的回答,我尝试了几种解决方案。都没用。例如,来自 GitHub 的文件从历史记录中删除了文件,但是 .git
目录的大小没有减小:
$ BADFILES=$(find test_data -type f -exec echo -n "'{}' " \;)
$ git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $BADFILES" HEAD
Rewrite 14ed3f41474f0a2f624a440e5a106c2768edb67b (66/66)
rm 'test_data/images/001.jpg'
[...snip...]
rm 'test_data/images/281.jpg'
Ref 'refs/heads/master' was rewritten
$ git log -p # looks nice
$ rm -rf .git/refs/original/
$ git reflog expire --all
$ git gc --aggressive --prune
Counting objects: 625, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (598/598), done.
Writing objects: 100% (625/625), done.
Total 625 (delta 351), reused 0 (delta 0)
$ du -hs .git
174M .git
$ # still 175 MB :-(