Git (LFS):什么是锁定支持?我应该启用它吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42597408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:39:06  来源:igfitidea点击:

Git (LFS): what is locking support? And should I enable it?

gitgit-lfs

提问by Mike Williamson

"New" Git Comment:

“新”Git 评论:

Just today I ran across the following comment from Git for the first time (at least the first time I saw it):

就在今天,我第一次从 Git 中看到以下评论(至少我第一次看到它):

Mikes-Mac$ git push
Locking support detected on remote "origin". Consider enabling it with:
  $ git config 'lfs.https://github.com/<my_repo>.git/info/lfs.locksverify' true
Everything up-to-date
Mikes-Mac$ 

What is this Locking support? Is this some sort of mutex lockingfor the LFS (large file storage)? If so, isn't it absolutely essential to get anything on git to work? (Minimally, how else could the "ordering" of the log history be established? Worse case, couldn't I have a binary file corrupted by simultaneous writes?)

这是什么Locking support?这是LFS(大文件存储)的某种互斥锁吗?如果是这样,让 git 上的任何东西都能正常工作不是绝对必要的吗?(至少,如何才能建立日志历史记录的“排序”?更糟糕的情况是,我不能有一个被同时写入损坏的二进制文件吗?)

My Actions

我的行动

I didn't do anything differently to this repository recently, nor have I done anything differently with this repository compared to any others that I've established with LFS.

我最近没有对这个存储库做任何不同的事情,与我用 LFS 建立的任何其他存储库相比,我对这个存储库也没有做任何不同的事情。

I'm therefore assuming this is a new comment being provided to "the world" to let us know of new features.

因此,我假设这是向“世界”提供的新评论,让我们了解新功能。

No Obvious Documentation

没有明显的文件

However, neither a Google search nor a quicksearch through their documentation led me to anything to explain this. So, I'm left wondering:

然而,无论是谷歌搜索还是快速搜索他们的文档,我都无法解释这一点。所以,我想知道:

  • What is this locking?
    • Is it mutex? If so, how could my repo even function without it?
    • Is this limited to just LFS? How is it different from normal git file locking?
  • What are the pros and cons of adding locking support for LFS?
  • 这是什么锁?
    • 是互斥锁吗?如果是这样,如果没有它,我的 repo 怎么能运行呢?
    • 这是否仅限于 LFS?它与普通的 git 文件锁定有何不同?
  • 为 LFS 添加锁定支持的利弊是什么?

回答by kennytm

Locking support of Git LFS is documented here https://github.com/git-lfs/git-lfs/wiki/File-Locking.

此处记录了 Git LFS 的锁定支持https://github.com/git-lfs/git-lfs/wiki/File-Locking

Git LFS v2.0.0 includes an early release of File Locking. File Locking lets developers lock files they are updating to prevent other users from updating them at the same time. Concurrent edits in Git repositories will lead to merge conflicts, which are very difficult to resolve in large binary files.

Git LFS v2.0.0 包含文件锁定的早期版本。文件锁定允许开发人员锁定他们正在更新的文件,以防止其他用户同时更新它们。Git 存储库中的并发编辑会导致合并冲突,这在大型二进制文件中很难解决。

Once file patterns in .gitattributesare lockable, Git LFS will make them readonly on the local file system automatically. This prevents users from accidentally editing a file without locking it first.

一旦文件模式.gitattributes可锁定,Git LFS 将自动将它们在本地文件系统上设为只读。这可以防止用户在没有先锁定文件的情况下意外编辑文件。

Git LFS will verify that you're not modifying a file locked by another user when pushing. Since File Locking is an early release, and few LFS servers implement the API, Git LFS won't halt your push if it cannot verify locked files. You'll see a message like this:

$ git lfs push origin master --all
Remote "origin" does not support the LFS locking API. Consider disabling it with:
  $ git config 'lfs.http://git-server.com/user/test.locksverify' false
Git LFS: (0 of 0 files, 7 skipped) 0 B / 0 B, 879.11 KB skipped
$ git lfs push origin master --all
Locking support detected on remote "origin". Consider enabling it with:
  $ git config 'lfs.http://git-server.com/user/repo.locksverify' true
Git LFS: (0 of 0 files, 7 skipped) 0 B / 0 B, 879.11 KB skipped

Git LFS 将验证您在推送时没有修改被其他用户锁定的文件。由于文件锁定是一个早期版本,并且很少有 LFS 服务器实现 API,如果 Git LFS 无法验证锁定的文件,它不会停止您的推送。你会看到这样的消息:

$ git lfs push origin master --all
Remote "origin" does not support the LFS locking API. Consider disabling it with:
  $ git config 'lfs.http://git-server.com/user/test.locksverify' false
Git LFS: (0 of 0 files, 7 skipped) 0 B / 0 B, 879.11 KB skipped
$ git lfs push origin master --all
Locking support detected on remote "origin". Consider enabling it with:
  $ git config 'lfs.http://git-server.com/user/repo.locksverify' true
Git LFS: (0 of 0 files, 7 skipped) 0 B / 0 B, 879.11 KB skipped

So in some sense you may consider it an advisory mutex, because:

所以从某种意义上说,您可能会将其视为咨询互斥锁,因为:

  • If you don't "lock" the file, you can't edit it
  • Once you "lock" the file with git lfs lock, you can edit it, and the repository server will recognize that you are editing it
  • The server will not accept commits changing the files you have locked by other people.
  • 如果您不“锁定”文件,则无法对其进行编辑
  • 一旦你用“锁定”文件git lfs lock,你就可以编辑它,存储库服务器会识别你正在编辑它
  • 服务器不会接受更改您已被其他人锁定的文件的提交。

It is mainly added to help team managing large files to prevent merge conflicts.

添加它主要是为了帮助团队管理大文件以防止合并冲突。