从 Git 提交两个远程项目
我在 Codeigniter 中有一个项目,通过 Git 和 Github 进行管理,其中包含我用于所有 CI 项目的“样板”自定义和库(如集中式渲染库)——我们称之为“基线”。
在我开发和完善 Baseline CI 项目的同时,我也在开发当前的客户端项目,我们将其称为“客户端”。
我的问题是 - 同时开发基线项目和客户项目的最有效方法是什么?例如,我可以在客户端项目中创建一个新的控制器和模型,然后添加新的帮助器、一些通用视图,并添加到我认为需要添加到基线中的几个库。我是否需要执行两次提交,一次提交给基线(并将其推送到远程基线存储库),然后再次提交给客户端项目?
我一直在试图弄清楚如何使用子模块或分支来完成同样的事情,但子模块似乎需要在 Git 中拥有自己的目录结构,并且对于分支,我不确定它是如何工作的。
帮助?
I have a project in Codeigniter, managed via Git and Github, that consists of my 'boilerplate' customizations and libraries (like a centralized Render library) that I use for all of my CI projects - let's call that 'Baseline'.
At the same time that I'm developing and refining the Baseline CI project, I'm also developing the current client project, which we'll call 'Client'.
My question is - what's the most efficient way to develop both the Baseline project and the client project simultaneously? For example, I may create a new controller and model in the Client project, but then add new helpers, some generic views and add to a couple of the libraries that I think need to be added to Baseline. Do I need to perform two commits, one for the Baseline (and push that to the remote Baseline repo), then commit again for the Client project?
I've been trying to figure out how to use submodules or branching to accomplish the same thing, but submodules seem to require their own directory structure in Git, and with branching I'm not sure how it would work.
Help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为我猜测子模块所需的单独目录结构设置不适合您,所以我建议如下:
拥有一个存储库 (A),它是您的“基准”项目。在该存储库中的基线上完成所有工作,然后将其提交到那里。
将该存储库克隆到另一个存储库 (B),并在那里完成客户端项目的所有工作。将 (A) 保留为远程(如果您
git clone (A)
,它将自动设置为origin
;您可以将 github 远程添加为github
而不是origin
)。然后,当您对基线 (A) 存储库进行更新时,将它们提交到 (A),然后使用 git pull 将它们从 (A) 拉取到 (B)。 (切勿从 (B) 推送到 (A),因为您不希望基线存储库中包含客户端代码。)
所以,是的,您需要分别提交基线更新和客户端更新,但您不必这样做提交相同的代码两次。
Since I'm guessing the separate-directory-structures setup that submodules require is no-go for you, here's what I'd suggest instead:
Have one repository (A) that is your "baseline" project. Do all of your work on the baseline in that repository, and commit it there.
Clone that repository to another, (B), and do all of your work for the client project there. Keep (A) as a remote (if you
git clone (A)
, it'll be set asorigin
automatically; you could add the github remote asgithub
instead oforigin
).Then, when you make updates to the baseline (A) repository, commit them to (A), and then use
git pull
to pull them from (A) to (B). (Never push from (B) to (A), since you don't want client code in the baseline repo.)So yes, you will need to commit your baseline updates and your client updates separately, but you won't have to commit the same code twice.
我建议使用分支或子模块。
对于分支,您将拥有一个
baseline
分支和一个client
分支。每当您在更新baseline
后切换到client
时,请将baseline
合并到client
中。对于子模块,任一存储库都可以是顶级模块,而另一个存储库可以是其子模块。两种布局都有一定的逻辑意义(
baseline
位于顶部,client
依赖于它,因此是一个子布局;而client
位于顶部,它使用baseline
作为一个库,所以这应该是孩子,由你决定)。不过,我会推荐分支。
I would recommend using branches or submodules.
With branches, you would have a
baseline
branch and aclient
branch. Whenever you switch toclient
after updatingbaseline
, mergebaseline
intoclient
.With submodules, either repository could be the top-level module, with the other as its child. Both layouts make some logical sense (with
baseline
on top,client
depends on it and is therefore a child; withclient
on top, it usesbaseline
as a library, so that should be the child; it's up to you).I would recommend the branching, though.