{"id":2165,"date":"2018-06-09T23:03:20","date_gmt":"2018-06-09T15:03:20","guid":{"rendered":"http:\/\/www.brofive.org\/?p=2165"},"modified":"2018-12-16T22:32:41","modified_gmt":"2018-12-16T14:32:41","slug":"%e4%bb%a3%e7%a0%81%e5%88%86%e6%94%af%e6%a8%a1%e5%9e%8b%ef%bc%9agitflow%e3%80%81github-flow%e3%80%81trunk-based-development","status":"publish","type":"post","link":"http:\/\/www.brofive.net\/?p=2165","title":{"rendered":"Git \u4ee3\u7801\u5206\u652f\u6a21\u578b\uff081\uff09\uff1aGitFlow\u3001GitHub Flow\u3001Trunk Based Development"},"content":{"rendered":"<p>\u6700\u8fd1\u548c\u9879\u76ee\u7ec4\u51e0\u4f4d\u540c\u5fd7\uff08WBH\u3001CLF\u3001QEN\uff09\u8ba8\u8bba\u4e86\u4ee3\u7801\u5206\u652f\u6a21\u578b\u3002\u91cd\u70b9\u8ba8\u8bba\u4e863\u79cd\u6a21\u578b\uff0c\u7279\u522b\u662f\u8ba8\u8bba\u4e86GitFlow\u7684\u9002\u7528\u6027\u3002<\/p>\n<p><em>\u672c\u7cfb\u5217\u4e00\u51713\u7bc7\u6587\u7ae0\uff1a<\/em><\/p>\n<p><em><a href=\"http:\/\/www.brofive.net\/?p=2165\">\uff081\uff09GitFlow\u3001GitHubFlow \u548c TBD<\/a><\/em><\/p>\n<p><em><a href=\"http:\/\/www.brofive.net\/?p=2233\">\uff082\uff09GitLab Flow<\/a><\/em><\/p>\n<p><em><a href=\"http:\/\/www.brofive.net\/?p=4352\">\uff083\uff09Atlassian Simple Git Flow &amp; Google Upstream<\/a><\/em><\/p>\n<p>\u4e00\u3001GitFlow\u6a21\u578b\u3002<a href=\"https:\/\/nvie.com\/posts\/a-successful-git-branching-model\/\">Vincent Driessen\u57282010\u5e74\u63d0\u51fa\u7684GitFlow\u6a21\u578b\u3002<\/a>\u8fd9\u4e2a\u6a21\u578b\u7684\u7279\u70b9\u662f\u53ea\u67092\u4e2a\u4e3b\u5e72\u5206\u652f\uff0cMaster\u548cDevelop\u5206\u652f\uff1aMaster\u5206\u652f\u4e0a\u53ea\u6709\u7a33\u5b9a\u7684\u751f\u4ea7\u7248\u672c\uff0cDevelop\u5206\u652f\u7528\u4e8e\u96c6\u6210\u3002\u5176\u4e2d\u8fd8\u6d89\u53ca\u5230HotFix\u5206\u652f\u3002\u800c\u5176\u4ed6\u8fd8\u6709\u4e09\u7c7b\u5206\u652f\uff1aFeature\u5206\u652f\u7528\u4e8e\u5f00\u53d1\u4eba\u5458\u5404\u81ea\u5f00\u53d1\uff1bRelease\u7528\u4e8e\u4ee3\u7801\u5408\u5e76\u548c\u96c6\u6210\uff1bHotFix\u7528\u4e8e\u4ea7\u54c1\u7248\u672c\u4ee3\u7801\u7684\u7d27\u6025\u4fee\u8ba2\u3002\u4e0b\u56fe\u662f\u7ecf\u5178\u7684\u6a21\u578b\u56fe<\/p>\n<p><a href=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/clip_image001-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border: 0px;\" title=\"clip_image001\" src=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/clip_image001_thumb-2.png\" alt=\"clip_image001\" width=\"552\" height=\"712\" border=\"0\"><\/a><\/p>\n<p>\u4e0d\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\uff0cThoughtWorks\u8fd9\u4e9b\u5e74\u4e00\u76f4\u5728\u62a8\u51fbGitFlow\u6a21\u578b\uff0c\u4e00\u5e74\u6bd4\u4e00\u5e74\u4e25\u8083\uff0c\u540e\u9762\u6211\u4eec\u4f1a\u5206\u6790\u4e00\u4e0b\u5982\u4f55\u4f18\u5316\uff1b<\/p>\n<p>2011\u5e74\uff1a\u505c\u7528GitFlow\u7684Feature\u5206\u652f<\/p>\n<p>Disappointingly, we continue to see development teams embrace the practice of feature branching to isolate work and defer integration. Feature branches commonly cause significant pain and unpredictability during late merges, but more importantly prevent the continual design improvement necessary to maintain high quality software. We recommend continuous integration and branch by abstraction as an alternative to feature branching.<\/p>\n<p>2015\u5e74\uff1a\u505c\u7528GitFlow\u7684\u957f\u65f6\u5206\u652f<\/p>\n<p>Gitflow is a strict branching pattern for releases using Git. Although not an inherently bad pattern, we often see it misused. If the feature and develop branches are short lived and merged often, you are really using the power of Git, which makes these activities easy. However, a problem we often see is that these become long lived branches, which results in the dreaded merge conflicts many people began using Git to escape. A merge is a merge. Regardless of the source control tool or pattern you use. If you wait more than a day or two to merge, you could hit a big merge conflict. This becomes a real issue if you have a larger team. If you have more than a few people waiting to merge, you can have a serious a bottleneck. Introducing patterns like Gitflow require the discipline to merge often to be successful. So by all means use the pattern, but only if you have the discipline to prevent long lived branches<\/p>\n<p>2016\u5e74\uff1a\u505c\u7528GitFlow<\/p>\n<p>We firmly believe that long-lived version-control branches harm valuable engineering practices such as continuous integration, and this belief underlies our dislike for Gitflow. We love the flexibility of <a href=\"https:\/\/git-scm.com\/\">Git<\/a> underneath but abhor tools that encourage bad engineering practices. Very short-lived branches hurt less, but most teams we see using Gitflow feel empowered to abuse its branch-heavy workflow, which encourages late integration (therefore discouraging true continuous integration).<\/p>\n<p>\u8fd9\u4e9b\u5185\u5bb9\u7684\u6838\u5fc3\u5728\u4e8eGitFlow\u91cd\u89c6\u7ba1\u7406\uff0c\u5f3a\u8c03\u591a\u5206\u652f\u5f00\u53d1\uff0c\u4f1a\u9020\u6210\u96c6\u6210\u6ede\u540e\uff0c\u5408\u5e76\u56f0\u96be\uff0c\u5f71\u54cd\u6301\u7eed\u96c6\u6210\u3002\u57282016\u5e74\u53d1\u5e03\u7684\u6587\u7ae0\u4e2d\uff0cTW\u7ed9\u51fa\u4e86\u51e0\u4e2a\u5176\u4ed6\u7684\u5efa\u8bae\uff0c\u5305\u62ec\u63a8\u8350GitHub Flow\u548cTrunk-Based Developmeng<\/p>\n<p>\u4e8c\u3001GitHub Flow\u3002\u8fd9\u4e2a\u662fGitHub\u7684Scott Chacon\u4e8e2011\u5e74\u63d0\u51fa\u7684\uff0c\u9488\u5bf9\u7684\u5c31\u662fGitFlow\u3002\u4f46\u662f\u5176\u4e2d\u4e3b\u8981\u95ee\u9898\u5e76\u4e0d\u662f\u9488\u5bf9GitFlow\uff0c\u800c\u662f\u9488\u5bf9\u6709\u4eba\u5f00\u53d1\u7684GitFlow Script\uff0c\u8fd9\u4e9bScript\u7528\u4e8e\u76f8\u5bf9\u5f3a\u5236\u6027\u5730\u6267\u884cGitFlow\u89c4\u5219\uff0c\u4f46\u662f\u4ec5\u652f\u6301\u547d\u4ee4\u884c\uff0c\u56e0\u6b64\u88ab\u5f88\u591a\u4eba\u5410\u69fd\u3002Scott\u7ed9\u51fa\u4e86GitHub\u7684\u6a21\u578b\uff0c\u5373GitHub Flow\u3002GitHub Flow\u5e0c\u671b\u9488\u5bf9\u7684\u573a\u666f\u662f\u6bcf\u5929\u53d1\u5e03\u51e0\u6b21\u4ea7\u54c1\u4ee3\u7801\u7684\u573a\u666f\uff08\u4e2a\u4eba\u8ba4\u4e3a\u8fd9\u662fDevOps\u573a\u666f\uff0c\u800c\u4e0d\u662f\u4ea7\u54c1\u4ea4\u4ed8\u578b\u573a\u666f\uff09\uff0c\u5e0c\u671b\u91c7\u7528\u654f\u6377\u7684\u573a\u666f\u6bcf\u5929\u591a\u6b21\u89e3\u51b3\u5c0f\u95ee\u9898\u3002<\/p>\n<p>GitHub Flow\u53ea\u6709Master\u548cFeature\u5206\u652f\uff0c\u76f8\u5f53\u4e8e\u628aGitFlow\u7684Master\u548cDevelop\u5206\u652f\u5408\u5e76\u4e3a\u4e00\u4e2a\u5206\u652f\u3002\u6709\u5982\u4e0b6\u4e2a\u73af\u8282\u3002<\/p>\n<ol>\n<li>Anything in the master branch is deployable<\/li>\n<li>To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes)<\/li>\n<li>Commit to that branch locally and regularly push your work to the same named branch on the server<\/li>\n<li>When you need feedback or help, or you think the branch is ready for merging, open a pull request<\/li>\n<li>After someone else has reviewed and signed off on the feature, you can merge it into master<\/li>\n<li>Once it is merged and pushed to \u2018master\u2019, you can and should deploy immediately<\/li>\n<\/ol>\n<p>GitHub Flow\u7684\u4f7f\u7528\u573a\u666f\uff1a<\/p>\n<p>GitHub is 35 employees now, maybe 15-20 of whom work on the same project (github.com) at the same time. I think that most development teams &#8211; groups that work on the same logical code at the same time which could produce conflicts &#8211; are around this size or smaller.<\/p>\n<p>\u4e09\u3001Trunk Based development\u3002\u8fd9\u662f<a href=\"https:\/\/paulhammant.com\/2013\/04\/05\/what-is-trunk-based-development\/\">Paul Hammant 2013\u5e74\u63d0\u51fa\u7684\u6a21\u578b<\/a>\uff0c\u8fd9\u4e2a\u6a21\u578b\u4e0d\u7528\u591a\u89e3\u91ca\uff0c\u57fa\u672c\u5c31\u662fSVN\u7684\u6a21\u578b\uff0c\u5728TBD\u6a21\u578b\u4e2d\uff0c\u6240\u6709\u5f00\u53d1\u90fd\u5728\u4e3b\u5e72\uff0c\u4f46\u662f\u62c9\u51fa\u65b0\u7684\u5206\u652f\u4ea4\u4ed8\u3002\u8fd9\u4e2a\u573a\u666f\u4e0b\uff0c\u5047\u8bbe\u6240\u6709\u7684\u7279\u6027\u5f00\u53d1\u90fd\u53ef\u4ee5\u5feb\u901f\u5b8c\u6210\uff0c\u8fd9\u6837\u5c31\u4e0d\u4f1a\u5f71\u54cdCI\u3002<\/p>\n<p><a href=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/clip_image002-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border: 0px;\" title=\"clip_image002\" src=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/clip_image002_thumb-2.png\" alt=\"clip_image002\" width=\"780\" height=\"521\" border=\"0\"><\/a><\/p>\n<p>\u7406\u8bba\u4e0a\uff0cTBD\u5355\u4e3b\u5e72\u5f00\u53d1\u548c\u654f\u6377\u6838\u5fc3\u8981\u6c42\u6bd4\u8f83\u5339\u914d\uff1a<\/p>\n<ol>\n<li>You\u2019ve broken your application into multiple components.<\/li>\n<li>Each component into a directory inside the trunk (possibly hierarchical).<\/li>\n<li>Each directory its own source self-contained and its own build (possibly hierarchical).<\/li>\n<li>You have a good set of unit tests and consider them important enough to illustrate snippets of example usage.<\/li>\n<li>Continuous Integration drives things, even for hundreds of components, that drops items into a Maven-like repository. <a href=\"http:\/\/cruisecontrol.sourceforge.net\/\">CruiseControl<\/a> has a nice <a href=\"http:\/\/cruisecontrol.sourceforge.net\/main\/configxml.html#httpfile\">&lt;httpfile\/&gt;<\/a> directive that with the <a href=\"http:\/\/cruisecontrol.sourceforge.net\/main\/configxml.html#include.projects\">&lt;include-projects\/&gt;<\/a> directive that allows you to set up the killer CI installation that is branch-ready meaning you can run without a dedicated CI administrator.<\/li>\n<li>Your management are good at release planning.<\/li>\n<li>Developers are in the habit of never breaking the build \ud83d\ude42<\/li>\n<\/ol>\n<p>\u4f46\u662f\u9488\u5bf9\u5927\u578b\u53d8\u66f4\u7684\u65f6\u5019\uff08\u5982\u66ff\u6362\u67d0\u4e2d\u95f4\u4ef6\uff09\uff0c\u4e0a\u8ff0\u6d41\u7a0b\u88ab\u6253\u4e71\u4e86\uff0c\u56e0\u6b64\u63d0\u51fa\u4e86BBA\uff08Branch By Abstraction\uff09<\/p>\n<ol>\n<li>Introduce an abstraction over the core bits of the big thing you\u2019re going to change and commit<\/li>\n<li>Update all the bits of code that were formerly using the thing directly to use it via the new abstraction and commit<\/li>\n<li>Make a second implementation of the abstraction, with unit tests that specifically test its core functionality and commit<\/li>\n<li>Update all the code from (2) to use the new implementation (still via the abstraction)* and commit<\/li>\n<li>Deprecate the first implementation (or skip to 6 if you don\u2019t want a respectful grace period).<\/li>\n<li>Delete the first implementation (its proven there is no need for you to go back).<\/li>\n<li>Remove the abstraction (if it is inelegant).<\/li>\n<\/ol>\n<p>\u8fd9\u4e2a\u662f\u4e00\u79cd\u67b6\u6784\u4e0a\u7684\u62bd\u8c61\u5c42\u8bbe\u8ba1\uff0c\u53ef\u4ee5\u8ba9\u539f\u6709\u4e0d\u76f8\u5173\u6a21\u5757\u7ee7\u7eed\u5f00\u53d1\uff0c\u800c\u4ec5\u53d8\u5316\u76f4\u63a5\u76f8\u5173\u7684\u6a21\u5757<\/p>\n<p>\u7b80\u8981\u6bd4\u8f83\u4e00\u4e0b\u4e0a\u97623\u79cd\u6a21\u578b\uff1a<\/p>\n<p><a href=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/image-45.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; border: 0px;\" title=\"image\" src=\"http:\/\/www.brofive.net\/wp-content\/uploads\/2018\/06\/image_thumb-45.png\" alt=\"image\" width=\"910\" height=\"397\" border=\"0\"><\/a><\/p>\n<p>\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/nvie.com\/posts\/a-successful-git-branching-model\/\">GitFlow\uff1aA successful Git branching model 2010<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/nvie\/gitflow\">\u652f\u6301GitFlow\u6a21\u578b\u7684\u811a\u672c<\/a><\/li>\n<li><a href=\"http:\/\/insights.thoughtworks.cn\/gitflow-consider-harmful\/\">ThoughtWorks 2016\uff1aGitFlow\u6709\u5bb3\u8bba<\/a><\/li>\n<li><a href=\"https:\/\/www.thoughtworks.com\/radar\/techniques\/feature-branching\">ThoughtWorks 2011\uff1a\u505c\u7528Feature \u5206\u652f<\/a><\/li>\n<li><a href=\"https:\/\/www.thoughtworks.com\/radar\/techniques\/long-lived-branches-with-gitflow\">ThoughtWorks 2015\uff1a\u505c\u7528\u957f\u65f6\u5206\u652f<\/a><\/li>\n<li><a href=\"https:\/\/www.thoughtworks.com\/radar\/techniques\/gitflow\">ThoughtWorks 2016\uff1a\u505c\u7528GitFlow<\/a><\/li>\n<li><a href=\"http:\/\/scottchacon.com\/2011\/08\/31\/github-flow.html\">GitHub Flow 2012<\/a><\/li>\n<li><a href=\"https:\/\/paulhammant.com\/2013\/04\/05\/what-is-trunk-based-development\/\">Trunkbased Development 2013<\/a><\/li>\n<li><a href=\"https:\/\/paulhammant.com\/categories.html#Branch_by_Abstraction,_etc\">Branch by Abstraction, etc<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u548c\u9879\u76ee\u7ec4\u51e0\u4f4d\u540c\u5fd7\uff08WBH\u3001CLF\u3001QEN\uff09\u8ba8\u8bba\u4e86\u4ee3\u7801\u5206\u652f\u6a21\u578b\u3002\u91cd\u70b9\u8ba8\u8bba\u4e863\u79cd\u6a21\u578b\uff0c\u7279\u522b\u662f\u8ba8\u8bba\u4e86GitFlo&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2160,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156,237,300],"tags":[406,408,407,409],"views":14855,"_links":{"self":[{"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/posts\/2165"}],"collection":[{"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.brofive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2165"}],"version-history":[{"count":6,"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/posts\/2165\/revisions"}],"predecessor-version":[{"id":6630,"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/posts\/2165\/revisions\/6630"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.brofive.net\/index.php?rest_route=\/wp\/v2\/media\/2160"}],"wp:attachment":[{"href":"http:\/\/www.brofive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.brofive.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2165"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.brofive.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}