我不小心把一个dvd光盘放到了一个网站项目中,然后不小心提交-a -m…而且,快,回购膨胀了2.2 g。下次我做了一些编辑,删除了视频文件,并提交了所有内容,但压缩文件仍然在存储库中,在历史中。
我知道我可以从这些提交中启动分支,并将一个分支重置到另一个分支上。但是我应该怎么做才能合并两次提交,使大文件不显示在历史记录中,并在垃圾收集过程中被清理?
我不小心把一个dvd光盘放到了一个网站项目中,然后不小心提交-a -m…而且,快,回购膨胀了2.2 g。下次我做了一些编辑,删除了视频文件,并提交了所有内容,但压缩文件仍然在存储库中,在历史中。
我知道我可以从这些提交中启动分支,并将一个分支重置到另一个分支上。但是我应该怎么做才能合并两次提交,使大文件不显示在历史记录中,并在垃圾收集过程中被清理?
当前回答
如果你知道你的提交是最近的,而不是遍历整个树,执行以下操作: git filter-branch -tree filter 'rm LARGE_FILE.zip' HEAD~10.
其他回答
根据GitHub文档,只需遵循以下步骤:
去掉大文件
选项1:你不想保留大文件:
rm path/to/your/large/file # delete the large file
选项2:您希望将大文件保存到一个未跟踪的目录中
mkdir large_files # create directory large_files
touch .gitignore # create .gitignore file if needed
'/large_files/' >> .gitignore # untrack directory large_files
mv path/to/your/large/file large_files/ # move the large file into the untracked directory
保存更改
git add path/to/your/large/file # add the deletion to the index
git commit -m 'delete large file' # commit the deletion
从所有提交中删除大文件
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch path/to/your/large/file" \
--prune-empty --tag-name-filter cat -- --all
git push <remote> <branch>
我用一个bitbucket帐户遇到了这个问题,我不小心在那里存储了我网站的巨大*.jpa备份。
git filter-branch——prune-empty——index-filter 'git rm -rf——cached——ignore-unmatch MY-BIG-DIRECTORY-OR-FILE'——tag-name-filter cat -- --all
用所讨论的文件夹重新安装MY-BIG-DIRECTORY,以完全重写历史记录(包括标记)。
来源:https://web.archive.org/web/20170727144429/http: / / naleid.com: 80 /博客/ 2012/01/17 / finding-and-purging-big-files-from-git-history /
这将从你的历史记录中删除它
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch bigfile.txt' --prune-empty --tag-name-filter cat -- --all
如果你知道你的提交是最近的,而不是遍历整个树,执行以下操作: git filter-branch -tree filter 'rm LARGE_FILE.zip' HEAD~10.
当您遇到这个问题时,git rm是不够的,因为git会记住这个文件在我们的历史中曾经存在过一次,因此会保留对它的引用。
更糟糕的是,重基也不容易,因为任何对blob的引用都会阻止git垃圾收集器清理空间。这包括远程引用和reflog引用。
我把git forget-blob放在一起,一个尝试删除所有这些引用的小脚本,然后使用git filter-branch重写分支中的每个提交。
一旦你的blob完全没有被引用,git gc就会删除它
它的用法很简单,git forget-blob file-to-forget。你可以在这里获得更多信息
https://ownyourbits.com/2017/01/18/completely-remove-a-file-from-a-git-repository-with-git-forget-blob/
多亏了Stack Overflow和一些博客的回答,我把这些放在了一起。感谢他们!