我提交了id 56f06019(例如).在那个提交中,我不小心提交了大文件(50Mb).在另一个提交中,我添加相同的文件,但大小合适(小).现在我克隆的回购太重了:(如何从回购历史中删除那个大文件以减少我的回购的大小?
seh*_*ehe 155
让我简要介绍一下这里的步骤:
git filter-branch --index-filter \
'git rm --cached --ignore-unmatch path/to/mylarge_50mb_file' \
--tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)
像之前描述的rebasing选项一样,filter-branch是重写操作.如果您已发布历史记录,则必须--force推送新的参考号.
这种filter-branch方法比rebase方法强大得多,因为它
filter-branch 保持备份,所以除非你使reflogs和垃圾收集过期,否则repo的大小不会立即减少:
rm -Rf .git/refs/original # careful
git gc --aggressive --prune=now # danger
Run Code Online (Sandbox Code Playgroud)
您可以使用git-extras工具。该泯命令完全从库中删除一个文件,其中包括过去的提交和标签。
https://github.com/tj/git-extras/blob/master/Commands.md
我尝试在 Windows /sf/answers/611907131/上使用以下答案
单引号在 Windows 上不起作用;你需要双引号。
以下为我工作。
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch PathRelativeRepositoryRoot/bigfile.csv" -- --all
Run Code Online (Sandbox Code Playgroud)
删除大文件后,我能够将更改推送到 GitHub master。
| 归档时间: |
|
| 查看次数: |
40503 次 |
| 最近记录: |