我对 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/