网络共享文件夹上的 GIT 存储库中的并发 [英] Concurrency in a GIT repo on a network shared folder

查看:18
本文介绍了网络共享文件夹上的 GIT 存储库中的并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 (windows) 网络共享上存储一个裸 git 存储库.我使用 linux,并且使用 CIFS 安装了上述网络共享.我的同事使用 windows xp,并将网络共享自动挂载(从 ActiveDirectory,不知何故)作为网络驱动器.

I want to have a bare git repository stored on a (windows) network share. I use linux, and have the said network share mounted with CIFS. My coleague uses windows xp, and has the network share automounted (from ActiveDirectory, somehow) as a network drive.

我想知道我是否可以在两台计算机上使用 repo,而不会出现并发问题.

I wonder if I can use the repo from both computers, without concurrency problems.

我已经测试过了,最后我可以克隆,但我担心如果我们同时访问同一个 repo(推/拉)会发生什么.

I've already tested, and on my end I can clone ok, but I'm afraid of what might happen if we both access the same repo (push/pull), at the same time.

在 git FAQ 中有一个关于使用网络文件系统的参考(以及 SMBFS 的一些问题),但我不确定网络/服务器/windows/linux 是否有任何文件锁定 - 我很肯定没有.

In the git FAQ there is a reference about using network file systems (and some problems with SMBFS), but I am not sure if there is any file locking done by the network/server/windows/linux - i'm quite sure there isn't.

那么,有没有人在没有服务器且没有问题的情况下在网络共享上使用过 git repo?

So, has anyone used a git repo on a network share, without a server, and without problems?

谢谢,
亚历克斯

Thank you,
Alex

PS:我想避免使用 http 服务器(或 git-daemon),因为我无法访问带有共享的服务器.此外,我知道我们可以从一个推/拉到另一个,但出于备份原因,我们需要在共享上拥有代码/存储库.

PS: I want to avoid using an http server (or the git-daemon), because I do not have access to the server with the shares. Also, I know we can just push/pull from one to another, but we are required to have the code/repo on the share for back-up reasons.

更新:

我担心的不是网络故障的可能性.即便如此,我们也会在本地拥有所需的分支,并且我们将能够编译我们的源代码.

Update:

My worries are not about the possibility of a network failure. Even so, we would have the required branches locally, and we'll be able to compile our sources.

但是,我们通常经常提交,并且需要经常变基/合并.在我看来,最好的选择是在共享上拥有一个中央存储库(因此可以确保备份),我们都将从该存储库中进行克隆,并使用它进行变基.

But, we usually commit quite often, and need to rebase/merge often. From my point of view, the best option would be to have a central repo on the share (so the backups are assured), and we would both clone from that one, and use it to rebase.

但是,由于我们经常这样做,我担心文件/存储库损坏,如果碰巧我们同时推/拉.通常,我们每次访问远程存储库时都可以大喊 :),但最好让计算机/网络对其进行保护.

But, due to the fact we are doing this often, I am afraid about file/repo corruption, if it happens that we both push/pull at the same time. Normally, we could yell at each other each time we access the remote repo :), but it would be better to have it secured by the computers/network.

而且,GIT 可能有一个内部机制来做到这一点(因为有人可以在你处理它的时候推送到你的一个存储库),但我还没有找到任何结论.

And, it is possible that GIT has an internal mechanism to do this (since someone can push to one of your repos, while you work on it), but I haven't found anything conclusive yet.

更新 2:

共享驱动器上的存储库将是 存储库,不包含工作副本.

Update 2:

The repo on the share drive would be a bare repo, not containing a working copy.

推荐答案

Git 需要最少的文件锁定,我认为这是通过网络文件系统使用此类共享资源时出现问题的主要原因.它可以逃脱的原因是 Git 存储库中的大多数文件——所有构成对象数据库的文件——都被命名为其内容的摘要,并且一旦创建就无法改变.因此,不会出现两个客户端尝试将同一文件用于不同内容的问题.

Git requires minimal file locking, which I believe is the main cause of problems when using this kind of shared resource over a network file system. The reason it can get away with this is that most of the files in a Git repo--- all the ones that form the object database--- are named as a digest of their content, and immutable once created. So there the problem of two clients trying to use the same file for different content doesn't come up.

对象数据库的另一部分更棘手——引用存储在refs"目录(或packed-refs")下的文件中,这些确实发生了变化:尽管refs/* 文件很小并且总是被重写而不是被编辑.在这种情况下,Git 将新的 ref 写入一个临时的.lock"文件,然后在目标文件上重命名它.如果文件系统尊重 O_EXCL 语义,那是安全的.即使没有,可能发生的最坏情况也是覆盖 ref 文件的竞争.尽管遇到这种情况会很烦人,但它不应该导致损坏:可能是您推送到共享存储库的情况,并且该推送看起来成功了,而实际上其他人已成功.但这可以通过拉动(合并其他人的提交)并再次推送来解决.

The other part of the object database is trickier-- the refs are stored in files under the "refs" directory (or in "packed-refs") and these do change: although the refs/* files are small and always rewritten rather than being edited. In this case, Git writes the new ref to a temporary ".lock" file and then renames it over the target file. If the filesystem respects O_EXCL semantics, that's safe. Even if not, the worst that could happen would be a race overwriting a ref file. Although this would be annoying to encounter, it should not cause corruption as such: it just might be the case that you push to the shared repo, and that push looks like it succeeded whereas in fact someone else's did. But this could be sorted out simply by pulling (merging in the other guy's commits) and pushing again.

总而言之,我不认为这里的 repo 损坏是一个太大的问题——确实,由于锁定问题,事情可能会出现一些错误,但是 Git repo 的设计会将损坏降至最低.

In summary, I don't think that repo corruption is too much of a problem here--- it's true that things can go a bit wrong due to locking problems, but the design of the Git repo will minimise the damage.

(免责声明:这一切在理论上听起来都不错,但我没有对 repo 进行任何并发锤击来测试它,并且只通过 NFS 而不是 CIFS 共享它们)

(Disclaimer: this all sounds good in theory, but I've not done any concurrent hammering of a repo to test it out, and only share them over NFS not CIFS)

这篇关于网络共享文件夹上的 GIT 存储库中的并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆