是否可以将git remote url设置到存储库中的子文件夹? [英] Is it possible to set git remote url to a sub folder in the repository?

查看:96
本文介绍了是否可以将git remote url设置到存储库中的子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个回购(例如"test"),其文件夹结构为

For a repo (say "test"), that has the folder structure as

├──Project1
├──Project2
├──Project3

├── Project1
├── Project2
├── Project3

我可以只为project1设置一个远程URL吗?

Can I set a remote url for just project1 ?

推荐答案

否,是.也就是说,您可以设置,但是它不会做您想要的,无论可能是什么.

No and yes. That is, you can set this, but it will not do what you want, whatever that may be.

远程只是用作密钥的简称:

A remote is just a short name that acts as a key:

  • origin => remote.origin.urlremote.origin.fetch
  • xyz => remote.xyz.urlremote.xyz.fetch
  • origin => remote.origin.url, remote.origin.fetch
  • xyz => remote.xyz.url, remote.xyz.fetch

,依此类推.您可以将每个这样的键的 url 设置为您喜欢的任何内容:https://example.com/path/to/repo/local/pathjellybeans或任何您喜欢的东西,但是使用的东西值是git fetchgit pushgit ls-remote.这些都以给定的URL与另一个Git存储库联系,并来回传输 commits (不是文件),或者在git ls-remote的情况下,告诉您可用的提交和分支名称.

and so on. You can set the url for each such key to anything you like: https://example.com/path/to/repo or /local/path or jellybeans or whatever you like, but the things that use this value are git fetch, git push, and git ls-remote. These all contact another Git repository at the given URL and transfer commits (not files) back and forth, or in the case of git ls-remote, tell you what commits and branch names are available.

由于git fetchgit push传输了整个提交,文件随同提交一起使用,但是它们具有在提交中为它们赋予的名称

Since git fetch and git push transfer entire commits, files come along with the commits for the ride, but they have the names you gave them in the commits.

但是,您可以在Project1中进行仅包含 个文件的提交.签出这样的提交将删除所有的Project2Project3文件,然后签出一个包含所有文件的提交将带回所有Project3文件.但是,当您运行git pushgit fetch时,您可能会发送和接收包含 all 文件的提交以及包含 only 文件,所以这可能不是一个好主意.

You can, however, make commits that contain only files in Project1. Checking out such a commit will remove all the Project2 and Project3 files, and then checking out a commit that has all the files will bring back all the Project2 and Project3 files. But when you run git push or git fetch, you're likely to send and receive commits that contain all the files along with any commits that contain only the Project1 files, so that's probably not a great idea.

如果将每个项目存储在单独的Git存储库中,则可能会得到所需的内容.尽管我通常建议避免使用子模块,但是您可以将每个存储库都设为单个 superproject 的子模块,该子模块除了协调所有子模块外什么也不做;这个特定的路径是可行的.

If you store each project in a separate Git repository, that will probably get you what you want. Although I generally recommend avoiding submodules, you can make each of these repositories a submodule of a single superproject that does nothing but coordinate all the submodules; this particular path is workable.

这篇关于是否可以将git remote url设置到存储库中的子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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