简体   繁体   English

Git流程-从另一个功能分支创建功能分支

[英]Git flow - create feature branch off another feature branch

I having been using git flow for a while now.我已经使用git flow有一段时间了。 I am curious to learn about a specific use case.我很想了解一个特定的用例。

For one of my projects I have a ticket for a new website feature.对于我的一个项目,我有一张新网站功能的门票。 This ticket depends on many sub-tasks.这张票取决于许多子任务。 I would like to create a feature branch for the main ticket, and then for each sub-task create a feature branch off of the parent feature branch.我想为主工单创建一个功能分支,然后为每个子任务从父功能分支创建一个功能分支。

Let's assume I have a ticket PROJ-500 and I create a feature branch for it假设我有一张票 PROJ-500 并为它创建了一个功能分支

git flow feature start PROJ-500

Then I want to integrate tickets PROJ-501 through PROJ-515 into PROJ-500 before integrating the whole thing into develop .然后我想将票PROJ-501PROJ-515集成到PROJ-500中,然后再将整个东西集成到develop中。 Is there a way for me to do something like有没有办法让我做类似的事情

git flow feature start PROJ-511 -b PROJ-500

Then over time these sub-tasks get completed and when their feature is finished, the branch is merged into PROJ-500 .然后随着时间的推移,这些子任务完成,当它们的功能完成时,分支被合并到PROJ-500中。

git flow feature finish PROJ-511

The above command would merge PROJ-511 into PROJ-500上述命令会将PROJ-511合并到PROJ-500

And once all sub-tasks are completed then PROJ-500 will be finished and merged into develop .一旦所有子任务完成, PROJ-500将完成并合并到develop中。

This way the new website feature is integrate into develop as a single unit rather than piecemeal.这样,新的网站功能就可以作为一个单独的单元而不是零碎地集成到开发中。

You can create a sub-feature branch via您可以通过创建子功能分支

git flow feature start PROJ-511 feature/PROJ-500

But you cannot use the GitFlow tool to merge the branch back into the main feature branch because if you do但是您不能使用 GitFlow 工具将分支合并回主要功能分支,因为如果这样做

git flow feature finish PROJ-511

the feature will be merged into develop .该功能将合并到develop中。 Ergo sub-features are not supported , you need to do it manually.不支持尔格子功能,您需要手动完成。

Alternatives: The requirement is not new, though.替代方案:不过,这个要求并不新鲜。 There is an open issue as well as a fork project claiming to support finishing features into branches other than develop .有一个未解决的问题以及一个fork 项目,声称支持将功能整理到除develop之外的分支中。 I also found a pull request with an implementation of that feature.我还发现了一个带有该功能实现的拉取请求 You might want to try that modification and see if you are happy with it.您可能想尝试该修改,看看您是否满意。


Update 2019-12-13: As user Matěj Kříž just mentioned in his comment, user Tony Chemit has written an answer here a few months after mine, pointing to gitflow-avh as an alternative to the original gitflow product. 2019 年12 月 13 日更新:正如用户Matěj Kříž刚刚在他的评论中提到的那样,用户Tony Chemit在我的几个月后在这里写了一个答案,指出gitflow-avh作为原始 gitflow 产品的替代品。 It supports sub-features out of the box with the syntax shown above.它使用上面显示的语法支持开箱即用的子功能。 Some years have passed by and nowadays the AVH edition is part of the normal installation of Git for Windows, I just verified this on my local box and tested the sub-feature option.几年过去了,现在 AVH 版本是 Windows 版 Git 正常安装的一部分,我刚刚在我的本地机器上验证了这一点并测试了子功能选项。 Ie for Windows users it just works right after Git installation.即对于 Windows 用户,它只在 Git 安装后立即工作。

As I understood, gitflow is quite abandoned.据我了解,gitflow 已被完全抛弃。

gitflow-avh replaces it and offers this feature (see https://github.com/petervanderdoes/gitflow#creating-featurereleasehotfixsupport-branches ). gitflow-avh替换它并提供此功能(请参阅https://github.com/petervanderdoes/gitflow#creating-featurereleasehotfixsupport-branches )。

I just try it and it works well to me.我只是尝试一下,它对我来说效果很好。

git flow feature start PROJ-511 feature/PROJ-500
git flow feature finish PROJ-511

PROJ-511 was merged into feature/PROJ-500 . PROJ-511被合并到feature/PROJ-500中。

As already mentioned, we can start a new feature using any base branch with如前所述,我们可以使用任何基础分支启动一个新功能

git flow feature start PROJ-511 feature/PROJ-500

And to finish the sub feature we can temporarly change git flow configuration to use our feature branch instead of develop :为了完成子功能,我们可以临时更改 git flow 配置以使用我们的功能分支而不是develop

git flow config set develop feature/PROJ-500 && git flow feature finish PROJ-511

This way, git flow runs all commands and sanity checks.这样,git flow 运行所有命令和完整性检查。 Finally, To restore config, we can run最后,要恢复配置,我们可以运行

git flow config set develop develop 

Update (November 5, 2020): As noted in the newer answer here , this is possible with gitflow-avh which has replaced the original git flow.更新(2020 年 11 月 5 日):正如此处更新的答案中所述,这可以通过 gitflow-avh 替代原始 git 流。

=================== ====================

Original Answer:原答案:

I don't think there is a method for this in git flow, but it is fairly simple with just git.我认为 git flow 中没有这种方法,但仅使用 git 就相当简单。

git checkout PROJ-500
git checkout -b PROJ-511
...do your PROJ-511 work...
git checkout PROJ-500
git merge PROJ-511
git branch -d PROJ-511

简单地说,您可以根据需要从基本功能甚至分支中制作它

git flow feature start new-feature-name original-feature-or-base-branch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM