Git 流——从另一个特性分支创建特性分支

我使用 git flow已经有一段时间了,我很想了解一个特定的用例。

对于我的一个项目,我有一个新的网站功能票。此票据依赖于许多子任务。我想为主票据创建一个特性分支,然后为每个子任务在父特性分支之外创建一个特性分支。

让我们假设我有一张票 PROJ-500,并且我为它创建了一个功能分支

git flow feature start PROJ-500

然后我想整合门票 PROJ-501通过 PROJ-515PROJ-500之前,整个事情集成到 develop。有没有什么方法可以让我

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

然后随着时间的推移,这些子任务完成,当它们的特性完成时,分支就合并到 PROJ-500中。

git flow feature finish PROJ-511

上面的命令将把 PROJ-511合并到 PROJ-500

一旦所有的子任务完成,然后 PROJ-500将完成并合并到 develop

通过这种方式,新的网站功能被整合为一个单元而不是零碎的开发。

58323 次浏览

Update (November 5, 2020): As noted in the newer answer here, this is possible with gitflow-avh which has replaced the original git flow.

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

Original Answer:

I don't think there is a method for this in git flow, but it is fairly simple with just 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

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

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.

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. 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. 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.

As I understood, gitflow is quite abandoned.

gitflow-avh replaces it and offers this feature (see 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.

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 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 config set develop develop

Simply you can make it from a base feature or even a branch as you like

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