清理后如何减小 Bitbucket repo 中的大小

How reduce size in Bitbucket repo after clean it

我在 Bitbucket 中有一个存储库,已使用约 160MB,我删除了所有分支。回购协议非常清楚,它继续说我使用了 160 MB。

Image

我怎样才能真正删除我的仓库中的所有文件。我不想创建新的存储库。

作为补充。如果我向回购添加一些文件,例如“file.mp3”,然后我将其删除,它会增加回购大小并且我无法再次减少它。我尝试了一些 post 比如 this Atlassian Help.

最佳,

编辑:我正在尝试使用 BFG。当我制作“bfg --strip-blobs-bigger-than 1M”时,我得到:

Scanning packfile for large blobs: 115
Scanning packfile for large blobs completed in 16 ms.
Found 6 blob ids for large blobs - biggest=47522424 smallest=1515614
Total size (unpacked)=102234236
Found 2 objects to protect
Found 4 commit-pointing refs : HEAD, refs/heads/11.0.0-7, refs/heads/master, refs/notes/master

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit 57632224 (protected by 'HEAD')

Cleaning
--------

Found 3 commits
Cleaning commits:       100% (3/3)
Cleaning commits completed in 166 ms.

Updating 1 Ref
--------------

        Ref                   Before     After
        -----------------------------------------
        refs/heads/11.0.0-7 | b333507a | 37b0f5cb

Updating references:    100% (1/1)
...Ref update completed in 16 ms.

Commit Tree-Dirt History
------------------------

        Earliest      Latest
        |                  |
           .     D      .

        D = dirty commits (file tree fixed)
        m = modified commits (commit message or parents changed)
        . = clean commits (no changes to file tree)

                                Before     After
        -------------------------------------------
        First modified commit | b333507a | 37b0f5cb
        Last dirty commit     | b333507a | 37b0f5cb

Deleted files
-------------

        Filename                                 Git id
        -----------------------------------------------------------
        Image.png                             | 6481d63a (3,3 MB)
        Sfile3.rpm                            | e8b6f2b8 (29,4 MB)
        UserManual.pdf                        | 77c29187 (16,2 MB)
        c.res                                 | 92392c06 (1,4 MB)
        xxxx.png                              | 6481d63a (3,3 MB)
        file1                                 | f24d869b (45,3 MB)
        file2                                 | 4e62ab09 (1,9 MB)


In total, 9 object ids were changed.

问题是 git 永久存储散列,因此您必须更加努力地删除内容。通过删除分支,您实际上只是删除了对存储在存储库中的补丁的引用。

我建议您尝试使用 bfg。它非常快速且使用起来非常简单。

git clone --mirror git://example.com/some-big-repo.git
java -jar bfg.jar --strip-blobs-bigger-than 100M some-big-repo.git
cd some-big-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force

这些设置将需要更改以满足您的需要,但这实际上会重写存储库中 blob 的内容。

验证

为了验证这些步骤,我执行了以下操作:

mkdir bfg-test
cd bfg-test
echo "Test bfg cleanup in bitbucket." > README.md
git init
git remote add origin git@bitbucket.org:theherk/bfg-test.git
git add README.md
git commit -m "Initial commit."
git push origin main
# size in bitbucket.org: 57.94 KB
dd if=/dev/urandom bs=1048577 count=1 | base64 > garbage
git add garbage
git checkout -b garbage-branch
git commit -m "Add garbage file."
git push origin garbage-branch
# size in bitbucket.org: 1.12 MB
git checkout main
git branch -D garbage-branch
git push origin -d garbage-branch
# size in bitbucket.org: 1.12 MB
cd ..
git clone --mirror git@bitbucket.org:theherk/bfg-test.git
java -jar ~/bin/bfg.jar --strip-blobs-bigger-than 1K bfg-test.git

此时,我没有发现大的斑点。如果它在那里,它就会被剥夺。所以我检查了回购镜像的大小。 88 KB;而不是 bitbucket.org 报告的 1.12 MB。事实证明,bitbucket 确实修剪了文件并且存储库实际上更小,他们的界面只是谎言并报告使用情况,包括将在以后清理的悬挂文件。

最重要的是,如果您的克隆较小,请不要相信存储库设置中的信息。

一旦您将对象添加到对象数据库,它会在那里至少停留一段时间如果对象没有被诸如电流之类的东西指向branch/tag .即使对象没有被 branch/tag 指向,它仍然可以被 reflog 保留一段时间,这可能需要一点时间才能清除修订。 Git 每隔一段时间就会 garbage-collection ......你可以用 git gc 强制 运行 它。检查它的选项并享受它的乐趣。