如何让Git知道单个分支中的某些文件是相互分支的

时间:2021-04-09 16:27:08

We have a product with different themes, that are stored in master branch like this

我们有一个具有不同主题的产品,存储在这样的主分支中

themes/theme_one/...
themes/theme_two/...
etc

Each folder has its own structure and keeps CSS and HTML files. Sometimes one of our customers wants to have a custom theme. Since we have a wide variety of themes, there is usually one that is highly similar to what customer needs and which requires cosmetic changes only. So what I usually do is create a branch new_customer, switch to that branch, copy the theme of choice (e.g. themes/theme_two/ -> themes/custom_theme/) and modify it, applying the changes the customer needs. Sometimes the changes are minimal, sometimes they are larger but the resultant theme still heavily inherits from its parent.

每个文件夹都有自己的结构,并保留CSS和HTML文件。有时,我们的一位客户希望拥有自定义主题。由于我们有各种各样的主题,通常有一个与客户需求高度相似,只需要进行外观修改。所以我通常做的是创建一个分支new_customer,切换到该分支,复制选择的主题(例如themes / theme_two / - > themes / custom_theme /)并修改它,应用客户需要的更改。有时候这些变化是最小的,有时它们会变大,但结果主题仍然大量继承自其父级。

What is the most efficient way to organize that? Suppose we've noticed some random bugs in themes/theme_two/ and applied the fixes. Is theme some way to tell Git that themes/custom_theme/ is in reality something like a branch from themes/theme_two/ and all the changes should be reapplied there as well (even though they still exist in the context of their respective branches - master and new_customer).

组织它的最有效方法是什么?假设我们已经注意到themes / theme_two /中的一些随机错误并应用了修复程序。主题是某种方式告诉Git,themes / custom_theme /实际上就像来自themes / theme_two /的分支,所有的更改也应该在那里重新应用(尽管它们仍然存在于各自分支的上下文中 - master和新客户)。

Some time ago I was reading a book on Git and I vaguely remember something about submodules. Is it the classical way to solve such a problem and if yes, how will it work? Will I do something like this - set up a separate repo for themes (may be a branch for each theme) and then in main product master create themes/.../ folders and link them to respective theme branches. Then when I'll need to create a custom theme, I'll create a some_customer branch from main products's master, create a branch from the other repo's theme_two branch and load it as a submodule into themes/custom_theme/ of the new_customer branch?

前段时间我正在读一本关于Git的书,我依旧记得一些关于子模块的东西。这是解决这个问题的经典方法吗?如果是,它将如何运作?我会做这样的事情 - 为主题设置一个单独的repo(可能是每个主题的分支),然后在主产品master中创建主题/.../文件夹并将它们链接到各自的主题分支。然后,当我需要创建一个自定义主题时,我将从主要产品的主人创建一个some_customer分支,从另一个repo的theme_two分支创建一个分支,并将其作为子模块加载到new_customer分支的themes / custom_theme /中?

1 个解决方案

#1


0  

I would think the best way would be to do branch per theme and always merge from theme_two into custom_theme. There is no way I know of to merge part of a git directory hierarchy -- and no way to record such a partial merge.

我认为最好的方法是每个主题分支,并始终从theme_two合并到custom_theme。我不知道合并git目录层次结构的一部分 - 并且无法记录这样的部分合并。

#1


0  

I would think the best way would be to do branch per theme and always merge from theme_two into custom_theme. There is no way I know of to merge part of a git directory hierarchy -- and no way to record such a partial merge.

我认为最好的方法是每个主题分支,并始终从theme_two合并到custom_theme。我不知道合并git目录层次结构的一部分 - 并且无法记录这样的部分合并。