git子模块,子树或其他 [英] git submodules, subtrees or else
问题描述
可能我误解了git的工作原理,我的目录结构如下:
Probably, i misunderstood how git works, I have my directory structure as follows:
project (git-repo)
project 1 (git-repo)
project 2 (git-repo)
common scripts (git-repo)
所有这些文件夹都有自己的存储库,主要的project
可以具有子存储库,例如project 1
,project 2
,child scripts
.它们可以是子模块或子树.问题,common scripts
包含一些共同的代码,对于同时构建project 1
和project 2
都是必不可少的.保持这种状态最好的策略是什么,这样每个项目都可以独立并且无需在两个地方都保留通用脚本.
All these folders have their own repositories where the main project
can have child repositories such as project 1
, project 2
, child scripts
. They can be submodules or subtree. The problem, the common scripts
contain some of the codes that is common and essential to build both project 1
and project 2
. What can be best strategy to maintain this so that each project can be independent as well as no need to keep common scripts in two places.
推荐答案
我只想离开我已经想到的间接解决方案.在获得其他方法之前,它可能对其他人有用.
I just want to leave the indirect solution that I have figured out. It might be useful for others until getting other approaches.
就目前而言,我不能逃避不将common scripts
文件夹保留在两个位置,但是可以将其保留在一个位置.以下是我目前采用的结构,
For now, I am not able to escape not keeping the common scripts
folder in two places but It is okay to maintain it in one place. Following is the structure I have adopted for now,
project
project 1 (git-repo)
common-script (git-repo/submodule)
project 2 (git-repo)
common-script (git-repo/submodule)
common-script (git-repo)
这样,我就可以在自己的仓库中使用common-script
了,并且可以在每个项目中使用git submodule foreach git pull origin master
并提交该仓库,以便在每个相关项目中都有更新的脚本.
That way, I can work on the common-script
from its own repo and from each of the project I can use git submodule foreach git pull origin master
and commit the repo so that I will have updated script in each of the dependent projects.
这篇关于git子模块,子树或其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!