Git flow - 从另一个功能分支创建功能分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22948747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git flow - create feature branch off another feature branch
提问by pymarco
I having been using git flow
for a while now. I am curious to learn about a specific use case.
我已经使用git flow
了一段时间了。我很想了解一个特定的用例。
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
. Is there a way for me to do something like
然后我想整合门票PROJ-501
通过PROJ-515
到PROJ-500
整个事情纳入前develop
。有没有办法让我做类似的事情
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.
通过这种方式,新的网站功能作为一个整体而不是零散地集成到开发中。
回答by kriegaex
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
. Ergo sub-features are not supported, you need to do it manually.
该功能将合并到develop
. 不支持Ergo子功能,您需要手动完成。
Alternatives:The requirement is not new, though. There is an open issueas well as a fork projectclaiming to support finishing features into branches other than develop
. I also found a pull requestwith an implementation of that feature. You might want to try that modification and see if you are happy with it.
替代方案:不过,该要求并不新鲜。有一个未解决的问题以及一个fork 项目声称支持将功能整理到develop
. 我还发现了一个带有该功能实现的拉取请求。您可能想尝试这种修改,看看您是否满意。
Update 2019-12-13:As user Matěj K?í?just mentioned in his comment, user Tony Chemithas written an answer herea few months after mine, pointing to gitflow-avhas an alternative to the original gitflow product. 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. I.e. for Windows users it just works right after Git installation.
2019-12-13 更新:作为用户Matěj K?í? 刚刚在他的评论中提到,用户Tony Chemit在我几个月后在这里写了一个答案,指出gitflow-avh作为原始 gitflow 产品的替代品。它使用上面显示的语法支持开箱即用的子功能。几年过去了,现在 AVH 版本是 Windows 版 Git 正常安装的一部分,我刚刚在我的本地机器上验证了这一点并测试了子功能选项。即对于 Windows 用户,它在 Git 安装后就可以正常工作。
回答by Tony Chemit
As I understood, gitflow is quite abandoned.
据我了解,gitflow 已被弃用。
gitflow-avhreplaces 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-511was merged into feature/PROJ-500.
PROJ-511合并到feature/PROJ-500 中。
回答by César
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. Finally, To restore config, we can run
这样,git flow 会运行所有命令和健全性检查。最后,要恢复配置,我们可以运行
git flow config set develop develop
回答by Derek S
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