由于部署问题,我们正在尝试将我们的 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/