删除大小(在磁盘空间中)大于给定值的提交

时间:2019-05-24 08:59:15

标签: git

通读后:

How to remove a too large file in a commit when my branch is ahead of master by 5 commits

https://help.github.com/en/articles/working-with-large-files

https://rtyley.github.io/bfg-repo-cleaner/

https://help.github.com/en/articles/removing-sensitive-data-from-a-repository

Show commit size in git log

Git - get all commits and blobs they created

我找不到删除磁盘上超过给定大小的提交的优雅解决方案。这些提交不一定具有大文件,但是它们本身就很大(具有许多〜200 KB的依赖项)。

如何从存储库中删除此类提交?

1 个答案:

答案 0 :(得分:1)

首先注意:

git压缩文件时将其存储在.git/结构中,并尝试仅使用它们的差异来存储相似文件;

从这种意义上讲,很难发现“什么提交占用了我的.git/文件夹中的最大空间”。


如果您要衡量签出时文件中占用的空间:

git ls-tree -r -l <commitid>

将列出文件及其各自大小

git ls-tree -r -l <commitid> | awk '{ sum += $4 } END { print sum }'

将打印这些文件的总大小。


您可以将上述快捷方式放在脚本中,查看哪些提交占用了超过xx个字节,接下来的事情是:您可以摆脱所说的提交吗?

您可以告诉git删除分支的结尾:

If all 'B's mark 'big commits' :

               +-- create a new branch here
               v
*--*--*--*--*--*--B--B--B--B <- branchA
    \              \
     \              \-B--B <- branchB
      \
       *--*--*--* <- branchC
              \
               \--B <- branchD

在上图中,您可以告诉git忘记branchAbranchBbranchD(并可能创建新引用以保留第一个“没有那么大”的提交),

但是当提交出现在分支的中间时:

*--*--B--B--*--* <- branchE

您“删除两个B”的概念在很大程度上取决于git存储库中存储的内容以及如何从分支的历史记录中删除这些提交。

一般建议是:不要删除提交。