简体   繁体   English

在另一个git repo中将一个文件夹的git repo分开

[英]Separate git repo for one folder in another git repo

This is my project folder structure. 这是我的项目文件夹结构。 I am using GitLab as my repo site. 我正在使用GitLab作为我的回购网站。 I am using Git v2.17.1 . 我正在使用Git v2.17.1

资料夹结构

I have multiple such projects which have the same structure. 我有多个具有相同结构的此类项目。 In all of them, the src folder should be the same. 在所有这些文件中, src文件夹应相同。 Is it possible to create a separate git repo for src and link it to this repo and the others? 是否可以为src创建一个单独的git repo并将其链接到该repo和其他仓库? How? 怎么样?

You can use git submodules . 您可以使用git子模块

What are Submodules? 什么是子模块?

The concept of submodules is brilliant. 子模块的概念很棒。 It essentially allows you to attach an external repository inside another repository at a specific path 从本质上讲,它允许您在特定路径下将外部存储库附加到另一个存储库中

How to use it? 如何使用它?

  1. Create a separate repo for your src folder. 为您的src文件夹创建一个单独的仓库。
  2. Add the src repo to your every repo that use it: src仓库添加到使用它的每个仓库中:

git submodule add git@mygithost:src localpath/when/submodule/will/be

  1. load the content of the submodule repo: 加载子模块仓库的内容:

git submodule update --init --recursive

  1. If you want to clone the repo with the submodule repo ( src repo) use this command: 如果要使用子模块存储库( src repo)克隆存储库,请使用以下命令:

git clone --recursive [URL to Git repo]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM