{"id":85,"date":"2026-08-07T09:00:00","date_gmt":"2026-08-07T01:00:00","guid":{"rendered":"https:\/\/fsdata.site\/?p=85"},"modified":"2026-08-07T09:00:00","modified_gmt":"2026-08-07T01:00:00","slug":"git-%e6%8f%90%e4%ba%a4%e8%a7%84%e8%8c%83%e4%b8%8e%e5%88%86%e6%94%af%e7%ae%a1%e7%90%86%ef%bc%9a%e4%bb%8e%e6%b7%b7%e4%b9%b1%e6%8f%90%e4%ba%a4%e5%88%b0%e6%a0%87%e5%87%86%e5%8c%96%e5%9b%a2%e9%98%9f-2","status":"publish","type":"post","link":"https:\/\/fsdata.site\/?p=85","title":{"rendered":"Git \u63d0\u4ea4\u89c4\u8303\u4e0e\u5206\u652f\u7ba1\u7406\uff1a\u4ece\u6df7\u4e71\u63d0\u4ea4\u5230\u6807\u51c6\u5316\u56e2\u961f\u5de5\u4f5c\u6d41"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u4f60\u7684 Git \u5386\u53f2\u4e00\u56e2\u7cdf<\/h2>\n<p>\u51e0\u4e4e\u6bcf\u4e2a\u56e2\u961f\u90fd\u7ecf\u5386\u8fc7\u8fd9\u6837\u7684\u63d0\u4ea4\u8bb0\u5f55\uff1a<code>fix<\/code>\u3001<code>fix again<\/code>\u3001<code>\u4e34\u65f6\u63d0\u4ea4<\/code>\u3001<code>\u597d\u50cf\u597d\u4e86<\/code>\u3002\u4e09\u4e2a\u6708\u540e\u60f3\u56de\u6eda\u4e00\u4e2a bug\uff0c<code>git log<\/code> \u7ffb\u4e86\u4e09\u5c4f\u4e5f\u627e\u4e0d\u5230\u5bf9\u5e94\u6539\u52a8\u3002\u95ee\u9898\u4e0d\u5728 Git\uff0c\u800c\u5728\u6ca1\u6709\u4eba\u7ea6\u5b9a\u300c\u600e\u4e48\u63d0\u4ea4\u3001\u600e\u4e48\u5f00\u5206\u652f\u300d\u3002<\/p>\n<p>\u672c\u6587\u7528\u4e24\u6761\u4e3b\u7ebf\u89e3\u51b3\uff1a<strong>\u63d0\u4ea4\u4fe1\u606f\u89c4\u8303\u5316<\/strong>\uff08Conventional Commits\uff09+ <strong>\u5206\u652f\u6a21\u578b\u9009\u62e9<\/strong>\uff08Git Flow \/ Trunk-Based\uff09\uff0c\u8ba9\u4f60\u7684\u4ed3\u5e93\u4ece\u300c\u8003\u53e4\u73b0\u573a\u300d\u53d8\u6210\u300c\u53ef\u8bfb\u6587\u6863\u300d\u3002<\/p>\n<h2>\u4e00\u3001\u63d0\u4ea4\u4fe1\u606f\uff1a\u7528 Conventional Commits \u7edf\u4e00\u8bed\u8a00<\/h2>\n<p>Conventional Commits \u662f\u4e00\u5957\u7ea6\u5b9a\u5f0f\u63d0\u4ea4\u89c4\u8303\uff0c\u683c\u5f0f\u56fa\u5b9a\u3001\u673a\u5668\u53ef\u89e3\u6790\uff0c\u4e5f\u662f Semantic Versioning \u548c\u81ea\u52a8\u5316 changelog \u7684\u57fa\u7840\u3002<\/p>\n<h3>\u57fa\u672c\u683c\u5f0f<\/h3>\n<pre><code>&lt;type&gt;(&&lt;scope&gt;): &lt;subject&gt;\n\n&lt;body&gt;\uff08\u53ef\u9009\uff09\n\n&lt;footer&gt;\uff08\u53ef\u9009\uff0c\u5982 BREAKING CHANGE \/ \u5173\u95ed issue\uff09\n<\/code><\/pre>\n<p>\u5e38\u7528 <code>type<\/code>\uff1a<\/p>\n<ul>\n<li><code>feat<\/code>\uff1a\u65b0\u529f\u80fd<\/li>\n<li><code>fix<\/code>\uff1a\u4fee\u590d bug<\/li>\n<li><code>docs<\/code>\uff1a\u6587\u6863\u53d8\u66f4<\/li>\n<li><code>style<\/code>\uff1a\u4ee3\u7801\u683c\u5f0f\uff08\u4e0d\u5f71\u54cd\u903b\u8f91\uff0c\u5982\u7a7a\u683c\u3001\u5206\u53f7\uff09<\/li>\n<li><code>refactor<\/code>\uff1a\u91cd\u6784\uff08\u975e feat \u4e5f\u975e fix\uff09<\/li>\n<li><code>perf<\/code>\uff1a\u6027\u80fd\u4f18\u5316<\/li>\n<li><code>test<\/code>\uff1a\u589e\u52a0\u6d4b\u8bd5<\/li>\n<li><code>chore<\/code>\uff1a\u6784\u5efa\/\u4f9d\u8d56\/\u5de5\u5177\u94fe\u53d8\u52a8<\/li>\n<li><code>build<\/code>\uff1a\u6784\u5efa\u7cfb\u7edf\u6216\u5916\u90e8\u4f9d\u8d56\u53d8\u52a8<\/li>\n<li><code>ci<\/code>\uff1aCI \u914d\u7f6e\u53d8\u52a8<\/li>\n<\/ul>\n<h3>\u597d\u4f8b\u5b50 vs \u574f\u4f8b\u5b50<\/h3>\n<pre><code># \u574f\uff1a\u4fe1\u606f\u91cf\u4e3a\u96f6\ngit commit -m \"\u66f4\u65b0\"\n\n# \u597d\uff1a\u4e00\u773c\u770b\u61c2\u505a\u4e86\u4ec0\u4e48\u3001\u5f71\u54cd\u54ea\u91cc\ngit commit -m \"feat(order): \u652f\u6301\u4f18\u60e0\u5238\u53e0\u52a0\u8ba1\u7b97\n\n\u5728\u7ed3\u7b97\u670d\u52a1\u65b0\u589e coupon-stacking \u6a21\u5757\uff0c\u5141\u8bb8\u7528\u6237\u53e0\u52a0\u6700\u591a 3 \u5f20\u5238\uff0c\n\u5e76\u8865\u5145\u4e86\u8fb9\u754c\u5355\u5143\u6d4b\u8bd5\u3002\n\nCloses #142\"\n<\/code><\/pre>\n<h2>\u4e8c\u3001\u7528\u5de5\u5177\u628a\u89c4\u8303\u300c\u5361\u300d\u4f4f\uff0c\u800c\u4e0d\u662f\u9760\u81ea\u89c9<\/h2>\n<p>\u89c4\u8303\u5199\u5728\u6587\u6863\u91cc\u6ca1\u4eba\u770b\uff0c\u5f97\u7528\u5de5\u5177\u5f3a\u5236\u3002\u63a8\u8350 <strong>Commitlint<\/strong> + <strong>Husky<\/strong> \u5728\u672c\u5730\u63d0\u4ea4\u65f6\u6821\u9a8c\uff0cCI \u91cc\u518d\u6821\u9a8c\u4e00\u6b21\u3002<\/p>\n<pre><code># \u5b89\u88c5\nnpm install --save-dev @commitlint\/cli @commitlint\/config-conventional husky\n\n# .commitlintrc.js\nmodule.exports = { extends: ['@commitlint\/config-conventional'] }\n\n# husky \u94a9\u5b50\uff08\u63d0\u4ea4\u524d\u6821\u9a8c\uff09\nnpx husky add .husky\/commit-msg \"npx --no -- commitlint --edit $1\"\n<\/code><\/pre>\n<p>\u8fd9\u6837\u4e0d\u7b26\u5408\u89c4\u8303\u7684\u63d0\u4ea4\u4f1a\u88ab\u76f4\u63a5\u62d2\u7edd\uff0c\u56e2\u961f\u5386\u53f2\u81ea\u7136\u5c31\u5e72\u51c0\u4e86\u3002<\/p>\n<h2>\u4e09\u3001\u5206\u652f\u6a21\u578b\uff1a\u9009\u4e00\u4e2a\uff0c\u522b\u6df7\u7740\u7528<\/h2>\n<h3>\u65b9\u6848 A\uff1aGit Flow\uff08\u9002\u5408\u6709\u7248\u672c\u53d1\u5e03\u8282\u594f\u7684\u56e2\u961f\uff09<\/h3>\n<ul>\n<li><code>main<\/code>\uff1a\u59cb\u7ec8\u53ef\u53d1\u5e03\u7684\u7a33\u5b9a\u7248\u672c<\/li>\n<li><code>develop<\/code>\uff1a\u65e5\u5e38\u96c6\u6210\u5206\u652f<\/li>\n<li><code>feature\/*<\/code>\uff1a\u65b0\u529f\u80fd\uff0c\u4ece develop \u62c9\uff0c\u5408\u56de develop<\/li>\n<li><code>release\/*<\/code>\uff1a\u53d1\u5e03\u51c6\u5907\uff0c\u4ece develop \u62c9\uff0c\u5408\u56de main \u548c develop<\/li>\n<li><code>hotfix\/*<\/code>\uff1a\u7ebf\u4e0a\u7d27\u6025\u4fee\u590d\uff0c\u4ece main \u62c9\uff0c\u5408\u56de main \u548c develop<\/li>\n<\/ul>\n<p>\u4f18\u70b9\uff1a\u804c\u8d23\u6e05\u6670\u3001\u9002\u5408\u591a\u7248\u672c\u5e76\u884c\u7ef4\u62a4\u3002\u7f3a\u70b9\uff1a\u5206\u652f\u591a\u3001\u6d41\u7a0b\u91cd\u3002<\/p>\n<h3>\u65b9\u6848 B\uff1aTrunk-Based\uff08\u9002\u5408\u9ad8\u9891\u4ea4\u4ed8\/CI \u6210\u719f\u56e2\u961f\uff09<\/h3>\n<ul>\n<li>\u53ea\u6709 <code>main<\/code> \u4e00\u6761\u957f\u751f\u547d\u5468\u671f\u5206\u652f<\/li>\n<li>\u529f\u80fd\u901a\u8fc7<strong>\u77ed\u547d\u5206\u652f<\/strong>\uff081-2 \u5929\uff09\u6216 <strong>Feature Flag<\/strong> \u5408\u5165<\/li>\n<li>\u6bcf\u6b21\u5408\u5165\u90fd\u89e6\u53d1 CI\uff0c\u5f3a\u8c03\u300c\u5c0f\u6b65\u5feb\u8dd1\u300d<\/li>\n<\/ul>\n<p>\u4f18\u70b9\uff1a\u6781\u7b80\u3001\u5408\u5e76\u51b2\u7a81\u5c11\u3001\u4ea4\u4ed8\u5feb\u3002\u7f3a\u70b9\uff1a\u5bf9 CI \u548c\u6d4b\u8bd5\u8986\u76d6\u8981\u6c42\u9ad8\u3002<\/p>\n<pre><code># Trunk-Based \u5178\u578b\u4e00\u5929\ngit switch main\ngit pull\ngit switch -c feature\/login-oauth   # \u77ed\u547d\u5206\u652f\n# ... \u5199\u4ee3\u7801\u3001\u672c\u5730\u6d4b\u8bd5 ...\ngit push -u origin feature\/login-oauth\n# \u63d0 PR\/MR\uff0cCI \u901a\u8fc7\u5373\u5408\u5165 main\n<\/code><\/pre>\n<h2>\u56db\u3001\u51e0\u4e2a\u8ba9\u5386\u53f2\u66f4\u5e72\u51c0\u7684\u5c0f\u4e60\u60ef<\/h2>\n<ol>\n<li><strong>\u4e00\u4e2a\u63d0\u4ea4\u53ea\u505a\u4e00\u4ef6\u4e8b<\/strong>\uff1a\u522b\u628a\u300c\u91cd\u6784 + \u4fee bug + \u52a0\u529f\u80fd\u300d\u585e\u8fdb\u4e00\u4e2a commit\uff0c\u7528 <code>git add -p<\/code> \u6309\u9700\u6682\u5b58\u3002<\/li>\n<li><strong>\u5b66\u4f1a rebase \u6574\u7406\u672c\u5730\u63d0\u4ea4<\/strong>\uff1a\u63a8\u9001\u5230\u8fdc\u7a0b\u524d\uff0c\u7528 <code>git rebase -i HEAD~3<\/code> \u628a\u96f6\u6563\u63d0\u4ea4\u538b\u6210\u6709\u610f\u4e49\u7684\u51e0\u4e2a\u3002<\/li>\n<li><strong>\u7981\u6b62\u5411\u5171\u4eab\u5206\u652f\u5f3a\u63a8<\/strong>\uff1a<code>git push --force<\/code> \u53ea\u7528\u4e8e\u81ea\u5df1\u7684\u7279\u6027\u5206\u652f\uff0c\u4e14\u4f18\u5148\u7528 <code>--force-with-lease<\/code>\u3002<\/li>\n<li><strong>\u5408\u5e76\u7528 &#8211;no-ff \u4fdd\u7559\u8f68\u8ff9<\/strong>\uff1a<code>git merge --no-ff feature\/x<\/code> \u8ba9\u529f\u80fd\u5206\u652f\u5728\u5386\u53f2\u4e0a\u53ef\u89c1\u3002<\/li>\n<\/ol>\n<h2>\u5c0f\u7ed3<\/h2>\n<p>\u63d0\u4ea4\u89c4\u8303\u89e3\u51b3\u300c\u6bcf\u6761\u8bb0\u5f55\u8bf4\u4ec0\u4e48\u300d\uff0c\u5206\u652f\u6a21\u578b\u89e3\u51b3\u300c\u4ee3\u7801\u5f80\u54ea\u6d41\u52a8\u300d\u3002\u4e24\u8005\u914d\u5408\uff0c\u518d\u914d\u4e0a Commitlint \u8fd9\u79cd\u5f3a\u5236\u5de5\u5177\uff0c\u4f60\u7684 Git \u5386\u53f2\u4f1a\u4ece\u8d1f\u62c5\u53d8\u6210\u8d44\u4ea7\u2014\u2014\u56de\u6eda\u3001\u590d\u76d8\u3001\u81ea\u52a8\u751f\u6210 changelog \u90fd\u4e0d\u518d\u662f\u96be\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528 Conventional Commits + \u5408\u7406\u7684\u5206\u652f\u6a21\u578b\uff08Git Flow \/ Trunk-Based\uff09\uff0c\u628a\u4e00\u56e2\u4e71\u9ebb\u7684\u63d0\u4ea4\u8bb0\u5f55\u53d8\u6210\u53ef\u8bfb\u3001\u53ef\u56de\u6eaf\u3001\u53ef\u81ea\u52a8\u5316\u7684\u56e2\u961f\u5de5\u4f5c\u6d41\u3002<\/p>\n","protected":false},"author":2,"featured_media":84,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-85","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/85","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=85"}],"version-history":[{"count":1,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/85\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/posts\/85\/revisions\/249"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=\/wp\/v2\/media\/84"}],"wp:attachment":[{"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fsdata.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}