本地仓库作为子模块

6
假设我有一个名为Shared Features的仓库,它在远程和本地都存在。
我想将此仓库作为子模块添加到另一个git仓库中,但是我想使用本地仓库而不是远程仓库(出于带宽原因)。
因此,我想将此本地仓库作为子模块和远程仓库之间的代理。这可能吗?
提前致谢。
注意:如果您告诉我如何在SourceTree中完成此操作,我将非常感激。
编辑:我认为我缺乏术语来清楚地表达我的问题,所以在这里我画出了我的意思:
在此输入图片描述
1个回答

5

子模块可以是任何你喜欢的仓库,但如果你想本地添加它,你需要一个支持的协议

在上面的链接中,第一个描述的协议是本地协议(Local protocol),它允许你使用路径(path)file://克隆(clone)

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.

If you have a shared mounted filesystem, then you can clone, push to, and pull from a local file-based repository.

To clone a repository like this or to add one as a remote to an existing project, use the path to the repository as the URL.

For example, to clone a local repository, you can run something like this:

git clone /opt/git/project.git

Or you can do this:

git clone file:///opt/git/project.git

Git operates slightly differently if you explicitly specify file:// at the beginning of the URL.

If you just specify the path, Git tries to use hardlinks or directly copy the files it needs.

If you specify file://, Git fires up the processes that it normally uses to transfer data over a network which is generally a lot less efficient method of transferring the data.

The main reason to specify the file:// prefix is if you want a clean copy of the repository with extraneous references or objects left out – generally after an import from another version-control system or something similar (see Git Internals for maintenance tasks). We’ll use the normal path here because doing so is almost always faster.

To add a local repository to an existing Git project, you can run something like this:

git remote add local_proj /opt/git/project.git

Then, you can push to and pull from that remote as though you were doing so over a network.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接