如何从所有未推送的 Git 提交中删除大于某个给定大小的所有文件?

Fra*_*urt 1 git

如何从所有未推送的 Git 提交中删除所有大于 X MB 的文件?

Von*_*onC 5

要清除该库的历史,你可能会考虑新的工具,git filter-repo取代了BFG和git filter-branch

git filter-repo --strip-blobs-bigger-than 10M --refs master~3..master
Run Code Online (Sandbox Code Playgroud)

将 3 替换为您拥有的未推送提交的数量(仅供参考:查看未推送的 Git 提交)。

或者:

git filter-repo --strip-blobs-bigger-than 10M --refs origin/master..master
Run Code Online (Sandbox Code Playgroud)

请注意,如果您Error: need a version of git whose diff-tree command has the --combined-all-paths option在运行上述命令时收到错误消息,则表示您必须更新git.