git - 我的 git 存储库有一个巨大的 .pack 文件。有没有办法安全删除它?

标签 git

我对 git 内部结构知之甚少,但我确实看到有一个 .pack 文件比我的 .git 目录中的其他文件(存储库 30 GB 中的 9 GB)占用了更多的空间。有什么方法可以安全地摆脱它而不失去存储库的完整性吗?

最佳答案

packfile 是 git 中的一种节省空间的机制。

每当提交对文件的更改时,都会创建新对象,其中包含新文件和旧文件之间的更改。这意味着当提交文件的新版本时,git 不必存储文件的多个副本。

来自git-scm.com :

The packfile is a single file containing the contents of all the objects that were removed from your filesystem. The index is a file that contains offsets into that packfile so you can quickly seek to a specific object. What is cool is that although the objects on disk before you ran the gc were collectively about 22K in size, the new packfile is only 7K. You’ve cut your disk usage by ⅔ by packing your objects.

如果您有兴趣节省空间,这里有 previous SO answer这描述了如何缩小你的历史记录。然后,您可以运行 git gc 来重新打包您的包文件(不包含“压缩”对象)。

关于git - 我的 git 存储库有一个巨大的 .pack 文件。有没有办法安全删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47130877/

相关文章:

Git:如何提交手动删除的文件?

java - 使用 JGit Eclipse 提交特定日期

git - 如何使用 Git rebase 重新排序/merge 提交?

git - 你如何让 git 集成与 m2eclipse 一起工作?

Git push 不工作,但 git pull 在远程分支上工作

Git 樱桃选择 : how to regenerate change id?

git - 查看未推送到远程的本地提交的 git 更改/差异

git - 使用 GPG 签署 git 提交

git - 在哪里放置用户项目特定的 Gradle 属性?

Git:如何将一个 Remote 从另一个 Remote rebase