问题
There are some child projects: "Project 1", "project 2" and so on in the future.
Also, There is a project that named: "Base Project" and it's foundation of other projects. "Base Project" is a content management system (CMS).
All projects have their own git repositories.
"Project 1" , "project 2" and others uses "Base Project" to develop and grow.
There are some methods in git like submodule or subtreemerge. but don't seem to fit here. "Base Project" not should be clone into a sub directory. It's in root directory. It's growing in "project 1" or "project 2"...
When I work in child projects, I have to be able to push "Base Project" changes separately to It's own repository to fetch in other children.
What can I do?
回答1:
Subtree merge or submodules are for a component-based development: two different but coherent set of files combined together.
Each set of files is in its own directory, because they can be branched or labelled independently (submodules), or together (subtree merge, while keeping the ability to get back an history of their own).
Both are requiring a separate directory though.
But what you are describing ("Base Project
" is in root directory, growing in "project 1
" or "project 2
") is about a system-based approach: all components merged into one large component: one large set of file which will always evolve together, as one unit.
So you can have one branch per project: branch1
for CMS-projet1
, branch2
for CMS-project2
, and so on.
But if you need to report projectx
-specific modifications or CMS-specific modifications back to their original (and separate) repos, then make said specific changes in dedicated branches, and then combine those changes:
branchp1
would be for changes affectingproject1
branchc1
would be for changes affectingCMS
branch1
would be the result of the merge frombranchp1
andbranchc1
(same thing for branch2
)
You can then export those changes as patches:
- from
branchp1
toproject1
repo - from
branchc1
toCMS
repo
The inconvenient is that Git won't remember what has already been merged back to the original repos, but that would allow you to report the common history developed in your CMS-projectx
set of files back to your original CMS
and projectx
repos.
Note: if you don't want to manage 2 extra branches, another solution is to:
- make sure each commit only include CMS modification OR project modification
- leave a commit message which helps to distinguish them ("
[CMS] my CMS modification comment...
", or "[Project1] my project1 modification comment...
" - use the script git-extract-patches to export as patches only the right commits.
来源:https://stackoverflow.com/questions/13539636/combine-a-base-project-that-is-growing-in-child-projects-in-git-repository-excep