git - 使用 BFG-repo-cleaner 删除文件列表

标签 git git-rewrite-history bfg-repo-cleaner

由于部署问题,我们正在尝试将我们的 git 存储库缩小到 500MB 以下。

为实现这一目标,我们创建了一个新分支,我们已将所有旧图像、视频和字体移至 AWS S3。

我可以使用 git diff --name-only --diff-filter=D master -- public/assets/ 轻松获取文件列表。

现在,我尝试运行 BFG-repo-cleaner每个文件上的 1.14.0。但是我有 400 个文件,单独删除每个文件需要很长时间(在我写这篇文章时仍在运行)。

git diff --name-only --diff-filter=D master -- public/assets/| xargs -i 基名 '{}' | xargs -i bfg --delete-files '{}'

因为每个文件都是不同的,所以我不能真正使用 glob 模式,如 Delete multiple files from multiple branch using bfg repo cleaner 所建议的那样.

我试图用逗号分隔每个文件,但结果是 BFG-repo-cleaner告诉我:

BFG aborting: No refs to update - no dirty commits found??

有没有办法向BFG-repo-cleaner提供多个文件?没有 glob 模式?

附言。我对多个文件尝试的命令是: git diff --name-only --diff-filter=D master -- public/assets/| xargs -i 基名 '{}' | sed -z 's/\n/,/g;s/,$/\n/' | xargs -i bfg --delete-files '{}' && git reflog expire --expire=now --all && git gc --prune=now --aggressive

PPS。 bfg 命令作为一个简单的 bash 脚本在我的 PATH 上,带有 java -jar/tools/BFG-repo-cleaner/bfg-1.14.0.jar "$@"

最佳答案

But I have 400 files and it is taking ages to delete each files separately

这就是为什么要使用的工具(基于 python)是 newren/git-filter-repo (参见 installation)

这样,您可以为该工具提供一个文件,其中包含文件列表:

git filter-repo --paths-from-file <filename> --invert-paths

来自 the documentation :

Similarly, you could use --paths-from-file to delete many files.

For example, you could run git filter-repo --analyze to get reports, look in one such as .git/filter-repo/analysis/path-deleted-sizes.txt and copy all the filenames into a file such as /tmp/files-i-dont-want-anymore.txt, and then run:

git filter-repo --invert-paths \
                --paths-from-file /tmp/files-i-dont-want-anymore.txt

to delete them all.

关于git - 使用 BFG-repo-cleaner 删除文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70387071/

相关文章:

Git/Gerrit Jenkins 持续集成 : How to handle rebase needs

git - 如何验证 BFG Repo-Cleaner 是否已从 git 存储库中正确删除大文件?

git - BFG Repo Cleaner 未按预期工作

Git BFG 追溯启用 LFS - protected 提交问题

git - 如何在 heroku 上的 package.json 中将 public bitbucket repo 引用为 npm 模块?

git - 没有子模块的嵌套 git 存储库?

git - 获取特定 Git 提交的更改文件列表及其状态

git - 将 Git 工作流从 merge 切换到 rebase : how to clean up a merge commit history?

git - merge Git 存储库的前两个提交?

git - 修改 merge 前 Git 提交的消息