簡體   English   中英

清理后如何減小 Bitbucket 存儲庫中的大小

[英]How reduce size in Bitbucket repo after clean it

我在 Bitbucket 中有一個使用了約 160MB 的存儲庫,我刪除了所有分支。 回購完全清楚,它繼續說我使用了 160 MB。

圖片

我怎樣才能真正刪除我的倉庫中的所有文件。 我不想創建一個新的倉庫。

作為補充。 如果我添加一些文件,例如“file.mp3”到 repo,然后我刪除它,它會增加 repo 大小,我不能再次減小它。 我嘗試了一些類似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 確實修剪了文件,並且存儲庫實際上更小,它們的界面只是謊言並報告使用情況,包括將在以后清理的懸空文件。

最重要的是,如果您的克隆較小,則不要相信存儲庫設置中的信息。

將對象添加到對象數據庫后,如果對象沒有被當前分支/標簽之類的東西指向,它將至少在那里停留一段時間。 即使對象沒有被分支/標簽指向,它仍然可以被 reflog 持有一段時間,這可能需要一點時間來清除修訂。 Git 每隔一段時間就會進行一次垃圾收集……你可以用git gc強制運行它。 檢查它的選項並玩得開心。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM