git flow - 如何在一个功能上暂停开发以在另一个功能上工作

时间:2011-12-20 20:33:36

标签: git git-flow

我是git和git流的新手。我已经阅读了所有各种页面,博客和stackoverflow问题,并在我的日常开发中使用过它。

但有一个问题一直困扰着我,我只是无法绕过它。我知道功能分支应该很小,你启动一个功能,编写它的一部分,然后完成功能。这是每天发生的事情,我明白了。我们只是确保我们的开发分支始终可构建。

但是当我在一个功能中间时,会发生什么事情,它还没有准备好完成,但工作重点会发生变化?我希望能够切换到另一个功能。

例如,我开始一个新功能。

$ git flow feature start yak-Speedup

我编写代码,提交文件等......并且正在取得良好进展。但现在我需要改变我正在进行的工作,主要是因为我需要一个不可用的资源,服务器编码器已经准备好了一两天。我无法完成这项功能,因为它会破坏开发分支。

我想做这样的事情:

$ git flow feature pause yak-Speedup
$ git flow feature start alpaca-Sheering
#write code
$ git flow feature finish alpaca-Sheering
$ git flow feature resume yak-Speedup

确实存在" git flow功能列表"命令意味着我可以同时使用多个功能。但我不知道如何在功能之间创建或切换。实际上,我开始认为这根本不是一个git flow问题,而是一个git问题。

我感谢任何帮助。谢谢!

4 个答案:

答案 0 :(得分:46)

您不需要git flow feature pause yak-Speedup命令(feature pause无论如何都不存在)。您要用来代替git flow feature resume yak-Speedup的命令是git flow feature checkout yak-Speedup;这会让你回到yak-Speedup功能分支继续开发。

执行git flow会显示:

Try 'git flow <subcommand> help' for details.

执行git flow feature help会显示:

usage: git flow feature [list] [-v]
       git flow feature start [-F] <name> [<base>]
       git flow feature finish [-rFk] <name|nameprefix>
       git flow feature publish <name>
       git flow feature track <name>
       git flow feature diff [<name|nameprefix>]
       git flow feature rebase [-i] [<name|nameprefix>]
       git flow feature checkout [<name|nameprefix>]
       git flow feature pull <remote> [<name>]

答案 1 :(得分:4)

晚会,但我的经验是这个......我将git与git flow结合使用..

git flow feature start foo  <<== start
#code, hack and COMMIT
git checkout develop        <<== go back to develop branch.. 
git flow feature start foo2 <<== start a new feature
#code, hack and COMMIT
git checkout feature/foo    <<== go back to foo. NB: using full branch name

通过回归开发我确保我独立于foo并仅使用开发。如果当时还有来自其他功能的提交,我也可以进行任何合并开发....

答案 2 :(得分:0)

你想要的是真正的分支:

git branch feature1 <startingpoint>
git checkout feature1
# hack hack hack, commit commit commit
git branch feature2 <startingpoint>
git checkout feature2
# hack hack hack, commit commit commit
# Oops, urgent request comming in, must switch to stable and patch
git stash
git checkout stable
# patch, commit, push
# back to feature2
git checkout feature2
git stash pop

等等。分支是为此而制作的。

一旦你知道你的功能是好的,就合并到开发和推送。

答案 3 :(得分:0)

使用更明确的模型。这是改进的git流,没有额外的命令:

https://plus.google.com/109096274754593704906/posts/R4qkeyRadLR

这里重要的是你不会从feature1启动feature2。

希望这有帮助。

<强>更新

我在博客上写过这篇文章。希望它更清楚一点:

http://dymitruk.com/blog/2012/02/05/branch-per-feature/