具有共享子存储库的主 GIT 存储库
我使用 RoR 创建了一个基本的管理系统。它具有非常基本的功能,例如用户、角色、安全功能和基本 UI。我想把这个项目放入一个主 GIT 存储库中。
如果我想创建未来的项目,我想使用这个基础项目作为基础。我要创建分支吗?
主项目
主项目 > 子项目#1
主项目 > 子项目#2
因此,此时两个子项目都与主项目相同。如果我想对主项目中的任何文件进行通用代码更改,如何使该更改渗透到所有子项目。这是我的第一个问题。
第二个问题:
如果我想对子项目之一的特定文件进行代码更改怎么办?
例如:如果我自定义 SUB PROJECT #2 (application.html.erb) 中的布局,我希望该更改仅影响 SUB PROJECT #2。我希望所有子项目都使用 MASTER PROJECT 中的 application.html.erb ,除非它已更改(自定义)。如果 SUB PROJECT #2 仅包含一个自定义文件,那就太好了。所有其他丢失的文件都会回退到主项目。
第三个问题:
如果我在主项目中对 application.html.erb 进行更改,则应该将该更改应用到所有子项目,除非其中一个子项目项目已经对该文件进行了自定义更改。在本例中,SUB PROJECT #2 就是如此。
我希望 GIT 要么:
a) 跳过 SUB PROJECT #2 上 application.html.erb 的更新
,或者
b) 提示警告以允许某种合并。
这有道理吗?这个设置可以吗?它会被称为什么?我从哪里开始?
I have created a basic admin system using RoR. It has very basic functionality such as users, roles, security features and a basic UI. I want to put this project into a master GIT repository.
If I want to create future projects, I'd like to use this base project as the foundation. Do I create braches?
MASTER PROJECT
MASTER PROJECT > SUB PROJECT #1
MASTER PROJECT > SUB PROJECT #2
So both sub projects are identical to the master project at this point. If I want to make a universal code change to any file within the MASTER PROJECT, how do I make that change trickle down to all sub projects. That is my FIRST QUESTION.
SECOND QUESTION:
What if I want to make a code change to a particular file on one of the sub projects?
e.g.: If I customize the layout in SUB PROJECT #2 (application.html.erb), I want that change only to affect SUB PROJECT #2. I want all sub projects to use the application.html.erb from MASTER PROJECT UNLESS it has changed (customized). It would be nice if SUB PROJECT #2 only contained the one customized file. All other missing files fallback on MASTER PROJECT.
THIRD QUESTION:
If I make a change to application.html.erb in the MASTER PROJECT, it is supposed to tickle that change down to all sub projects UNLESS one of the sub projects has a customized change to that file already. In this case, SUB PROJECT #2 does.
I'd want GIT to either:
a) Skip the update on application.html.erb on SUB PROJECT #2
OR
b) Prompt a warning to allow for some sort of merge.
Does that make sense? Is this setup possible? What would it be called? Where do i start?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题 1:
您可以使用分支来跟踪此问题。但是,您还应该考虑您需要的是否只是一组模板。
Git 本身不会执行自动合并。您可以编写一个脚本来执行此操作,但否则您需要在每个子项目分支上手动执行
git merge
。问题 2:
您创建的任何分支最初都与您创建分支时的原始分支(主分支)相同。在您提交更改或合并主分支中的更改之前,它不会更改。让此分支仅包含一个自定义文件是没有意义的,因此如果您想使用版本控制分支,您可能需要考虑为什么要这样做。分支可能只包含对一个文件的修改,但没有任何强制措施。
问题 3:
这就是 git 的设计目的。当您在子项目分支上执行 git merge 时,git 将尝试自动合并内容,如果失败,它将标记冲突并允许您手动执行合并。您还可以告诉 git 使用另一种合并策略,例如“保留本地版本”,但这是一种更高级的技术,可能不是您想要的。
我建议您从 git-tutorial 开始,并确保您对分支有很好的理解在 git 中。然后,重新审视这个想法,并确保它对于您想要实现的目标仍然有意义。
Question 1:
You could use branches to track this. However, you should also consider whether what you need is simply a set of templates.
Git does not perform automatic merges by itself. You can write a script to do this, but otherwise you'll need to manually perform a
git merge
on each subproject branch.Question 2:
Any branch you create will initially be identical to the original branch (master), at the time you created the branch. It will not change until you commit changes or merge in changes from the master branch. It wouldn't make sense to have this branch contain only the one customized file, so you may want to consider why you're asking for that if you want to use version control branches. The branch may only contain modifications to the one file, but nothing enforces this.
Question 3:
This is what git is designed for. When you do a
git merge
on the subproject branch, git will try to automatically merge the content and if it fails it will mark a conflict and allow you to manually perform a merge. You can also tell git to use another merge strategy, such as 'keep the local version', but this is a more advanced technique, and probably isn't what you want.I recommend you start with the git-tutorial and make sure you have a good understanding of branching in git. Then, revisit this idea and make sure it still makes sense for what you're trying to acheive.
也许将您的主项目放入其自己的存储库中并为每个项目创建一个新项目是正确的选择。 git 子模块 使您能够将其他存储库集成到项目中。您应该尝试仅在相关存储库中进行项目特定的更改,您可以通过 git 子模块更新主项目的更改!
Maybe it's the right choice to put your master project into its own repository and make a new one for each project. There's git submodule which enables you to integrate other repositories in a project. YOu should try to have project specific changes only in the relating repositories, changes on the master project you can update via git submodule!