我认为 git lfs migrate
重写了 repo 的历史,以便将指定的大文件保存在 LFS 中。这意味着 repo 应该变小,因为它不直接包含大文件的所有版本。然而,当我运行时
git lfs migrate import --include="test-data/**"--include-ref=refs/heads/master
test-data/
目录中的所有文件都替换为如下所示的文件:
version https://git-lfs.github.com/spec/v1
oid sha256:5853b5a2a95eaca53865df996aee1d911866f754e6089c2fe68875459f44dc55
size 19993296
并且 .git 文件夹变得两倍大(400MB 到 800MB)。我很迷惑。 git lfs migrate 在做什么
?
编辑:我做了 clean after migration
git reflog expire --expire-unreachable=now --all
git gc --prune=now
在运行 du
之前。之后,大部分空间被这些文件夹使用:
414M .git/对象 398M .git/lfs
最佳答案
唯一的问题是二进制文件的原始 git 对象仍在 .git
文件夹中,因为您没有对它们进行垃圾回收。
您应该遵循 git lfs migration tutorial这解释了:
The above successfully converts pre-existing git objects to lfs objects. However, the regular objects still persist in the .git directory. These will be cleaned up eventually by git, but to clean them up right away, run:
git reflog expire --expire-unreachable=now --all
git gc --prune=now
运行后你的 .git 应该是相同的大小,但是如果你进入它你应该看到 objects
现在应该比迁移之前小得多并且 lfs
保留其余部分。
更好的消息是,现在当其他开发人员/应用程序克隆 repo 时,他们只需下载 objects
目录,然后仅获取“large-他们检查的文件”,而不是整个历史记录。
关于git - git lfs migrate 做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51782043/