问题描述
我已经提交id 56f06019(例如)。在那个提交中我偶然提交了大文件(50Mb)。在另一个提交我添加相同的文件,但在正确的大小(小)。现在我的回购当我克隆是太重了:(如何从回购历史中删除该大文件,以减少我的回购大小?
解决方案我已经提交id 56f06019(例如)。在那个提交中我偶然提交了大文件(50Mb)。在另一个提交我添加相同的文件,但在正确的大小(小)。现在我的回购当我克隆是太重了:(如何从回购历史中删除该大文件,以减少我的回购大小?
解决方案书的第9章有关于。
让我简单地概述这里的步骤:
git filter-branch --index-filter \
'git rm --cached --ignore-unmatch path / to / mylarge_50mb_file'\
--tag-name-filter cat - --all
就像前面介绍的重新布局选项一样, filter-branch
是重写操作。必须 - force
推送新的参考。
过滤器分支
方法比 rebase
方法强大得多,因为它 filter-branch
还保留备份,所以回购的大小不会立即减少,除非您过期reflogs和垃圾回收:
rm -Rf .git / refs / original#谨慎
git gc --aggressive --prune = now#危险
I have commit with id 56f06019 (for example). In that commit i have accidentally commited large file (50Mb). In another commit i add the same file but in the right size (small). Now my repo when i clone is too heavy :( How to remove that large file from repo history to reduce the size of my repo ?
Chapter 9 of the Pro Git book has a section on Removing Objects.
Let me outline the steps briefly here:
git filter-branch --index-filter \
'git rm --cached --ignore-unmatch path/to/mylarge_50mb_file' \
--tag-name-filter cat -- --all
Like the rebasing option described before, filter-branch
is rewriting operation. If you have published history, you'll have to --force
push the new refs.
The filter-branch
approach is considerably more powerful than the rebase
approach, since it
filter-branch
keeps backups too, so the size of the repo won't decrease immediately unless you expire the reflogs and garbage collect:
rm -Rf .git/refs/original # careful
git gc --aggressive --prune=now # danger
这篇关于Git:如何从历史提交中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!