保持子模块在工作树外部 [英] Keep submodule outside working tree

查看:126
本文介绍了保持子模块在工作树外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库,我在多个项目中用作git子模块。



通常,有三种方法可以解决这个问题:


  1. 让每个项目都有自己的库副本。这是如果你用 - 递归克隆项目会发生什么情况。很显然,这是浪费的,并且在一次处理多个项目时可能会引起混淆。

  2. 不要克隆或注册子模块(即离开它作为默认情况下git创建的空白目录),并配置构建工具以在其他地方查找子模块。除此之外,这也有一个缺点,即子模块中的新提交不会在父项目的 git status 输出中看到,并且您不能轻松 git add 新的子模块状态。
  3. 将库存储库作为子模块目录中的别名访问。在Windows上,这是可以使用接点实现的;在Linux上,符号链接不起作用(git认为你删除了子模块并用符号链接替换了它),但是 - bind 挂载确实可行。尽管版本库布局不同( lib / .git )是一个真正的gitdir,而不是指向 ../。git / modules / lib / ),这工作正常,但创建绑定挂载很烦人,并且需要 sudo 访问权。


有没有更好的方法来做到这一点,即告诉git在文件系统的其他地方寻找子模块的存储库?

$ b $你可以做的是将子模块与 file:// 协议一起使用,这样它会指向所需的文件夹。但它只会在本地机器上运行。



这也称为本地协议

https://git-scm.com/book/ch4-1.html#Local-Protocol


最基本的是本地协议,远程仓库在磁盘上的另一个目录

如果团队中的每个人都可以访问共享文件系统(如NFS挂载),或者每个人都登录到同一台计算机的可能性较小。后者并不理想,因为所有代码库实例都驻留在同一台计算机上,导致灾难性损失的可能性大大增加。



I have a library, which I use in multiple projects as a git submodule.

Generally, there's three ways one can go about this:

  1. Let each project have its own copy of the library. This is what happens if you clone the projects with --recursive. Obviously, this is wasteful, and can get confusing when working on more than one project at a time.

  2. Don't clone or register the submodule (i.e. leave it as the blank directory that git creates by default), and configure your build tools to look for the submodule elsewhere. Aside this complication, this also has the downside that new commits in the submodule will not be seen in the parent projects' git status output, and you can't easily git add the new submodule state.

  3. Make the library repository accessible as an alias in the submodule directory. On Windows, this is achievable using junction points; on Linux, symlinks don't work (git thinks you deleted the submodule and replaced it with a symlink), but --bind mounts do work. Although the repository layout is different (lib/.git is a real gitdir instead of just a file pointing to the one in ../.git/modules/lib/), this works fine, but creating the bind mount is annoying and does require sudo access.

Is there a better way to do this, i.e. tell git to look for a submodule's repository elsewhere on the filesystem?

解决方案

What you can do is to use the submodule with the file:// protocol so it will be pointing to the desired folder. but it will only work on your local machine.

This is also known as the local protocol
https://git-scm.com/book/ch4-1.html#Local-Protocol

The most basic is the Local protocol, in which the remote repository is in another directory on disk.

This is often used if everyone on your team has access to a shared filesystem such as an NFS mount, or in the less likely case that everyone logs in to the same computer. The latter wouldn’t be ideal, because all your code repository instances would reside on the same computer, making a catastrophic loss much more likely.

这篇关于保持子模块在工作树外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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