Git LFS 未安装时会发生什么?

huangapple go评论59阅读模式
英文:

What happens when Git LFS is not installed?

问题

我有一个使用Git LFS的代码仓库,我需要了解如何指导我的合作开发者与之一起工作。特别是,我对在没有安装Git LFS的机器上工作时会发生什么情况感到困惑:我本来以为从这样的机器克隆会导致缺少文件(即存储在LFS中的文件),但经过快速尝试,我发现这些文件在代码树中。因此,我需要一些关于这个问题的澄清,以及在没有安装Git LFS的系统上可以期望什么样的不正常行为。

英文:

I have a repository using Git LFS, and I need to understand how to instruct my co-developers to work with it. In particular I am puzzled about what happens when working with a machine where Git LFS is not installed: I would have said that cloning from such a machine would result in missing files (i.e. those stored in the LFS), but from a quick try I see those files in the code tree.
So I'd need some clarifications about this and about what kind of misbehavior I can expect for systems where Git LFS is not installed.

答案1

得分: 3

当您使用Git LFS时,具有属性filter=lfs的任何文件都应存储在Git LFS中。存储在Git LFS中的文件在对象中提交的内容是指针文件。未存储在Git LFS中的文件仅是普通的Git对象。

如果未安装Git LFS而存储库使用Git LFS,那么在克隆或检出LFS文件时,指针文件将被写入树中,而不是调用Git LFS来写入大对象。结果通常是该文件无法正常使用应该处理它的软件,但在许多情况下,这可能是可以接受的选择。

更严重的是,如果未使用Git LFS的贡献者检入了本应由Git LFS管理的文件,那么他们将其检入为常规Git对象。Git LFS FAQ概述了会发生什么情况,但通常情况下,安装了Git LFS的用户通常会看到该文件被永久修改,即使使用git reset --hard也无法修复。FAQ建议使用基于CI的方法来防止这些提交被合并:

> 命令git lfs fsck --pointers BASE..HEAD(使用适当的BASEHEAD值)可以在您的CI系统中用于验证是否有人引入了这些问题。

请注意,这需要Git LFS 3.0.2或更高版本才能正常工作。

英文:

When you work with Git LFS, any file with the attribute filter=lfs is designed to be stored with Git LFS. When a file is stored with Git LFS, the contents committed in the object are a pointer file. Files that are not stored with Git LFS are simply normal Git objects.

If Git LFS is not installed and the repository uses Git LFS, then when a clone or checkout of an LFS file happens, the pointer file is written into the tree instead of Git LFS being invoked to write the large object. As a result, typically that file doesn't work with whatever software was supposed to process it, but this can be an acceptable choice in many contexts.

More seriously, if a contributor not using Git LFS checks in a file that was supposed to be managed by Git LFS, then they will check it in as a regular Git object. The Git LFS FAQ outlines what happens, but typically, users who do have Git LFS installed will often see the file as perpetually modified, and even git reset --hard cannot fix that. The FAQ recommends a CI-based approach to prevent those commits from being merged:

> The command git lfs fsck --pointers BASE..HEAD (with suitable values of BASE and HEAD) may be used in your CI system to verify that nobody is introducing such problems.

Note that this requires Git LFS 3.0.2 or later to work properly.

huangapple
  • 本文由 发表于 2023年6月6日 15:39:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定