{"id":6709,"date":"2025-03-09T17:53:23","date_gmt":"2025-03-09T09:53:23","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6709"},"modified":"2025-03-09T17:53:23","modified_gmt":"2025-03-09T09:53:23","slug":"git-%e5%bc%80%e5%8f%91%e5%b7%a5%e4%bd%9c%e6%b5%81%e4%b8%ad%e7%9a%84%e7%ba%a6%e6%9d%9f%e7%82%b9","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6709","title":{"rendered":"Git \u5f00\u53d1\u5de5\u4f5c\u6d41\u4e2d\u7684\u7ea6\u675f\u70b9"},"content":{"rendered":"<h2><strong>\ud83d\ude80 Git \u5f00\u53d1\u5de5\u4f5c\u6d41\u4e2d\u7684\u7ea6\u675f\u70b9\u4f18\u5316<\/strong><\/h2>\n<p>\u5728 <strong>Git \u5f00\u53d1\u5de5\u4f5c\u6d41<\/strong> \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0 <strong>\u4ee3\u7801\u8d28\u91cf\u3001\u6784\u5efa\u7ea6\u675f\u3001\u5206\u652f\u7ba1\u7406\u3001\u6d4b\u8bd5\u5408\u89c4\u6027<\/strong> \u7b49\u591a\u4e2a\u7ea6\u675f\u70b9\uff0c\u4ee5\u786e\u4fdd\u4ee3\u7801\u8d28\u91cf\u548c\u4ea4\u4ed8\u7a33\u5b9a\u6027\u3002\u4ee5\u4e0b\u662f <strong>\u5173\u952e\u7ea6\u675f\u70b9<\/strong> \u53ca\u5982\u4f55\u5b9e\u65bd\u7684\u5efa\u8bae\uff1a  <\/p>\n<hr \/>\n<h2><strong>\ud83d\udccc 1. \u63d0\u4ea4\u524d\u7ea6\u675f\uff08Pre-Commit &amp; Pre-Push\uff09<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u5728\u4ee3\u7801\u63d0\u4ea4\u524d\uff0c\u81ea\u52a8\u68c0\u67e5\u4ee3\u7801\u8d28\u91cf\uff0c\u907f\u514d\u4f4e\u8d28\u91cf\u4ee3\u7801\u8fdb\u5165 Git \u4ed3\u5e93  <\/p>\n<p>\u2705 <strong>\u4ee3\u7801\u98ce\u683c\u68c0\u67e5<\/strong>\uff1a  <\/p>\n<ul>\n<li>\u524d\u7aef\uff1a<code>ESLint + Prettier<\/code>\uff08JS\/TS\uff09\u3001<code>Stylelint<\/code>\uff08CSS\uff09  <\/li>\n<li>\u79fb\u52a8\u7aef\uff1a<code>SwiftLint<\/code>\uff08iOS\uff09\u3001<code>ktlint<\/code>\uff08Android\uff09  <\/li>\n<li>\u540e\u7aef\uff1a<code>Checkstyle<\/code>\uff08Java\uff09\u3001<code>pylint<\/code>\uff08Python\uff09  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u4ee3\u7801\u683c\u5f0f\u5316<\/strong>\uff08\u907f\u514d\u63d0\u4ea4\u4e0d\u89c4\u8303\u4ee3\u7801\uff09\uff1a  <\/p>\n<ul>\n<li>\u7edf\u4e00\u683c\u5f0f\u5316 <code>Prettier<\/code> \/ <code>clang-format<\/code> \/ <code>black<\/code>  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u654f\u611f\u4fe1\u606f\u68c0\u67e5<\/strong>\uff08\u907f\u514d API Key\u3001\u5bc6\u7801\u63d0\u4ea4\u5230 Git\uff09\uff1a  <\/p>\n<ul>\n<li><code>git-secrets<\/code> \/ <code>truffleHog<\/code> \u81ea\u52a8\u626b\u63cf  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u6784\u5efa\u5305\u5927\u5c0f\u68c0\u67e5<\/strong>\uff08\u907f\u514d\u8d85\u5927\u8d44\u6e90\u63d0\u4ea4\uff09\uff1a  <\/p>\n<ul>\n<li><code>size-limit<\/code>\uff08\u524d\u7aef\uff09  <\/li>\n<li><code>apk analyzer<\/code>\uff08Android\uff09  <\/li>\n<li><code>fastlane xcsize<\/code>\uff08iOS\uff09  <\/li>\n<\/ul>\n<p>\u2705 <strong>Lint \u4ee3\u7801\u68c0\u67e5<\/strong>\uff1a  <\/p>\n<pre><code class=\"language-bash\">npx eslint . --fix   # JS\/TS\nnpx stylelint &#039;**\/*.css&#039; --fix   # CSS\nswiftlint autocorrect   # iOS\nktlint -F   # Android<\/code><\/pre>\n<p>\ud83d\udd39 <strong>\u5de5\u5177\u5b9e\u73b0<\/strong>\uff1a\u4f7f\u7528 <strong>Husky + lint-staged<\/strong> \u914d\u7f6e Git Hook  <\/p>\n<pre><code class=\"language-bash\">npx husky add .husky\/pre-commit &quot;npm run lint &amp;&amp; npm run format&quot;<\/code><\/pre>\n<hr \/>\n<h2><strong>\ud83d\udccc 2. \u63d0\u4ea4\u4fe1\u606f\u7ea6\u675f\uff08Commit Message\uff09<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u786e\u4fdd commit \u89c4\u8303\uff0c\u4fbf\u4e8e\u8ffd\u8e2a\u5386\u53f2 &amp; \u751f\u6210\u81ea\u52a8\u5316 Changelog  <\/p>\n<p>\u2705 <strong>\u4f7f\u7528 <code>Conventional Commits<\/code> \u89c4\u8303<\/strong>  <\/p>\n<pre><code class=\"language-bash\">feat: \u65b0\u589e\u7528\u6237\u641c\u7d22\u529f\u80fd\nfix: \u4fee\u590d\u767b\u5f55\u6309\u94ae\u70b9\u51fb\u65e0\u54cd\u5e94\nchore: \u66f4\u65b0 ESLint \u89c4\u5219<\/code><\/pre>\n<p>\u2705 <strong>\u4f7f\u7528 <code>commitlint<\/code> + <code>husky<\/code> \u9650\u5236\u63d0\u4ea4\u683c\u5f0f<\/strong>  <\/p>\n<pre><code class=\"language-bash\">npx husky add .husky\/commit-msg &quot;npx commitlint --edit $1&quot;<\/code><\/pre>\n<p>\u2705 <strong>\u81ea\u52a8\u751f\u6210 Changelog<\/strong>  <\/p>\n<ul>\n<li><code>commitizen<\/code> \u2192 \u63d0\u793a\u586b\u5199\u7b26\u5408\u89c4\u8303\u7684\u63d0\u4ea4\u4fe1\u606f  <\/li>\n<li><code>standard-version<\/code> \u2192 \u81ea\u52a8\u751f\u6210 <code>CHANGELOG.md<\/code>  <\/li>\n<\/ul>\n<hr \/>\n<h2><strong>\ud83d\udccc 3. \u5206\u652f\u7ba1\u7406\u7ea6\u675f<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u907f\u514d\u4e3b\u5e72\u6c61\u67d3\uff0c\u786e\u4fdd\u4ee3\u7801\u53d8\u66f4\u53d7\u63a7  <\/p>\n<p>\u2705 <strong>\u63a8\u8350 Git \u5206\u652f\u7b56\u7565<\/strong>\uff08Git Flow \/ Trunk-Based\uff09  <\/p>\n<ul>\n<li><code>main<\/code> \u2192 \u7ebf\u4e0a\u7a33\u5b9a\u7248\u672c  <\/li>\n<li><code>develop<\/code> \u2192 \u5f00\u53d1\u5206\u652f  <\/li>\n<li><code>feature\/*<\/code> \u2192 \u529f\u80fd\u5206\u652f  <\/li>\n<li><code>hotfix\/*<\/code> \u2192 \u7ebf\u4e0a\u7d27\u6025\u4fee\u590d  <\/li>\n<li><code>release\/*<\/code> \u2192 \u9884\u53d1\u5e03\u5206\u652f  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u5206\u652f\u4fdd\u62a4<\/strong>\uff08\u9632\u6b62\u8bef\u63d0\u4ea4 &amp; \u76f4\u63a5\u63a8\u9001 main\uff09\uff1a  <\/p>\n<ul>\n<li><strong><code>main<\/code> \u5206\u652f\u5fc5\u987b\u5f00 PR\uff0c\u4e0d\u80fd\u76f4\u63a5 push<\/strong>  <\/li>\n<li><strong>PR \u9700 Review + CI \u901a\u8fc7\u624d\u80fd\u5408\u5e76<\/strong>\uff08<code>required status checks<\/code>\uff09  <\/li>\n<li><strong><code>feature\/*<\/code> \u5206\u652f commit \u9700 rebase\uff0c\u4e0d\u5141\u8bb8 merge commit<\/strong>  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u81ea\u52a8\u5220\u9664\u65e0\u7528\u5206\u652f<\/strong>\uff08PR \u5408\u5e76\u540e\u81ea\u52a8\u5220\u9664\uff09  <\/p>\n<pre><code class=\"language-bash\">git fetch --prune\ngit branch -d feature\/xxx<\/code><\/pre>\n<hr \/>\n<h2><strong>\ud83d\udccc 4. Pull Request \u7ea6\u675f<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u786e\u4fdd PR \u8d28\u91cf\uff0c\u907f\u514d\u9519\u8bef\u4ee3\u7801\u8fdb\u5165\u4e3b\u5e72  <\/p>\n<p>\u2705 <strong>\u5f3a\u5236 Code Review<\/strong>\uff08<code>GitHub Branch Protection<\/code>\uff09  <\/p>\n<ul>\n<li>\u81f3\u5c11 <strong>1-2 \u4eba<\/strong> \u4ee3\u7801\u5ba1\u67e5\u624d\u80fd\u5408\u5e76  <\/li>\n<li><strong>PR \u8d85\u8fc7 500 \u884c\u4ee3\u7801\u9700\u62c6\u5206<\/strong>\uff08\u907f\u514d\u5927\u89c4\u6a21\u53d8\u66f4\uff09  <\/li>\n<li>PR \u9700\u9644\u5e26 <strong>\u8be6\u7ec6\u63cf\u8ff0<\/strong>\uff08\u6d89\u53ca\u54ea\u4e9b\u6539\u52a8 &amp; \u5f71\u54cd\uff09  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u81ea\u52a8\u89e6\u53d1 CI\/CD \u6d41\u7a0b<\/strong>\uff08PR \u901a\u8fc7 CI \u540e\u624d\u80fd\u5408\u5e76\uff09  <\/p>\n<pre><code class=\"language-yaml\">name: PR Checks\non:\n  pull_request:\n    branches:\n      - main\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/checkout@v3\n      - name: Run Tests\n        run: npm test<\/code><\/pre>\n<p>\u2705 <strong>\u81ea\u52a8\u8fd0\u884c <code>sonarqube<\/code> \u4ee3\u7801\u8d28\u91cf\u5206\u6790<\/strong>  <\/p>\n<pre><code class=\"language-yaml\">name: Code Quality\non: pull_request\njobs:\n  sonar:\n    runs-on: ubuntu-latest\n    steps:\n      - name: SonarCloud Scan\n        run: sonar-scanner<\/code><\/pre>\n<hr \/>\n<h2><strong>\ud83d\udccc 5. \u4ee3\u7801\u5408\u5e76\uff08Merge\uff09\u7ea6\u675f<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u786e\u4fdd\u4ee3\u7801\u5408\u5e76\u540e <strong>\u53ef\u56de\u6eda\u3001\u53ef\u8ffd\u8e2a<\/strong>  <\/p>\n<table>\n<thead>\n<tr>\n<th>\u2705 <strong>\u63a8\u8350 Merge \u7b56\u7565<\/strong>\uff08\u907f\u514d\u6c61\u67d3\u4e3b\u5e72\uff09<\/th>\n<th>\u65b9\u5f0f<\/th>\n<th>\u9002\u7528\u573a\u666f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Squash Merge<\/strong><\/td>\n<td>\u5c0f\u578b PR\uff08\u5408\u5e76\u540e\u53d8 1 \u6761 commit\uff09<\/td>\n<\/tr>\n<tr>\n<td><strong>Rebase Merge<\/strong><\/td>\n<td>\u4ee3\u7801\u5386\u53f2\u4fdd\u6301\u7ebf\u6027<\/td>\n<\/tr>\n<tr>\n<td><strong>Merge Commit<\/strong><\/td>\n<td>\u9700\u8981\u5b8c\u6574\u4fdd\u7559 commit \u8bb0\u5f55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2705 <strong>\u5408\u5e76\u524d\u81ea\u52a8\u89e6\u53d1 CI\/CD<\/strong>\uff08\u786e\u4fdd\u6d4b\u8bd5\u5168\u90e8\u901a\u8fc7\uff09  <\/p>\n<ul>\n<li>CI \u5931\u8d25 <strong>\u4e0d\u80fd\u5408\u5e76 PR<\/strong>  <\/li>\n<li>PR \u5fc5\u987b <strong>\u6d4b\u8bd5\u8986\u76d6\u7387 \u2265 80%<\/strong> \u624d\u80fd\u5408\u5e76  <\/li>\n<\/ul>\n<p>\u2705 <strong>\u5408\u5e76\u540e\u81ea\u52a8\u90e8\u7f72<\/strong>\uff08\u4ec5\u5bf9 <code>main<\/code> \u5206\u652f\u751f\u6548\uff09  <\/p>\n<pre><code class=\"language-yaml\">on:\n  push:\n    branches:\n      - main\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Deploy to Production\n        run: .\/deploy.sh<\/code><\/pre>\n<hr \/>\n<h2><strong>\ud83d\udccc 6. \u7248\u672c &amp; \u53d1\u5e03\u7ea6\u675f<\/strong><\/h2>\n<p>\ud83d\udccc <strong>\u76ee\u6807<\/strong>\uff1a\u907f\u514d\u7248\u672c\u6df7\u4e71\uff0c\u786e\u4fdd\u6bcf\u4e2a Release \u53ef\u8ffd\u8e2a  <\/p>\n<p>\u2705 <strong>\u7248\u672c\u53f7\u91c7\u7528 <code>Semantic Versioning<\/code> \u89c4\u8303<\/strong>  <\/p>\n<pre><code>MAJOR.MINOR.PATCH\uff08\u5982 1.2.3\uff09\n- MAJOR\uff1a\u7834\u574f\u6027\u53d8\u66f4\n- MINOR\uff1a\u65b0\u589e\u529f\u80fd\n- PATCH\uff1a\u4fee\u590d Bug<\/code><\/pre>\n<p>\u2705 <strong>\u81ea\u52a8\u751f\u6210 Release Notes<\/strong>  <\/p>\n<pre><code class=\"language-bash\">npx standard-version<\/code><\/pre>\n<p>\u2705 <strong>\u81ea\u52a8\u53d1\u5e03\u5230 npm \/ App Store \/ Google Play<\/strong>  <\/p>\n<pre><code class=\"language-yaml\">name: Publish\non:\n  push:\n    tags:\n      - &quot;v*.*.*&quot;\njobs:\n  publish:\n    steps:\n      - name: Publish to npm\n        run: npm publish<\/code><\/pre>\n<hr \/>\n<h2><strong>\ud83d\udca1 7. \u5173\u952e Git \u7ea6\u675f\u70b9\u603b\u7ed3<\/strong><\/h2>\n<table>\n<thead>\n<tr>\n<th><strong>\u9636\u6bb5<\/strong><\/th>\n<th><strong>\u7ea6\u675f\u70b9<\/strong><\/th>\n<th><strong>\u5b9e\u73b0\u65b9\u5f0f<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u63d0\u4ea4\u524d<\/td>\n<td>\u4ee3\u7801\u98ce\u683c\u3001\u6784\u5efa\u5927\u5c0f\u3001\u654f\u611f\u4fe1\u606f<\/td>\n<td><code>Husky<\/code> \/ <code>ESLint<\/code> \/ <code>git-secrets<\/code><\/td>\n<\/tr>\n<tr>\n<td>Commit<\/td>\n<td>\u89c4\u8303\u5316\u63d0\u4ea4\u4fe1\u606f<\/td>\n<td><code>commitlint<\/code> \/ <code>commitizen<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u5206\u652f\u7ba1\u7406<\/td>\n<td>\u53d7\u63a7 Git Flow<\/td>\n<td><code>GitHub Branch Protection<\/code><\/td>\n<\/tr>\n<tr>\n<td>Pull Request<\/td>\n<td>\u5f3a\u5236 Code Review\u3001CI\/CD<\/td>\n<td><code>GitHub Actions<\/code> \/ <code>SonarQube<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7801\u5408\u5e76<\/td>\n<td>\u786e\u4fdd CI \u901a\u8fc7\uff0c\u81ea\u52a8\u6d4b\u8bd5<\/td>\n<td><code>GitHub Actions<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u7248\u672c\u7ba1\u7406<\/td>\n<td>\u8bed\u4e49\u5316\u7248\u672c\uff0c\u81ea\u52a8\u53d1\u5e03<\/td>\n<td><code>standard-version<\/code> \/ <code>npm publish<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h2><strong>\ud83c\udfaf \u7ed3\u8bba<\/strong><\/h2>\n<p>\u2705 <strong>\u81ea\u52a8\u5316\u4ee3\u7801\u68c0\u67e5<\/strong>\uff08Lint\u3001\u6784\u5efa\u5927\u5c0f\u3001\u654f\u611f\u4fe1\u606f\u68c0\u6d4b\uff09<br \/>\n\u2705 <strong>\u4e25\u683c\u7684\u5206\u652f\u7ba1\u7406<\/strong>\uff08PR \u4fdd\u62a4\u3001\u5f3a\u5236 Code Review\uff09<br \/>\n\u2705 <strong>CI\/CD \u7ea6\u675f<\/strong>\uff08\u6d4b\u8bd5 &amp; \u8d28\u91cf\u68c0\u67e5\u901a\u8fc7\u624d\u80fd\u5408\u5e76\uff09<br \/>\n\u2705 <strong>\u81ea\u52a8\u7248\u672c\u7ba1\u7406<\/strong>\uff08\u8bed\u4e49\u5316\u7248\u672c\u3001\u81ea\u52a8 Release Notes\uff09  <\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\ude80 Git \u5f00\u53d1\u5de5\u4f5c\u6d41\u4e2d\u7684\u7ea6\u675f\u70b9\u4f18\u5316 \u5728 Git \u5f00\u53d1\u5de5\u4f5c\u6d41 \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u589e\u52a0 \u4ee3\u7801\u8d28\u91cf\u3001\u6784\u5efa\u7ea6\u675f\u3001\u5206\u652f\u7ba1\u7406\u3001&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6709\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-6709","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6709"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6709\/revisions"}],"predecessor-version":[{"id":6710,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6709\/revisions\/6710"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}