清理Bitbucket repo后如何减少大小



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

形象我怎么能真正删除所有的文件在我的repo。我不想创建一个新的仓库。

adittion。如果我添加一些文件,例如"file.mp3"到回购,然后我删除它,它增加了回购规模,我不能再减少它。我尝试了一些类似于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确实对文件进行了修剪,并且存储库实际上更小,他们的界面只是说谎,并报告使用情况,包括稍后将被清理的悬空文件。

最重要的是,如果你的克隆更小,那么不要相信存储库设置中的信息。

一旦将对象添加到对象数据库中,如果对象没有被当前分支/标记之类的东西指向,它将在那里停留至少一段时间。即使对象不是由分支/标签指向的,它仍然可以被refg保留一段时间,这可能需要一点时间来允许修改被清除。Git会时不时地进行垃圾收集……你可以用git gc强制运行它。检查它的选项,并享受它的乐趣。

最新更新