git-sizer 学习笔记

git-sizer 命令输出

$ git-sizer --verbose

Processing blobs: 1215
Processing trees: 1086
Processing commits: 513
Matching commits to trees: 513
Processing annotated tags: 0
Processing references: 2
| Name                         | Value     | Level of concern               |
| ---------------------------- | --------- | ------------------------------ |
| Overall repository size      |           |                                |
| * Commits                    |           |                                |
|   * Count                    |   513     |                                |
|   * Total size               |   148 KiB |                                |
| * Trees                      |           |                                |
|   * Count                    |  1.09 k   |                                |
|   * Total size               |  1.34 MiB |                                |
|   * Total tree entries       |  29.7 k   |                                |
| * Blobs                      |           |                                |
|   * Count                    |  1.22 k   |                                |
|   * Total size               |  26.4 MiB |                                |
| * Annotated tags             |           |                                |
|   * Count                    |     0     |                                |
| * References                 |           |                                |
|   * Count                    |     2     |                                |
|     * Branches               |     1     |                                |
|     * Remote-tracking refs   |     1     |                                |
|                              |           |                                |
| Biggest objects              |           |                                |
| * Commits                    |           |                                |
|   * Maximum size         [1] |  1.97 KiB |                                |
|   * Maximum parents      [2] |     1     |                                |
| * Trees                      |           |                                |
|   * Maximum entries      [3] |   126     |                                |
| * Blobs                      |           |                                |
|   * Maximum size         [4] |  3.79 MiB |                                |
|                              |           |                                |
| History structure            |           |                                |
| * Maximum history depth      |   513     |                                |
| * Maximum tag depth          |     0     |                                |
|                              |           |                                |
| Biggest checkouts            |           |                                |
| * Number of directories  [5] |    25     |                                |
| * Maximum path depth     [6] |     5     |                                |
| * Maximum path length    [6] |    73 B   |                                |
| * Number of files        [7] |   281     |                                |
| * Total size of files    [8] |  20.6 MiB |                                |
| * Number of symlinks         |     0     |                                |
| * Number of submodules       |     0     |                                |

[1]  314be6877a8519aba4e703f2fdc7a9d540b441db
[2]  6a930f6bb128b4e023b5d40f4ec284650441cb19 (refs/heads/main)
[3]  70871672fc82c0697bb8a9e1d8ee78cc48940779 (723190f8c4bd0a25651123c2842438f544d46810:assets)
[4]  6e6f60ac463d1616bedcf2b9d3826c4e52d2b49f (refs/heads/main:assets/文件.pdf)
[5]  6612e646c5b1203be32186c76aa093852519f8f3 (12c0591edb5a3f6affe1dd5d001bfc2d4072d64f^{tree})
[6]  63264b7f5024765f195d69cca0a7d8734d9508f9 (refs/heads/main^{tree})
[7]  7ef042f07987acc492f5ca5f8cf3fb0c15c58264 (1424d4955f210f89f1f82117b18822ead85ae617^{tree})
[8]  78bdd67d7e37b0f4a8af0f6009236ef2270a7288 (f84cb9d396b1d2297dddea27dc72d6ed252f33cd^{tree})

输出解释

git-sizer 的输出中可以看出,你的 Git 仓库的整体大小和结构信息。以下是一些关键点的解释:

仓库整体大小

最大对象

历史结构

最大检出

具体对象

这些信息可以帮助你了解仓库的大小和结构,识别可能需要优化的部分。

哪些部分需要优化

根据 git-sizer 的输出,以下是一些可能需要优化的部分:

1. Blobs(文件对象)

2. 总文件大小

3. 树对象

4. 提交历史

具体优化建议:

  1. 使用 Git LFS:
git lfs install
git lfs track "*.pdf"
git add .gitattributes
git commit -m "Track PDF files with Git LFS"
  1. 移除不必要的文件:
git rev-list --objects --all | sort -k 2 > allfileshas.txt
git gc && git verify-pack -v .git/objects/pack/pack-*.idx | sort -k 3 -n | tail -40
  1. 简化提交历史:
git rebase -i HEAD~n  ## n 是你想要合并的提交数量
  1. 优化目录结构:

通过这些优化措施,你可以减少仓库的大小,提高操作性能。