git - 为什么复制笔记时存储库大小会翻倍?

标签 git subgit bfg-repo-cleaner git-notes

我使用 Subgit 导入 SVN 存储库,这是一个出色的工具,可以快速完成并支持自定义 svn 布局。 Subgit 在 git notes 中保存 git commit -> svn revision reference。每个提交在注释中都有修订号,您可以通过 git log 查看它。

在 SVN->git import 之后,我使用 BFG repo cleaner 从 jar、dll 等二进制文件中清理旧项目存储库。 BFG 不会重写 git 注释和更改的提交之间的链接,但幸运的是它留下了 object-id-map.old-new.txt 文件。

我使用此文件将注释从旧提交复制到新提交:

cat object-id-map.old-new.txt | git 注释复制 --stdin

复制笔记后,我将它们从旧对象中删除:

cat object-id-map.old-new.txt |剪切-d''-f 1 | git notes remove --stdin --ignore-missing

问题是在修复 git notes 后,存储库的大小变成了原来的 2 倍(即使我在没有 --bare 的情况下克隆)。为什么?

示例:我使用 Subgit 从 svn 导入了 repo,并且有 400Mb .git。然后我应用 BFG 并获得 40 Mb 裸存储库。我想通过上面的 2 个命令移动(复制和删除)它们来恢复 git notes,但不幸的是 repo 的大小从 40 Mb 增加到 80 Mb。 我尝试执行 BFG 推荐的 git notes prunegit reflog expire --expire=now --all && git gc --prune=now --aggressive,但仍有 80 Mb。

UPD:现在无法重现 40 Mb 的 repo:/BFG 清理后为 80,复制笔记后为 86

最佳答案

Git 的三个演变(自 2017 年以来)和围绕 Git 的工具应该有助于解决这个问题:

  • 一个:类似github/git-sizer 的工具会让您了解什么占用了如此多的空间。
  • 两个:git filter-repo (我 mentioned here )现在取代了 BFG 或 gilter-branch。 Install it first . (python3 -m pip install --user git-filter-repo).
    清理不需要的 jar /二进制文件后,它会留下更少的数据。
git filter-repo --strip-blobs-bigger-than 10M
  • 三:丢失引用的对象可以被删除,即使它们附有注释(这些注释将变得悬空,反过来可以用“git notes prune”删除(man) ).
    这已在 Git 2.31(2021 年第一季度)的文档中得到阐明。

参见 commit fa9ab02 (2021 年 2 月 10 日)Martin von Zweigbergk (martinvonz) .
(由 Junio C Hamano -- gitster -- merge 于 commit d590ae5 ,2021 年 2 月 25 日)

docs: clarify that refs/notes/ do not keep the attached objects alive

Signed-off-by: Martin von Zweigbergk

git help(man) gc contains this snippet:

"[...] it will keep [..] objects referenced by the index,
remote-tracking branches, notes saved by git notes under refs/notes/"

I had interpreted that as saying that the objects that notes were attached to are kept, but that is not the case.
Let's clarify the documentation by moving out the part about git notes(man) to a separate sentence.

git gc 现在包含在其 man page 中:

objects referenced by the index, remote-tracking branches, reflogs (which may reference commits in branches that were later amended or rewound), and anything else in the refs/* namespace.

Note that a note (of the kind created by 'git notes') attached to an object does not contribute in keeping the object alive.
If you are expecting some objects to be deleted and they aren't, check all of those locations and decide whether it makes sense in your case to remove those references.

关于git - 为什么复制笔记时存储库大小会翻倍?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43808653/

相关文章:

windows - Windows 上的 Github "Failed to publish this branch"错误

javascript - git hooks pre-push 不起作用

Git rebase 分支到旧的提交

subgit 导入和多个分支目录

git - BFG Repo Cleaner 的正确使用方法

php - "git push appengine master"中需要用户名和密码

git - Subgit:避免将 git 分支同步到 svn

git - 如何使用 BFG 删除 protected 提交

BFG 之后的 git 笔记?