用于功能分支和通用代码的 Git 分支策略

发布于 2024-10-20 01:42:53 字数 491 浏览 3 评论 0原文

我一直在使用此处概述的 git 分支策略 http://nvie.com /posts/a-successful-git-branching-model/

到目前为止,它对我来说效果非常好。

我经常问自己的问题是,在开发功能分支时,我最终需要实现与整个项目相关的代码。处理这些情况的最佳方法是什么?

a) 检查主开发分支,提交更改并重新建立开发分支的功能基础。

b) 在功能分支上进行更改,然后合并回开发中,以便其他功能分支可以访问该代码。

c) 为公共代码创建一个新分支,并将其合并到 Develop 以及需要使用它的任何功能分支中。

这是另一个问题。您多久将一个功能分支合并回主开发分支?您是否会等到该功能完全完成后再合并并删除它?或者,在其生命周期内,只要它稳定,您是否会多次合并回开发中?

I've been using the git branching strategy outlined here http://nvie.com/posts/a-successful-git-branching-model/

So far its been working really well for me.

The question I often find my self asking is while working on a feature branch I'll end up needing to implement code that is relevant to the entire project. What is the best way to handle these situations?

a) Check out the main development branch, commit the change and rebase the feature branch off of develop.

b) Make the change on the feature branch, then merge back into develop so that other feature branches can have access to that code.

c) Create a new branch for the common code and merge that into Develop as well as any feature branches that need to use it.

Here's another question. How often do you merge a feature branch back into the main development branch? Do you wait until the feature is completely done then merge it and delete it? Or do you merge back into develop several times throughout its lifetime any time that it's stable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生死何惧 2024-10-27 01:42:53

我喜欢选项 a/,但现实是,当您在提交后进行提交时,您只会在该过程的后期才意识到其中一些实际上是常见代码。

当这种情况发生在 feature 分支(通常尚未推送并共享)上时,我更喜欢进行交互式变基,对公共代码的提交重新排序首先,然后将 n 个首次提交的 master 分支合并到 feature 分支(快进合并)。
从那里,我可以将任何其他必须从这些新的通用功能中受益的分支重新定位到 master 上。

仅当该功能分支的状态必须对其他人可见时,合并回功能分支才有意义(因为您希望推送 master 同时保持 feature 分支对您的存储库私有) .
如果开发的其余部分:

  • 可以继续进行,而不需要 feature 分支中的任何部分
  • 可以继续进行,而无需修改一些常见的文件集(这意味着您在 feature 之间等待的时间越长,合并就越困难code>master 和 feature 分支)

,那么我更喜欢稍后合并 feature 分支。

I like option a/, but the reality is, when you are doing commits after commits, you only realize that some of them are actually common code much later in the process.

When that happens on a feature branch (that usually hasn't been pushed yet and shared with), I prefer doing an interactive rebase, re-ordering the commits for common code first, and then merging the master branch to the feature branch for those n first commits (fast-forward merge).
From there, I can rebase onto master any other branch that have to benefit from those new common features.

Merging back a feature branch only makes sense if the state of that feature branch must be visible for others (because you want to push master while keeping feature branch private to your repo).
If the rest of the development:

  • can proceed without needing any part of what is in the feature branch
  • can proceed without modifying some common set of files (which would imply a much harder merge the longer you wait between master and feature branches)

, then I prefer merging feature branch later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文