1

我有一个巨大的 git 存储库,我想减小大小。为此,我想删除一个文件夹,该文件夹多次存在于具有相同名称的不同子目录中。

git 存储库具有以下文件夹结构:

- ID1
   - Graphs
- ID2
   - Graphs

我想删除所有Graphs文件夹,因为它们很大。我运行了java -jar ~/Downloads/bfg-1.13.0.jar --delete-folders Graphs --no-blob-protection ~/path/to/Repo以下输出:

Using repo : ~/path/to/Repo/.git

Found 0 objects to protect
Found 3 tag-pointing refs : refs/tags/VERSION1.4, refs/tags/VERSION1.5, refs/tags/VERSION3.1
Found 5 commit-pointing refs : HEAD, refs/heads/master, refs/remotes/origin/HEAD, ...

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

You're not protecting any commits, which means the BFG will modify the contents of even *current* commits.

This isn't recommended - ideally, if your current commits are dirty, you should fix up your working copy and commit that, check that your build still works, and only then run the BFG to clean up your history.

Cleaning
--------

Found 284 commits
Cleaning commits:       100% (284/284)
Cleaning commits completed in 268 ms.

Updating 3 Refs
---------------

    Ref                           Before     After
    -------------------------------------------------
    refs/heads/master           | 7f5ba511 | fcd2600c
    refs/remotes/origin/develop | c30fa798 | 7e345ac0
    refs/remotes/origin/master  | 7f5ba511 | fcd2600c

Updating references:    100% (3/3)
...Ref update completed in 20 ms.

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

    Earliest                                              Latest
    |                                                          |
    ...DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDm

    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 | 3fba1762 | 7a24f280
    Last dirty commit     | 0ea27985 | 1cc26472


In total, 490 object ids were changed. Full details are logged here:

    ~/path/to/Repo.bfg-report/2019-04-03/16-35-48

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive

然后我按照指示跑了git reflog expire --expire=now --all && git gc --prune=now --aggressive。这至少需要 5 小时才能完成。输出(我试图翻译):

Object count: 11191, Fertig.
Counting objects: 100% (11191/11191), Fertig.
Delta Compression is using up to 12 threads.
compress objects: 100% (11115/11115), Fertig.
write objects: 100% (11191/11191), Fertig.
Total 11191 (Delta 1866), Re-used 5522 (Delta 0)

现在,在它完成后,存储库的大小只是稍微小了一点。

查看签出的目录,大小仅为 <50MB。但是.git文件夹的大小> 19GB。浏览历史时,Graphs文件夹似乎消失了。

我不明白,为什么存储库大小仍然那么大,但这些文件夹实际上已经在提交历史记录中消失了。

4

0 回答 0