我有一个巨大的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
文件夹已经消失了。
我不明白,为什么存储库大小仍然那么大,但是文件夹实际上不在提交历史记录中。