Git 从历史记录中删除大文件 - Bitbucket
Git deleting large file from history - Bitbucket
我不小心将一个大文件推送到 Bitbucket 中的远程 git 存储库。
该文件的扩展名为 .webm
。
我把 *.webm
放在 .gitignore
中,然后为了删除它我 运行 BFG:
java -jar bfg-1.13.0.jar --delete-files *.webm
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push origin --force
问题是最后一个命令一直将原始 .webm 文件推送到远程存储库,而 bitbucket 一直说我的存储库已使用 1Gb+ space.
如果我运行而不是最后一个命令git push -u origin master
,它说我需要做一个git pull
,这让我再次下载大文件。
我做错了什么?我应该直接从 Bitbucket 中删除文件吗?
请参阅 BFG 文档的 "Your files are sacred" 段落:
By default the BFG doesn't modify the contents of your latest commit on your master (or 'HEAD') branch, even though it will clean all the commits before it.
That's because your latest commit is likely to be the one that you deploy to production
(...)
If you want to turn off the protection (in general, not recommended) you can use the --no-blob-protection
flag:
$ bfg --strip-biggest-blobs 100 --no-blob-protection repo.git
另一种方法是手动将其从头部提交中删除:
git rm --cached thatfile.webm
git commit --amend
我不小心将一个大文件推送到 Bitbucket 中的远程 git 存储库。
该文件的扩展名为 .webm
。
我把 *.webm
放在 .gitignore
中,然后为了删除它我 运行 BFG:
java -jar bfg-1.13.0.jar --delete-files *.webm
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push origin --force
问题是最后一个命令一直将原始 .webm 文件推送到远程存储库,而 bitbucket 一直说我的存储库已使用 1Gb+ space.
如果我运行而不是最后一个命令git push -u origin master
,它说我需要做一个git pull
,这让我再次下载大文件。
我做错了什么?我应该直接从 Bitbucket 中删除文件吗?
请参阅 BFG 文档的 "Your files are sacred" 段落:
By default the BFG doesn't modify the contents of your latest commit on your master (or 'HEAD') branch, even though it will clean all the commits before it.
That's because your latest commit is likely to be the one that you deploy to production
(...)
If you want to turn off the protection (in general, not recommended) you can use the
--no-blob-protection
flag:$ bfg --strip-biggest-blobs 100 --no-blob-protection repo.git
另一种方法是手动将其从头部提交中删除:
git rm --cached thatfile.webm
git commit --amend