{"id":10020948,"date":"2025-08-19T21:23:52","date_gmt":"2025-08-19T13:23:52","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020948"},"modified":"2025-08-19T21:23:52","modified_gmt":"2025-08-19T13:23:52","slug":"%e7%a8%8b%e5%ba%8f%e5%91%98%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d-git-%e5%86%b2%e7%aa%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020948","title":{"rendered":"\u7a0b\u5e8f\u5458\u5982\u4f55\u907f\u514d git \u51b2\u7a81\uff1f"},"content":{"rendered":"<h2>\u7a0b\u5e8f\u5458\u5982\u4f55\u907f\u514dGit\u51b2\u7a81\uff1f\u4e00\u4e2a\u8001\u7801\u519c\u7684\u8840\u6cea\u53f2\u548c\u5b9e\u6218\u7ecf\u9a8c<\/h2>\n<p>\u770b\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u7684\u5185\u5fc3\u77ac\u95f4\u6d8c\u8d77\u4e86\u65e0\u6570\u4e2a\u75db\u82e6\u7684\u56de\u5fc6\u3002\u4f5c\u4e3a\u4e00\u4e2a\u5728\u8fd9\u884c\u6478\u722c\u6eda\u6253\u4e86\u5feb\u5341\u5e74\u7684\u8001\u7a0b\u5e8f\u5458\uff0c\u4ece\u673a\u68b0\u4e13\u4e1a\u8f6c\u884c\u5230\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u518d\u5230\u5916\u4f01\u5de5\u4f5c\uff0c\u6700\u540e\u81ea\u5df1\u521b\u4e1a\uff0c\u6211\u53ef\u4ee5\u6beb\u4e0d\u5938\u5f20\u5730\u8bf4\uff1aGit\u51b2\u7a81\u662f\u6211\u7a0b\u5e8f\u5458\u751f\u6daf\u4e2d\u6700\u5927\u7684\u5669\u68a6\u4e4b\u4e00\u3002<\/p>\n<p>\u4eca\u5929\u5c31\u8ba9\u6211\u8fd9\u4e2a\u8e29\u8fc7\u65e0\u6570\u5751\u3001\u6d41\u8fc7\u65e0\u6570\u6cea\u7684\u8001\u7801\u519c\uff0c\u8ddf\u5927\u5bb6\u804a\u804a\u5982\u4f55\u907f\u514dGit\u51b2\u7a81\u8fd9\u4e2a\u8ba9\u6240\u6709\u7a0b\u5e8f\u5458\u90fd\u5934\u75bc\u7684\u95ee\u9898\u3002\u76f8\u4fe1\u6211\u8bf4\u7684\u6bcf\u4e00\u70b9\uff0c\u90fd\u4f1a\u8ba9\u4f60\u4ea7\u751f\u6df1\u6df1\u7684\u5171\u9e23\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u90fd\u662f\u7528\u8840\u548c\u6cea\u6362\u6765\u7684\u7ecf\u9a8c\u3002<\/p>\n<h3>\u4e00\u3001\u6211\u4e0eGit\u51b2\u7a81\u7684\u7b2c\u4e00\u6b21&#8221;\u4eb2\u5bc6\u63a5\u89e6&#8221;\uff1a\u90a3\u4e2a\u8ba9\u6211\u6000\u7591\u4eba\u751f\u7684\u591c\u665a<\/h3>\n<p>\u8bf4\u8d77Git\u51b2\u7a81\uff0c\u6211\u6c38\u8fdc\u5fd8\u4e0d\u4e862015\u5e74\u7684\u90a3\u4e2a\u6df1\u591c\u3002\u5f53\u65f6\u6211\u521a\u4ece\u673a\u68b0\u4e13\u4e1a\u8f6c\u884c\u505a\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u5728\u67d0\u9a6c\u5de5\u4f5c\u8fd8\u4e0d\u5230\u534a\u5e74\uff0c\u5bf9Git\u7684\u7406\u89e3\u8fd8\u505c\u7559\u5728<code>git add<\/code>\u3001<code>git commit<\/code>\u3001<code>git push<\/code>\u8fd9\u51e0\u4e2a\u57fa\u672c\u547d\u4ee4\u4e0a\u3002<\/p>\n<p>\u90a3\u5929\u4e0b\u5348\uff0c\u6211\u548c\u53e6\u5916\u4e24\u4e2a\u540c\u4e8b\u540c\u65f6\u5728\u5f00\u53d1\u4e00\u4e2aLinux\u9a71\u52a8\u7a0b\u5e8f\u3002\u6211\u4eec\u4e09\u4e2a\u4eba\u5206\u522b\u8d1f\u8d23\u4e0d\u540c\u7684\u529f\u80fd\u6a21\u5757\uff0c\u4f46\u7531\u4e8e\u9a71\u52a8\u7a0b\u5e8f\u7684\u7279\u6b8a\u6027\uff0c\u5f88\u591a\u4ee3\u7801\u90fd\u5728\u540c\u4e00\u4e2a\u6587\u4ef6\u91cc\u3002\u9879\u76ee\u7ecf\u7406\u50ac\u5f97\u5f88\u7d27\uff0c\u8bf4\u5ba2\u6237\u90a3\u8fb9\u7b49\u7740\u6d4b\u8bd5\uff0c\u5fc5\u987b\u5f53\u5929\u665a\u4e0a\u63d0\u4ea4\u4ee3\u7801\u3002<\/p>\n<p>\u4e0b\u53486\u70b9\uff0c\u6211\u5b8c\u6210\u4e86\u81ea\u5df1\u8d1f\u8d23\u7684\u90e8\u5206\uff0c\u4fe1\u5fc3\u6ee1\u6ee1\u5730\u6267\u884c\u4e86<code>git add .<\/code>\u548c<code>git commit -m &quot;\u6dfb\u52a0GPIO\u63a7\u5236\u529f\u80fd&quot;<\/code>\u3002\u7136\u540e\uff0c\u5f53\u6211\u6ee1\u6000\u671f\u5f85\u5730\u6267\u884c<code>git push<\/code>\u7684\u65f6\u5019\uff0cGit\u7ed9\u4e86\u6211\u4e00\u4e2a\u6674\u5929\u9739\u96f3\uff1a<\/p>\n<pre><code>! [rejected] master -&gt; master (fetch first)\nerror: failed to push some refs to 'origin'\nhint: Updates were rejected because the remote contains work that you do\nhint: not have locally. This is usually caused by another repository pushing\nhint: to the same ref. You may want to first integrate the remote changes\nhint: (e.g., 'git pull ...') before pushing again.<\/code><\/pre>\n<p>\u6211\u5f53\u65f6\u7684\u5fc3\u60c5\u7b80\u76f4\u662f\u61f5\u903c\u52a0\u7edd\u671b\u3002\u4ec0\u4e48\u53eb&#8221;remote contains work that you do not have locally&#8221;\uff1f\u6211\u660e\u660e\u521a\u521a\u5199\u7684\u4ee3\u7801\u554a\uff01\u4e8e\u662f\u6211\u6309\u7167\u63d0\u793a\u6267\u884c\u4e86<code>git pull<\/code>\uff0c\u7136\u540e&#8230;\u5730\u72f1\u4e4b\u95e8\u6253\u5f00\u4e86\uff1a<\/p>\n<pre><code>Auto-merging drivers\/gpio_driver.c\nCONFLICT (content): Merge conflict in drivers\/gpio_driver.c\nAutomatic merge failed; fix conflicts and then commit the result.<\/code><\/pre>\n<p>\u770b\u5230\u8fd9\u4e9b\u5bc6\u5bc6\u9ebb\u9ebb\u7684\u51b2\u7a81\u6807\u8bb0\uff0c\u6211\u6574\u4e2a\u4eba\u90fd\u4e0d\u597d\u4e86\uff1a<\/p>\n<pre><code class=\"c\">&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD\nvoid gpio_set_output(int pin, int value) {\n    \/\/ \u6211\u7684\u5b9e\u73b0\n    writel(value &lt;&lt; pin, GPIO_BASE + GPIO_OUTPUT_REG);\n}\n=======\nvoid gpio_set_output(int pin, int value) {\n    \/\/ \u540c\u4e8b\u7684\u5b9e\u73b0\n    if (value) {\n        writel(1 &lt;&lt; pin, GPIO_BASE + GPIO_SET_REG);\n    } else {\n        writel(1 &lt;&lt; pin, GPIO_BASE + GPIO_CLEAR_REG);\n    }\n}\n&gt;&gt;&gt;&gt;&gt;&gt;&gt; origin\/master<\/code><\/pre>\n<p>\u6211\u76ef\u7740\u8fd9\u4e9b\u51b2\u7a81\u6807\u8bb0\uff0c\u5b8c\u5168\u4e0d\u77e5\u9053\u8be5\u600e\u4e48\u529e\u3002\u5220\u6389\u4e0a\u9762\u7684\u4fdd\u7559\u4e0b\u9762\u7684\uff1f\u8fd8\u662f\u5220\u6389\u4e0b\u9762\u7684\u4fdd\u7559\u4e0a\u9762\u7684\uff1f\u8fd8\u662f\u4e24\u4e2a\u90fd\u8981\uff1f\u6700\u8981\u547d\u7684\u662f\uff0c\u6211\u6839\u672c\u4e0d\u77e5\u9053\u540c\u4e8b\u6539\u4e86\u4ec0\u4e48\uff0c\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u6539\uff0c\u6211\u7684\u4fee\u6539\u4f1a\u4e0d\u4f1a\u5f71\u54cd\u4ed6\u7684\u529f\u80fd\u3002<\/p>\n<p>\u90a3\u4e00\u591c\uff0c\u6211\u5728\u529e\u516c\u5ba4\u5f85\u5230\u4e86\u51cc\u66682\u70b9\uff0c\u53cd\u590d\u5730Google\u3001Stack Overflow\u3001\u8bf7\u6559\u540c\u4e8b\uff0c\u7ec8\u4e8e\u641e\u660e\u767d\u4e86\u4ec0\u4e48\u662f\u5408\u5e76\u51b2\u7a81\uff0c\u600e\u4e48\u89e3\u51b3\u51b2\u7a81\u3002\u4f46\u90a3\u79cd\u65e0\u52a9\u548c\u7edd\u671b\u7684\u611f\u89c9\uff0c\u81f3\u4eca\u8fd8\u6df1\u6df1\u5370\u5728\u6211\u7684\u8bb0\u5fc6\u91cc\u3002<\/p>\n<p>\u4ece\u90a3\u4ee5\u540e\uff0c\u6211\u5c31\u6697\u6697\u53d1\u8a93\uff1a\u4e00\u5b9a\u8981\u641e\u660e\u767dGit\u7684\u539f\u7406\uff0c\u4e00\u5b9a\u8981\u5b66\u4f1a\u907f\u514d\u8fd9\u79cd\u75db\u82e6\u7684\u51b2\u7a81\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"401\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlLdz\" alt=\"\" title=\"\"><\/p>\n<h3>\u4e8c\u3001Git\u51b2\u7a81\u7684\u672c\u8d28\uff1a\u4e3a\u4ec0\u4e48\u4f1a\u53d1\u751f\u8fd9\u79cd&#8221;\u4eba\u95f4\u60e8\u5267&#8221;\uff1f<\/h3>\n<p>\u7ecf\u8fc7\u8fd9\u4e9b\u5e74\u7684\u6478\u7d22\u548c\u5b9e\u8df5\uff0c\u6211\u9010\u6e10\u7406\u89e3\u4e86Git\u51b2\u7a81\u7684\u672c\u8d28\u3002\u7b80\u5355\u6765\u8bf4\uff0cGit\u51b2\u7a81\u5c31\u662f\u5f53\u591a\u4e2a\u5f00\u53d1\u8005\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\u7684\u540c\u4e00\u90e8\u5206\u65f6\uff0cGit\u65e0\u6cd5\u81ea\u52a8\u5224\u65ad\u5e94\u8be5\u91c7\u7528\u54ea\u4e2a\u7248\u672c\u7684\u4fee\u6539\uff0c\u9700\u8981\u4eba\u5de5\u4ecb\u5165\u6765\u51b3\u5b9a\u6700\u7ec8\u7684\u4ee3\u7801\u5e94\u8be5\u662f\u4ec0\u4e48\u6837\u5b50\u3002<\/p>\n<p><strong>\u51b2\u7a81\u4ea7\u751f\u7684\u6839\u672c\u539f\u56e0<\/strong><\/p>\n<p>Git\u51b2\u7a81\u7684\u4ea7\u751f\u6709\u51e0\u4e2a\u6839\u672c\u539f\u56e0\uff0c\u6211\u901a\u8fc7\u65e0\u6570\u6b21\u7684\u8e29\u5751\u603b\u7ed3\u51fa\u6765\uff1a<\/p>\n<ol>\n<li><strong>\u5e76\u884c\u5f00\u53d1\u7684\u5fc5\u7136\u7ed3\u679c<\/strong>\uff1a\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u57fa\u672c\u90fd\u662f\u56e2\u961f\u534f\u4f5c\uff0c\u591a\u4e2a\u7a0b\u5e8f\u5458\u540c\u65f6\u5728\u4e0d\u540c\u7684\u529f\u80fd\u4e0a\u5de5\u4f5c\u3002\u5f53\u5927\u5bb6\u90fd\u9700\u8981\u4fee\u6539\u540c\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u51b2\u7a81\u5c31\u4e0d\u53ef\u907f\u514d\u4e86\u3002<\/li>\n<\/ol>\n<p>\u6211\u5728\u5916\u4f01\u5de5\u4f5c\u7684\u65f6\u5019\uff0c\u6211\u4eec\u56e2\u961f\u67098\u4e2a\u7a0b\u5e8f\u5458\uff0c\u5927\u5bb6\u90fd\u5728\u540c\u4e00\u4e2a\u4ee3\u7801\u5e93\u4e0a\u5de5\u4f5c\u3002\u867d\u7136\u5206\u5de5\u660e\u786e\uff0c\u4f46\u5f88\u591a\u6838\u5fc3\u6587\u4ef6\uff08\u6bd4\u5982\u914d\u7f6e\u6587\u4ef6\u3001\u516c\u5171\u5934\u6587\u4ef6\u3001\u4e3b\u7a0b\u5e8f\u5165\u53e3\u7b49\uff09\u51e0\u4e4e\u6bcf\u4e2a\u4eba\u90fd\u53ef\u80fd\u9700\u8981\u4fee\u6539\u3002\u4e00\u5929\u4e0b\u6765\uff0c\u4e3b\u5206\u652f\u4e0a\u53ef\u80fd\u6709\u5341\u51e0\u4e2a\u63d0\u4ea4\uff0c\u51b2\u7a81\u662f\u5bb6\u5e38\u4fbf\u996d\u3002<\/p>\n<ol start=\"2\">\n<li><strong>Git\u7684\u884c\u7ea7\u5408\u5e76\u7b56\u7565<\/strong>\uff1aGit\u5728\u5408\u5e76\u4ee3\u7801\u65f6\uff0c\u662f\u6309\u884c\u6765\u6bd4\u8f83\u7684\u3002\u5373\u4f7f\u4e24\u4e2a\u7a0b\u5e8f\u5458\u4fee\u6539\u7684\u662f\u5b8c\u5168\u4e0d\u76f8\u5173\u7684\u529f\u80fd\uff0c\u53ea\u8981\u4ed6\u4eec\u4fee\u6539\u4e86\u540c\u4e00\u884c\u4ee3\u7801\uff0cGit\u5c31\u4f1a\u8ba4\u4e3a\u5b58\u5728\u51b2\u7a81\u3002<\/li>\n<\/ol>\n<p>\u6211\u8bb0\u5f97\u6709\u4e00\u6b21\uff0c\u6211\u53ea\u662f\u5728\u4e00\u4e2a\u51fd\u6570\u7684\u672b\u5c3e\u52a0\u4e86\u4e00\u884c\u6ce8\u91ca\uff0c\u800c\u540c\u4e8b\u5728\u540c\u4e00\u884c\u6dfb\u52a0\u4e86\u4e00\u4e2a\u5206\u53f7\uff08\u4e4b\u524d\u5fd8\u8bb0\u4e86\uff09\u3002\u867d\u7136\u8fd9\u4e24\u4e2a\u4fee\u6539\u5b8c\u5168\u4e0d\u51b2\u7a81\uff0c\u4f46Git\u8fd8\u662f\u62a5\u544a\u4e86\u51b2\u7a81\uff0c\u9700\u8981\u6211\u4eec\u624b\u52a8\u5408\u5e76\u3002<\/p>\n<ol start=\"3\">\n<li><strong>\u5206\u652f\u7b56\u7565\u7684\u590d\u6742\u6027<\/strong>\uff1a\u73b0\u4ee3\u7684Git\u5de5\u4f5c\u6d41\u901a\u5e38\u6d89\u53ca\u591a\u4e2a\u5206\u652f\uff1amaster\u5206\u652f\u3001develop\u5206\u652f\u3001feature\u5206\u652f\u3001hotfix\u5206\u652f\u7b49\u3002\u5f53\u4ee3\u7801\u5728\u4e0d\u540c\u5206\u652f\u4e4b\u95f4\u5408\u5e76\u65f6\uff0c\u51b2\u7a81\u7684\u6982\u7387\u4f1a\u5927\u5927\u589e\u52a0\u3002<\/li>\n<\/ol>\n<p><strong>\u5e38\u89c1\u7684\u51b2\u7a81\u573a\u666f<\/strong><\/p>\n<p>\u5728\u6211\u7684\u804c\u4e1a\u751f\u6daf\u4e2d\uff0c\u6211\u9047\u5230\u8fc7\u5404\u79cd\u5404\u6837\u7684\u51b2\u7a81\u573a\u666f\uff0c\u6bcf\u4e00\u79cd\u90fd\u6709\u81ea\u5df1\u7684\u7279\u70b9\u548c\u75db\u70b9\uff1a<\/p>\n<p><strong>\u6587\u672c\u51b2\u7a81<\/strong>\uff1a\u8fd9\u662f\u6700\u5e38\u89c1\u7684\u51b2\u7a81\u7c7b\u578b\u3002\u4e24\u4e2a\u7a0b\u5e8f\u5458\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\u7684\u540c\u4e00\u884c\u6216\u76f8\u90bb\u7684\u884c\u3002\u8fd9\u79cd\u51b2\u7a81\u76f8\u5bf9\u5bb9\u6613\u89e3\u51b3\uff0c\u56e0\u4e3a\u53ef\u4ee5\u76f4\u63a5\u770b\u5230\u4e24\u4e2a\u7248\u672c\u7684\u5dee\u5f02\u3002<\/p>\n<p><strong>\u8bed\u4e49\u51b2\u7a81<\/strong>\uff1a\u8fd9\u79cd\u51b2\u7a81\u66f4\u52a0\u9690\u853d\u548c\u5371\u9669\u3002\u867d\u7136Git\u80fd\u591f\u81ea\u52a8\u5408\u5e76\u4ee3\u7801\uff0c\u4f46\u5408\u5e76\u540e\u7684\u4ee3\u7801\u5728\u8bed\u4e49\u4e0a\u662f\u9519\u8bef\u7684\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u7a0b\u5e8f\u5458\u91cd\u547d\u540d\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u53e6\u4e00\u4e2a\u7a0b\u5e8f\u5458\u5728\u5176\u4ed6\u5730\u65b9\u8c03\u7528\u4e86\u8fd9\u4e2a\u51fd\u6570\u7684\u65e7\u540d\u79f0\u3002Git\u80fd\u6210\u529f\u5408\u5e76\uff0c\u4f46\u7a0b\u5e8f\u4f1a\u7f16\u8bd1\u5931\u8d25\u3002<\/p>\n<p>\u6211\u66fe\u7ecf\u9047\u5230\u8fc7\u4e00\u4e2a\u66f4\u9690\u853d\u7684\u8bed\u4e49\u51b2\u7a81\uff1a\u4e00\u4e2a\u540c\u4e8b\u4fee\u6539\u4e86\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u7684\u5b9a\u4e49\uff0c\u589e\u52a0\u4e86\u4e00\u4e2a\u5b57\u6bb5\uff1b\u800c\u6211\u5728\u53e6\u4e00\u4e2a\u5730\u65b9\u4f7f\u7528\u4e86\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\uff0c\u4f46\u4f7f\u7528\u7684\u662f\u65e7\u7684\u5b9a\u4e49\u3002Git\u6210\u529f\u5408\u5e76\u4e86\u4ee3\u7801\uff0c\u7f16\u8bd1\u4e5f\u901a\u8fc7\u4e86\uff0c\u4f46\u7a0b\u5e8f\u8fd0\u884c\u65f6\u4f1a\u4ea7\u751f\u968f\u673a\u7684\u5185\u5b58\u9519\u8bef\u3002\u8fd9\u79cd\u95ee\u9898\u975e\u5e38\u96be\u4ee5\u8c03\u8bd5\uff0c\u6211\u4eec\u82b1\u4e86\u6574\u6574\u4e00\u4e2a\u661f\u671f\u624d\u627e\u5230\u6839\u56e0\u3002<\/p>\n<p><strong>\u4e8c\u8fdb\u5236\u6587\u4ef6\u51b2\u7a81<\/strong>\uff1a\u5f53\u591a\u4e2a\u7a0b\u5e8f\u5458\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u6bd4\u5982\u56fe\u7247\u3001\u6587\u6863\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\u65f6\uff0cGit\u65e0\u6cd5\u8fdb\u884c\u667a\u80fd\u5408\u5e76\uff0c\u53ea\u80fd\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u7248\u672c\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f80\u5f80\u9700\u8981\u624b\u52a8\u534f\u8c03\uff0c\u51b3\u5b9a\u91c7\u7528\u54ea\u4e2a\u7248\u672c\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"750\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlRE7\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u4e09\u3001\u56e2\u961f\u534f\u4f5c\u4e2d\u7684&#8221;\u51b2\u7a81\u5730\u72f1&#8221;\uff1a\u90a3\u4e9b\u8ba9\u6211\u8bb0\u5fc6\u6df1\u523b\u7684\u56e2\u961f\u914d\u5408\u95ee\u9898<\/h3>\n<p>\u5728\u56e2\u961f\u5f00\u53d1\u4e2d\uff0cGit\u51b2\u7a81\u4e0d\u4ec5\u4ec5\u662f\u6280\u672f\u95ee\u9898\uff0c\u66f4\u662f\u56e2\u961f\u534f\u4f5c\u548c\u6c9f\u901a\u7684\u95ee\u9898\u3002\u6211\u5728\u4e0d\u540c\u7684\u56e2\u961f\u4e2d\u5de5\u4f5c\u8fc7\uff0c\u6df1\u523b\u4f53\u4f1a\u5230\u4e86\u56e2\u961f\u914d\u5408\u5bf9\u4e8e\u51cf\u5c11Git\u51b2\u7a81\u7684\u91cd\u8981\u6027\u3002<\/p>\n<p><strong>\u7f3a\u4e4f\u6c9f\u901a\u5bfc\u81f4\u7684\u91cd\u590d\u52b3\u52a8<\/strong><\/p>\n<p>\u6211\u5728\u67d0\u9a6c\u5de5\u4f5c\u7684\u65f6\u5019\uff0c\u56e2\u961f\u6c9f\u901a\u4e0d\u591f\u5145\u5206\uff0c\u7ecf\u5e38\u51fa\u73b0\u591a\u4e2a\u4eba\u540c\u65f6\u5f00\u53d1\u76f8\u4f3c\u529f\u80fd\u7684\u60c5\u51b5\u3002\u6709\u4e00\u6b21\uff0c\u6211\u548c\u53e6\u4e00\u4e2a\u540c\u4e8b\u4e0d\u7ea6\u800c\u540c\u5730\u90fd\u5728\u4f18\u5316\u540c\u4e00\u4e2a\u7b97\u6cd5\uff0c\u800c\u4e14\u91c7\u7528\u4e86\u4e0d\u540c\u7684\u4f18\u5316\u7b56\u7565\u3002<\/p>\n<p>\u6211\u82b1\u4e86\u4e24\u5929\u65f6\u95f4\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e\u67e5\u627e\u8868\u7684\u4f18\u5316\u65b9\u6848\uff0c\u540c\u4e8b\u82b1\u4e86\u4e09\u5929\u65f6\u95f4\u5b9e\u73b0\u4e86\u4e00\u4e2a\u57fa\u4e8e\u7f13\u5b58\u7684\u4f18\u5316\u65b9\u6848\u3002\u5f53\u6211\u4eec\u90fd\u51c6\u5907\u63d0\u4ea4\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u53d1\u73b0\u5bf9\u540c\u4e00\u4e2a\u51fd\u6570\u8fdb\u884c\u4e86\u5b8c\u5168\u4e0d\u540c\u7684\u91cd\u6784\u3002<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7684\u51b2\u7a81\u89e3\u51b3\u7279\u522b\u75db\u82e6\uff0c\u56e0\u4e3a\u4e24\u4e2a\u65b9\u6848\u90fd\u662f\u53ef\u884c\u7684\uff0c\u4f46\u65e0\u6cd5\u7b80\u5355\u5730\u5408\u5e76\u3002\u6211\u4eec\u4e0d\u5f97\u4e0d\u5750\u4e0b\u6765\u8ba8\u8bba\uff0c\u6bd4\u8f83\u4e24\u79cd\u65b9\u6848\u7684\u4f18\u52a3\uff0c\u6700\u7ec8\u9009\u62e9\u4e86\u4e00\u79cd\u65b9\u6848\uff0c\u53e6\u4e00\u4e2a\u4eba\u7684\u5de5\u4f5c\u57fa\u672c\u767d\u8d39\u4e86\u3002<\/p>\n<p><strong>\u7f3a\u4e4f\u4ee3\u7801\u89c4\u8303\u5bfc\u81f4\u7684\u683c\u5f0f\u51b2\u7a81<\/strong><\/p>\n<p>\u4ee3\u7801\u683c\u5f0f\u7684\u4e0d\u7edf\u4e00\u662f\u5bfc\u81f4Git\u51b2\u7a81\u7684\u4e00\u4e2a\u91cd\u8981\u539f\u56e0\u3002\u6709\u4e9b\u7a0b\u5e8f\u5458\u559c\u6b22\u7528\u7a7a\u683c\u7f29\u8fdb\uff0c\u6709\u4e9b\u559c\u6b22\u7528Tab\uff1b\u6709\u4e9b\u559c\u6b22\u628a\u5927\u62ec\u53f7\u653e\u5728\u540c\u4e00\u884c\uff0c\u6709\u4e9b\u559c\u6b22\u6362\u884c\uff1b\u6709\u4e9b\u559c\u6b22\u5728\u9017\u53f7\u540e\u9762\u52a0\u7a7a\u683c\uff0c\u6709\u4e9b\u4e0d\u52a0\u3002<\/p>\n<p>\u6211\u8bb0\u5f97\u5728\u5916\u4f01\u7684\u4e00\u4e2a\u9879\u76ee\u4e2d\uff0c\u6211\u4eec\u6709\u6765\u81ea\u4e0d\u540c\u56fd\u5bb6\u7684\u7a0b\u5e8f\u5458\uff0c\u5927\u5bb6\u7684\u7f16\u7801\u4e60\u60ef\u5dee\u5f02\u5f88\u5927\u3002\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff0c\u7ecf\u8fc7\u51e0\u4e2a\u4eba\u7684\u4fee\u6539\u540e\uff0c\u53ef\u80fd\u7a7a\u683c\u3001\u6362\u884c\u3001\u6ce8\u91ca\u683c\u5f0f\u90fd\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u6700\u8981\u547d\u7684\u662f\uff0c\u5f88\u591aIDE\u90fd\u6709\u81ea\u52a8\u683c\u5f0f\u5316\u529f\u80fd\u3002\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u5458\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0cIDE\u81ea\u52a8\u683c\u5f0f\u5316\u540e\uff0c\u53ef\u80fd\u4f1a\u4fee\u6539\u51e0\u5341\u884c\u4ee3\u7801\u7684\u683c\u5f0f\uff0c\u867d\u7136\u903b\u8f91\u5b8c\u5168\u6ca1\u53d8\uff0c\u4f46\u5728Git\u770b\u6765\u8fd9\u5c31\u662f\u51e0\u5341\u884c\u7684\u4fee\u6539\u3002\u5f53\u591a\u4e2a\u4eba\u90fd\u8fd9\u6837\u64cd\u4f5c\u65f6\uff0c\u51b2\u7a81\u5c31\u4e0d\u53ef\u907f\u514d\u4e86\u3002<\/p>\n<p><strong>\u7248\u672c\u7ba1\u7406\u7b56\u7565\u7684\u6df7\u4e71<\/strong><\/p>\n<p>\u4e0d\u540c\u7684\u56e2\u961f\u6709\u4e0d\u540c\u7684Git\u5de5\u4f5c\u6d41\uff0c\u4f46\u5982\u679c\u56e2\u961f\u5185\u90e8\u5bf9\u5de5\u4f5c\u6d41\u7684\u7406\u89e3\u4e0d\u4e00\u81f4\uff0c\u5c31\u4f1a\u5bfc\u81f4\u5404\u79cd\u95ee\u9898\u3002<\/p>\n<p>\u6211\u89c1\u8fc7\u4e00\u4e9b\u56e2\u961f\uff0c\u6709\u4e9b\u4eba\u559c\u6b22\u5728master\u5206\u652f\u4e0a\u76f4\u63a5\u5f00\u53d1\uff0c\u6709\u4e9b\u4eba\u559c\u6b22\u521b\u5efafeature\u5206\u652f\uff1b\u6709\u4e9b\u4eba\u559c\u6b22\u9891\u7e41\u63d0\u4ea4\uff0c\u6709\u4e9b\u4eba\u559c\u6b22\u6512\u4e00\u5806\u4fee\u6539\u540e\u4e00\u6b21\u6027\u63d0\u4ea4\uff1b\u6709\u4e9b\u4eba\u559c\u6b22\u7528merge\uff0c\u6709\u4e9b\u4eba\u559c\u6b22\u7528rebase\u3002<\/p>\n<p>\u8fd9\u79cd\u6df7\u4e71\u7684\u7248\u672c\u7ba1\u7406\u7b56\u7565\u4f1a\u5927\u5927\u589e\u52a0\u51b2\u7a81\u7684\u6982\u7387\u3002\u800c\u4e14\uff0c\u5f53\u51b2\u7a81\u53d1\u751f\u65f6\uff0c\u7531\u4e8e\u5927\u5bb6\u5bf9Git\u7684\u7406\u89e3\u7a0b\u5ea6\u4e0d\u540c\uff0c\u89e3\u51b3\u51b2\u7a81\u7684\u65b9\u5f0f\u4e5f\u4e0d\u4e00\u6837\uff0c\u6709\u65f6\u5019\u4f1a\u5f15\u5165\u65b0\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u65f6\u95f4\u538b\u529b\u4e0b\u7684&#8221;\u66b4\u529b&#8221;\u89e3\u51b3<\/strong><\/p>\n<p>\u5728\u9879\u76ee\u7d27\u6025\u7684\u60c5\u51b5\u4e0b\uff0c\u5f88\u591a\u7a0b\u5e8f\u5458\u4f1a\u91c7\u7528\u4e00\u4e9b&#8221;\u66b4\u529b&#8221;\u7684\u65b9\u6cd5\u6765\u89e3\u51b3\u51b2\u7a81\uff0c\u8fd9\u5f80\u5f80\u4f1a\u5e26\u6765\u66f4\u5927\u7684\u95ee\u9898\u3002<\/p>\n<p>\u6211\u89c1\u8fc7\u6709\u540c\u4e8b\u9047\u5230\u590d\u6742\u51b2\u7a81\u65f6\uff0c\u76f4\u63a5\u5220\u9664\u6389\u81ea\u5df1\u7684\u672c\u5730\u5206\u652f\uff0c\u91cd\u65b0\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u62c9\u53d6\u4ee3\u7801\uff0c\u7136\u540e\u624b\u52a8\u91cd\u65b0\u5e94\u7528\u81ea\u5df1\u7684\u4fee\u6539\u3002\u8fd9\u79cd\u505a\u6cd5\u867d\u7136\u80fd\u591f\u907f\u514d\u5904\u7406\u590d\u6742\u7684\u51b2\u7a81\uff0c\u4f46\u4e5f\u5f88\u5bb9\u6613\u4e22\u5931\u4ee3\u7801\u6216\u5f15\u5165\u9519\u8bef\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e9b\u7a0b\u5e8f\u5458\uff0c\u9047\u5230\u51b2\u7a81\u65f6\u4f1a\u9009\u62e9&#8221;\u66b4\u529b\u8986\u76d6&#8221;\uff1a\u76f4\u63a5\u7528\u81ea\u5df1\u7684\u7248\u672c\u8986\u76d6\u6389\u522b\u4eba\u7684\u4fee\u6539\uff0c\u6216\u8005\u5b8c\u5168\u91c7\u7528\u522b\u4eba\u7684\u7248\u672c\u800c\u4e22\u5f03\u81ea\u5df1\u7684\u4fee\u6539\u3002\u8fd9\u79cd\u505a\u6cd5\u867d\u7136\u80fd\u591f\u5feb\u901f\u89e3\u51b3\u51b2\u7a81\uff0c\u4f46\u5f80\u5f80\u4f1a\u5bfc\u81f4\u529f\u80fd\u4e22\u5931\u6216\u5f15\u5165bug\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdkEIv\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u56db\u3001\u9884\u9632\u4e3a\u4e3b\uff1a\u4ece\u6839\u6e90\u4e0a\u51cf\u5c11Git\u51b2\u7a81\u7684\u53d1\u751f<\/h3>\n<p>\u7ecf\u8fc7\u8fd9\u4e9b\u5e74\u7684\u5b9e\u8df5\uff0c\u6211\u6df1\u523b\u8ba4\u8bc6\u5230\uff0c\u9884\u9632Git\u51b2\u7a81\u6bd4\u89e3\u51b3Git\u51b2\u7a81\u66f4\u91cd\u8981\u3002\u5c31\u50cf\u533b\u751f\u5e38\u8bf4\u7684&#8221;\u9884\u9632\u80dc\u4e8e\u6cbb\u7597&#8221;\u4e00\u6837\uff0c\u5728\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0c\u901a\u8fc7\u826f\u597d\u7684\u56e2\u961f\u534f\u4f5c\u548c\u4ee3\u7801\u7ba1\u7406\u5b9e\u8df5\u6765\u51cf\u5c11\u51b2\u7a81\u7684\u53d1\u751f\uff0c\u6bd4\u4e8b\u540e\u5904\u7406\u51b2\u7a81\u8981\u9ad8\u6548\u5f97\u591a\u3002<\/p>\n<p><strong>\u5408\u7406\u7684\u5206\u652f\u7b56\u7565\uff1a\u8ba9\u6bcf\u4e2a\u4eba\u90fd\u6709\u81ea\u5df1\u7684&#8221;\u9886\u5730&#8221;<\/strong><\/p>\n<p>\u4e00\u4e2a\u597d\u7684\u5206\u652f\u7b56\u7565\u662f\u51cf\u5c11\u51b2\u7a81\u7684\u57fa\u7840\u3002\u6211\u5728\u4e0d\u540c\u7684\u56e2\u961f\u4e2d\u5c1d\u8bd5\u8fc7\u5404\u79cd\u5206\u652f\u7b56\u7565\uff0c\u6700\u7ec8\u603b\u7ed3\u51fa\u4e86\u4e00\u5957\u6bd4\u8f83\u5b9e\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>Feature\u5206\u652f\u7b56\u7565<\/strong><\/p>\n<p>\u8fd9\u662f\u6211\u6700\u63a8\u8350\u7684\u7b56\u7565\u3002\u6bcf\u4e2a\u529f\u80fd\u5f00\u53d1\u90fd\u5728\u72ec\u7acb\u7684feature\u5206\u652f\u4e0a\u8fdb\u884c\uff0c\u53ea\u6709\u5728\u529f\u80fd\u5b8c\u6210\u5e76\u6d4b\u8bd5\u901a\u8fc7\u540e\uff0c\u624d\u5408\u5e76\u5230\u4e3b\u5206\u652f\u3002<\/p>\n<pre><code class=\"bash\"># \u521b\u5efa\u65b0\u7684\u529f\u80fd\u5206\u652f\ngit checkout -b feature\/user-authentication\n# \u5728\u529f\u80fd\u5206\u652f\u4e0a\u5f00\u53d1\ngit add .\ngit commit -m &quot;\u5b9e\u73b0\u7528\u6237\u767b\u5f55\u529f\u80fd&quot;\n# \u529f\u80fd\u5b8c\u6210\u540e\u5408\u5e76\u5230\u4e3b\u5206\u652f\ngit checkout master\ngit merge feature\/user-authentication<\/code><\/pre>\n<p>\u8fd9\u79cd\u7b56\u7565\u7684\u597d\u5904\u662f\uff0c\u4e0d\u540c\u529f\u80fd\u7684\u5f00\u53d1\u76f8\u4e92\u72ec\u7acb\uff0c\u51cf\u5c11\u4e86\u76f4\u63a5\u5728\u4e3b\u5206\u652f\u4e0a\u7684\u51b2\u7a81\u3002\u5373\u4f7ffeature\u5206\u652f\u5185\u90e8\u6709\u51b2\u7a81\uff0c\u4e5f\u53ea\u5f71\u54cd\u7279\u5b9a\u7684\u529f\u80fd\u5f00\u53d1\u3002<\/p>\n<p>\u6211\u5728\u73b0\u5728\u7684\u516c\u53f8\u63a8\u884c\u8fd9\u79cd\u7b56\u7565\u540e\uff0c\u4e3b\u5206\u652f\u4e0a\u7684\u51b2\u7a81\u9891\u7387\u964d\u4f4e\u4e8670%\u4ee5\u4e0a\u3002\u7a0b\u5e8f\u5458\u4eec\u53ef\u4ee5\u5728\u81ea\u5df1\u7684\u5206\u652f\u4e0a\u81ea\u7531\u5f00\u53d1\uff0c\u4e0d\u7528\u62c5\u5fc3\u5f71\u54cd\u5176\u4ed6\u4eba\u7684\u5de5\u4f5c\u3002<\/p>\n<p><strong>\u5b9a\u671f\u540c\u6b65\u4e3b\u5206\u652f<\/strong><\/p>\n<p>\u5373\u4f7f\u4f7f\u7528\u4e86feature\u5206\u652f\uff0c\u4e5f\u8981\u5b9a\u671f\u5c06\u4e3b\u5206\u652f\u7684\u6700\u65b0\u4ee3\u7801\u540c\u6b65\u5230\u81ea\u5df1\u7684\u5206\u652f\u4e2d\u3002\u8fd9\u6837\u53ef\u4ee5\u53ca\u65e9\u53d1\u73b0\u6f5c\u5728\u7684\u51b2\u7a81\uff0c\u5728\u51b2\u7a81\u89c4\u6a21\u8fd8\u6bd4\u8f83\u5c0f\u7684\u65f6\u5019\u5c31\u89e3\u51b3\u6389\u3002<\/p>\n<pre><code class=\"bash\"># \u5728feature\u5206\u652f\u4e0a\u5b9a\u671f\u540c\u6b65\u4e3b\u5206\u652f\ngit checkout feature\/user-authentication\ngit merge master\n# \u6216\u8005\u4f7f\u7528rebase\uff08\u6211\u66f4\u559c\u6b22\u8fd9\u79cd\u65b9\u5f0f\uff09\ngit rebase master<\/code><\/pre>\n<p>\u6211\u7684\u4e60\u60ef\u662f\u6bcf\u5929\u65e9\u4e0a\u5f00\u59cb\u5de5\u4f5c\u524d\uff0c\u90fd\u4f1a\u540c\u6b65\u4e00\u6b21\u4e3b\u5206\u652f\u3002\u8fd9\u6837\u5373\u4f7f\u6709\u51b2\u7a81\uff0c\u4e5f\u80fd\u5728\u5f53\u5929\u5c31\u89e3\u51b3\uff0c\u800c\u4e0d\u662f\u7b49\u5230\u6700\u540e\u5408\u5e76\u65f6\u624d\u53d1\u73b0\u5927\u91cf\u51b2\u7a81\u3002<\/p>\n<p><strong>\u6a21\u5757\u5316\u5f00\u53d1\uff1a\u51cf\u5c11\u6587\u4ef6\u7ea7\u522b\u7684\u51b2\u7a81<\/strong><\/p>\n<p>\u826f\u597d\u7684\u4ee3\u7801\u67b6\u6784\u53ef\u4ee5\u4ece\u6839\u672c\u4e0a\u51cf\u5c11\u51b2\u7a81\u7684\u53d1\u751f\u3002\u5982\u679c\u4ee3\u7801\u6a21\u5757\u5316\u7a0b\u5ea6\u9ad8\uff0c\u4e0d\u540c\u529f\u80fd\u7684\u4ee3\u7801\u5206\u5e03\u5728\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d\uff0c\u90a3\u4e48\u591a\u4e2a\u7a0b\u5e8f\u5458\u540c\u65f6\u4fee\u6539\u540c\u4e00\u4e2a\u6587\u4ef6\u7684\u6982\u7387\u5c31\u4f1a\u5927\u5927\u964d\u4f4e\u3002<\/p>\n<p><strong>\u6309\u529f\u80fd\u6a21\u5757\u7ec4\u7ec7\u4ee3\u7801<\/strong><\/p>\n<p>\u6211\u73b0\u5728\u7684\u9879\u76ee\u4e2d\uff0c\u6211\u4eec\u4e25\u683c\u6309\u7167\u529f\u80fd\u6a21\u5757\u6765\u7ec4\u7ec7\u4ee3\u7801\uff1a<\/p>\n<pre><code>src\/\n\u251c\u2500\u2500 user\/          # \u7528\u6237\u6a21\u5757\n\u2502   \u251c\u2500\u2500 user.h\n\u2502   \u251c\u2500\u2500 user.c\n\u2502   \u2514\u2500\u2500 user_test.c\n\u251c\u2500\u2500 auth\/          # \u8ba4\u8bc1\u6a21\u5757\n\u2502   \u251c\u2500\u2500 auth.h\n\u2502   \u251c\u2500\u2500 auth.c\n\u2502   \u2514\u2500\u2500 auth_test.c\n\u251c\u2500\u2500 database\/      # \u6570\u636e\u5e93\u6a21\u5757\n\u2502   \u251c\u2500\u2500 db.h\n\u2502   \u251c\u2500\u2500 db.c\n\u2502   \u2514\u2500\u2500 db_test.c\n\u2514\u2500\u2500 common\/        # \u516c\u5171\u6a21\u5757\n    \u251c\u2500\u2500 common.h\n    \u251c\u2500\u2500 common.c\n    \u2514\u2500\u2500 utils.c<\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u7ec4\u7ec7\u65b9\u5f0f\uff0c\u8ba9\u8d1f\u8d23\u4e0d\u540c\u529f\u80fd\u7684\u7a0b\u5e8f\u5458\u4e3b\u8981\u5728\u5404\u81ea\u7684\u76ee\u5f55\u4e2d\u5de5\u4f5c\uff0c\u5927\u5927\u51cf\u5c11\u4e86\u6587\u4ef6\u7ea7\u522b\u7684\u51b2\u7a81\u3002<\/p>\n<p><strong>\u63a5\u53e3\u8bbe\u8ba1\u7684\u91cd\u8981\u6027<\/strong><\/p>\n<p>\u826f\u597d\u7684\u63a5\u53e3\u8bbe\u8ba1\u53ef\u4ee5\u8ba9\u4e0d\u540c\u6a21\u5757\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u66f4\u52a0\u6e05\u6670\uff0c\u51cf\u5c11\u56e0\u4e3a\u63a5\u53e3\u53d8\u5316\u5bfc\u81f4\u7684\u51b2\u7a81\u3002<\/p>\n<p>\u6211\u5728\u8bbe\u8ba1\u6a21\u5757\u63a5\u53e3\u65f6\uff0c\u4f1a\u5c3d\u91cf\u4fdd\u6301\u63a5\u53e3\u7684\u7a33\u5b9a\u6027\u3002\u5982\u679c\u9700\u8981\u4fee\u6539\u63a5\u53e3\uff0c\u4f1a\u63d0\u524d\u548c\u56e2\u961f\u6c9f\u901a\uff0c\u786e\u4fdd\u6240\u6709\u76f8\u5173\u7684\u7a0b\u5e8f\u5458\u90fd\u77e5\u9053\u8fd9\u4e2a\u53d8\u5316\u3002<\/p>\n<p><strong>\u4ee3\u7801\u89c4\u8303\u548c\u81ea\u52a8\u5316\u5de5\u5177\uff1a\u8ba9\u673a\u5668\u5e2e\u6211\u4eec\u907f\u514d\u4f4e\u7ea7\u51b2\u7a81<\/strong><\/p>\n<p>\u7edf\u4e00\u7684\u4ee3\u7801\u89c4\u8303\u53ef\u4ee5\u907f\u514d\u5f88\u591a\u4e0d\u5fc5\u8981\u7684\u683c\u5f0f\u51b2\u7a81\u3002\u4f46\u4ec5\u4ec5\u6709\u89c4\u8303\u662f\u4e0d\u591f\u7684\uff0c\u8fd8\u9700\u8981\u81ea\u52a8\u5316\u5de5\u5177\u6765\u786e\u4fdd\u89c4\u8303\u7684\u6267\u884c\u3002<\/p>\n<p><strong>\u4f7f\u7528\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177<\/strong><\/p>\n<p>\u6211\u4eec\u56e2\u961f\u73b0\u5728\u4f7f\u7528clang-format\u6765\u81ea\u52a8\u683c\u5f0f\u5316C\/C++\u4ee3\u7801\u3002\u5728\u63d0\u4ea4\u4ee3\u7801\u4e4b\u524d\uff0c\u6211\u4eec\u4f1a\u8fd0\u884c\u683c\u5f0f\u5316\u5de5\u5177\uff0c\u786e\u4fdd\u6240\u6709\u4ee3\u7801\u7684\u683c\u5f0f\u90fd\u662f\u4e00\u81f4\u7684\u3002<\/p>\n<pre><code class=\"bash\"># \u81ea\u52a8\u683c\u5f0f\u5316\u6240\u6709.c\u548c.h\u6587\u4ef6\nfind . -name &quot;*.c&quot; -o -name &quot;*.h&quot; | xargs clang-format -i<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u907f\u514d\u4e86\u56e0\u4e3a\u683c\u5f0f\u5dee\u5f02\u5bfc\u81f4\u7684\u51b2\u7a81\u3002\u5373\u4f7f\u591a\u4e2a\u7a0b\u5e8f\u5458\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u53ea\u8981\u903b\u8f91\u6ca1\u6709\u51b2\u7a81\uff0c\u683c\u5f0f\u5316\u540e\u5c31\u53ef\u4ee5\u6b63\u5e38\u5408\u5e76\u3002<\/p>\n<p><strong>Git hooks\u7684\u4f7f\u7528<\/strong><\/p>\n<p>\u6211\u4eec\u8fd8\u4f7f\u7528Git hooks\u6765\u81ea\u52a8\u68c0\u67e5\u4ee3\u7801\u8d28\u91cf\u548c\u683c\u5f0f\u3002\u5728pre-commit hook\u4e2d\uff0c\u6211\u4eec\u4f1a\u8fd0\u884c\u4ee3\u7801\u683c\u5f0f\u5316\u548c\u57fa\u672c\u7684\u8bed\u6cd5\u68c0\u67e5\uff1a<\/p>\n<pre><code class=\"bash\">#!\/bin\/bash\n# pre-commit hook\n# \u8fd0\u884c\u4ee3\u7801\u683c\u5f0f\u5316\nfind . -name &quot;*.c&quot; -o -name &quot;*.h&quot; | xargs clang-format -i\n# \u68c0\u67e5\u662f\u5426\u6709\u683c\u5f0f\u5316\u7684\u4fee\u6539\nif ! git diff --quiet; then\n    echo &quot;\u4ee3\u7801\u5df2\u81ea\u52a8\u683c\u5f0f\u5316\uff0c\u8bf7\u91cd\u65b0\u63d0\u4ea4&quot;\n    exit 1\nfi\n# \u8fd0\u884c\u57fa\u672c\u7684\u8bed\u6cd5\u68c0\u67e5\nmake check\nif [ $? -ne 0 ]; then\n    echo &quot;\u4ee3\u7801\u68c0\u67e5\u5931\u8d25\uff0c\u8bf7\u4fee\u590d\u9519\u8bef\u540e\u518d\u63d0\u4ea4&quot;\n    exit 1\nfi<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u63d0\u4ea4\u5230\u4ed3\u5e93\u7684\u4ee3\u7801\u90fd\u7b26\u5408\u7edf\u4e00\u7684\u6807\u51c6\uff0c\u51cf\u5c11\u540e\u7eed\u7684\u51b2\u7a81\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"401\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlLdC\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u4e94\u3001\u56e2\u961f\u6c9f\u901a\uff1a\u6280\u672f\u4e4b\u5916\u7684&#8221;\u8f6f\u6280\u80fd&#8221;<\/h3>\n<p>\u5728\u6211\u7684\u804c\u4e1a\u751f\u6daf\u4e2d\uff0c\u6211\u9010\u6e10\u8ba4\u8bc6\u5230\uff0c\u6280\u672f\u53ea\u662f\u907f\u514dGit\u51b2\u7a81\u7684\u4e00\u4e2a\u65b9\u9762\uff0c\u66f4\u91cd\u8981\u7684\u662f\u56e2\u961f\u4e4b\u95f4\u7684\u6c9f\u901a\u548c\u534f\u8c03\u3002\u5f88\u591a\u51b2\u7a81\u7684\u6839\u672c\u539f\u56e0\u4e0d\u662f\u6280\u672f\u95ee\u9898\uff0c\u800c\u662f\u6c9f\u901a\u95ee\u9898\u3002<\/p>\n<p><strong>\u5f00\u53d1\u524d\u7684\u4efb\u52a1\u5206\u5de5\u548c\u6c9f\u901a<\/strong><\/p>\n<p>\u6bcf\u6b21\u5f00\u59cb\u65b0\u529f\u80fd\u7684\u5f00\u53d1\u524d\uff0c\u6211\u4eec\u56e2\u961f\u90fd\u4f1a\u4e3e\u884c\u4e00\u4e2a\u7b80\u77ed\u7684\u4f1a\u8bae\uff0c\u660e\u786e\u5404\u81ea\u7684\u804c\u8d23\u8303\u56f4\u548c\u53ef\u80fd\u7684\u4ea4\u53c9\u70b9\u3002<\/p>\n<p>\u6211\u8bb0\u5f97\u6709\u4e00\u6b21\uff0c\u6211\u4eec\u8981\u5f00\u53d1\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5904\u7406\u6a21\u5757\uff0c\u6d89\u53ca\u5230\u524d\u7aef\u5c55\u793a\u3001\u540e\u7aefAPI\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u4e09\u4e2a\u65b9\u9762\u3002\u5728\u5206\u5de5\u4f1a\u8bae\u4e0a\uff0c\u6211\u4eec\u660e\u786e\u4e86\uff1a<\/p>\n<ul>\n<li>\u5c0f\u674e\u8d1f\u8d23\u524d\u7aef\u754c\u9762\uff0c\u4e3b\u8981\u4fee\u6539<code>src\/frontend\/<\/code>\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6<\/li>\n<li>\u6211\u8d1f\u8d23\u540e\u7aefAPI\uff0c\u4e3b\u8981\u4fee\u6539<code>src\/api\/<\/code>\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6<\/li>\n<li>\u5c0f\u738b\u8d1f\u8d23\u6570\u636e\u5e93\u8bbe\u8ba1\uff0c\u4e3b\u8981\u4fee\u6539<code>src\/database\/<\/code>\u76ee\u5f55\u548cSQL\u811a\u672c<\/li>\n<\/ul>\n<p>\u4f46\u662f\uff0c\u6211\u4eec\u4e5f\u8bc6\u522b\u51fa\u4e86\u51e0\u4e2a\u53ef\u80fd\u7684\u4ea4\u53c9\u70b9\uff1a<\/p>\n<ul>\n<li>API\u63a5\u53e3\u7684\u5b9a\u4e49\u9700\u8981\u524d\u540e\u7aef\u5171\u540c\u786e\u5b9a<\/li>\n<li>\u6570\u636e\u5e93\u8868\u7ed3\u6784\u53d8\u5316\u53ef\u80fd\u5f71\u54cdAPI\u7684\u5b9e\u73b0<\/li>\n<li>\u524d\u7aef\u7684\u67d0\u4e9b\u529f\u80fd\u53ef\u80fd\u9700\u8981\u65b0\u7684API\u652f\u6301<\/li>\n<\/ul>\n<p>\u5bf9\u4e8e\u8fd9\u4e9b\u4ea4\u53c9\u70b9\uff0c\u6211\u4eec\u7ea6\u5b9a\u4e86\u6c9f\u901a\u673a\u5236\uff1a\u4efb\u4f55\u4eba\u8981\u4fee\u6539\u516c\u5171\u63a5\u53e3\u6216\u914d\u7f6e\u6587\u4ef6\u65f6\uff0c\u90fd\u8981\u5148\u5728\u56e2\u961f\u7fa4\u91cc\u901a\u77e5\u4e00\u58f0\uff0c\u786e\u4fdd\u5176\u4ed6\u4eba\u77e5\u9053\u8fd9\u4e2a\u53d8\u5316\u3002<\/p>\n<p><strong>\u5b9e\u65f6\u6c9f\u901a\u7684\u91cd\u8981\u6027<\/strong><\/p>\n<p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5f53\u6211\u53d1\u73b0\u9700\u8981\u4fee\u6539\u4e00\u4e9b\u53ef\u80fd\u5f71\u54cd\u5176\u4ed6\u4eba\u7684\u4ee3\u7801\u65f6\uff0c\u6211\u4f1a\u4e3b\u52a8\u5728\u56e2\u961f\u7fa4\u91cc\u8bf4\u4e00\u58f0\uff1a<\/p>\n<p>&#8220;\u6211\u9700\u8981\u5728<code>common.h<\/code>\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5b8f\u5b9a\u4e49\uff0c\u5927\u5bb6\u6709\u5728\u4fee\u6539\u8fd9\u4e2a\u6587\u4ef6\u5417\uff1f&#8221;<\/p>\n<p>&#8220;\u6211\u8981\u91cd\u6784<code>database.c<\/code>\u4e2d\u7684<code>connect_db<\/code>\u51fd\u6570\uff0c\u5982\u679c\u6709\u4eba\u5728\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u8bf7\u544a\u8bc9\u6211\u4e00\u58f0\u3002&#8221;<\/p>\n<p>\u8fd9\u79cd\u4e3b\u52a8\u7684\u6c9f\u901a\u867d\u7136\u770b\u8d77\u6765\u589e\u52a0\u4e86\u5de5\u4f5c\u91cf\uff0c\u4f46\u5b9e\u9645\u4e0a\u5927\u5927\u51cf\u5c11\u4e86\u540e\u7eed\u5904\u7406\u51b2\u7a81\u7684\u65f6\u95f4\u3002\u800c\u4e14\uff0c\u901a\u8fc7\u5b9e\u65f6\u6c9f\u901a\uff0c\u6211\u4eec\u7ecf\u5e38\u80fd\u53d1\u73b0\u4e00\u4e9b\u8bbe\u8ba1\u4e0a\u7684\u95ee\u9898\uff0c\u53ca\u65e9\u89e3\u51b3\u6bd4\u4e8b\u540e\u4fee\u590d\u8981\u5bb9\u6613\u5f97\u591a\u3002<\/p>\n<p><strong>\u4ee3\u7801\u5ba1\u67e5\u7684\u53cc\u91cd\u4f5c\u7528<\/strong><\/p>\n<p>\u4ee3\u7801\u5ba1\u67e5\uff08Code Review\uff09\u4e0d\u4ec5\u80fd\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\uff0c\u8fd8\u80fd\u51cf\u5c11Git\u51b2\u7a81\u3002\u5728\u5ba1\u67e5\u8fc7\u7a0b\u4e2d\uff0c\u5ba1\u67e5\u8005\u53ef\u4ee5\u53d1\u73b0\u6f5c\u5728\u7684\u51b2\u7a81\u70b9\uff0c\u63d0\u524d\u534f\u8c03\u89e3\u51b3\u3002<\/p>\n<p>\u6211\u4eec\u56e2\u961f\u5b9e\u884c\u4e25\u683c\u7684\u4ee3\u7801\u5ba1\u67e5\u5236\u5ea6\u3002\u6bcf\u4e2apull request\u90fd\u9700\u8981\u81f3\u5c11\u4e24\u4e2a\u4eba\u5ba1\u67e5\u901a\u8fc7\u624d\u80fd\u5408\u5e76\u3002\u5728\u5ba1\u67e5\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u53d1\u73b0\u8fd9\u6837\u7684\u95ee\u9898\uff1a<\/p>\n<ul>\n<li>&#8220;\u8fd9\u4e2a\u4fee\u6539\u4f1a\u5f71\u54cd\u5230\u5c0f\u674e\u6b63\u5728\u5f00\u53d1\u7684\u767b\u5f55\u529f\u80fd\uff0c\u5efa\u8bae\u5148\u548c\u4ed6\u6c9f\u901a\u4e00\u4e0b\u3002&#8221;<\/li>\n<li>&#8220;\u8fd9\u4e2a\u51fd\u6570\u7684\u63a5\u53e3\u53d8\u5316\u6bd4\u8f83\u5927\uff0c\u9700\u8981\u66f4\u65b0\u76f8\u5173\u7684\u6587\u6863\u548c\u6d4b\u8bd5\u7528\u4f8b\u3002&#8221;<\/li>\n<li>&#8220;\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u7684\u4fee\u6539\u53ef\u80fd\u548c\u4e3b\u5206\u652f\u4e0a\u7684\u5176\u4ed6\u4fee\u6539\u51b2\u7a81\uff0c\u5efa\u8bae\u5148\u540c\u6b65\u4e3b\u5206\u652f\u3002&#8221;<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4ee3\u7801\u5ba1\u67e5\uff0c\u6211\u4eec\u80fd\u591f\u5728\u4ee3\u7801\u5408\u5e76\u4e4b\u524d\u5c31\u53d1\u73b0\u548c\u89e3\u51b3\u6f5c\u5728\u7684\u95ee\u9898\uff0c\u907f\u514d\u4e86\u5f88\u591a\u4e0d\u5fc5\u8981\u7684\u51b2\u7a81\u3002<\/p>\n<p><strong>\u5b9a\u671f\u7684\u56e2\u961f\u540c\u6b65\u4f1a\u8bae<\/strong><\/p>\n<p>\u6211\u4eec\u6bcf\u5468\u90fd\u4f1a\u4e3e\u884c\u4e00\u4e2a\u7b80\u77ed\u7684\u6280\u672f\u540c\u6b65\u4f1a\u8bae\uff0c\u8ba8\u8bba\u5f53\u524d\u7684\u5f00\u53d1\u8fdb\u5ea6\u548c\u53ef\u80fd\u7684\u6280\u672f\u95ee\u9898\u3002\u5728\u8fd9\u4e2a\u4f1a\u8bae\u4e0a\uff0c\u6211\u4eec\u4f1a\uff1a<\/p>\n<ul>\n<li>\u6c47\u62a5\u5404\u81ea\u7684\u5f00\u53d1\u8fdb\u5ea6\u548c\u9047\u5230\u7684\u95ee\u9898<\/li>\n<li>\u8ba8\u8bba\u4e0b\u5468\u7684\u5f00\u53d1\u8ba1\u5212\u548c\u53ef\u80fd\u7684\u51b2\u7a81\u70b9<\/li>\n<li>\u5206\u4eab\u4e00\u4e9b\u6709\u7528\u7684\u6280\u672f\u7ecf\u9a8c\u548c\u5de5\u5177<\/li>\n<li>\u56de\u987e\u4e0a\u5468\u7684Git\u51b2\u7a81\uff0c\u5206\u6790\u539f\u56e0\u548c\u6539\u8fdb\u63aa\u65bd<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u5b9a\u671f\u7684\u540c\u6b65\u673a\u5236\uff0c\u8ba9\u56e2\u961f\u6210\u5458\u5bf9\u6574\u4e2a\u9879\u76ee\u7684\u8fdb\u5c55\u6709\u6e05\u6670\u7684\u4e86\u89e3\uff0c\u80fd\u591f\u63d0\u524d\u8bc6\u522b\u548c\u907f\u514d\u6f5c\u5728\u7684\u51b2\u7a81\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdkKSL\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u516d\u3001\u51b2\u7a81\u89e3\u51b3\u7684\u5b9e\u6218\u6280\u5de7\uff1a\u5f53\u9884\u9632\u5931\u6548\u65f6\u8be5\u600e\u4e48\u529e<\/h3>\n<p>\u867d\u7136\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5404\u79cd\u65b9\u6cd5\u6765\u51cf\u5c11Git\u51b2\u7a81\u7684\u53d1\u751f\uff0c\u4f46\u5b8c\u5168\u907f\u514d\u51b2\u7a81\u662f\u4e0d\u73b0\u5b9e\u7684\u3002\u5f53\u51b2\u7a81\u4e0d\u53ef\u907f\u514d\u5730\u53d1\u751f\u65f6\uff0c\u5982\u4f55\u5feb\u901f\u3001\u6b63\u786e\u5730\u89e3\u51b3\u51b2\u7a81\u5c31\u6210\u4e86\u4e00\u9879\u91cd\u8981\u6280\u80fd\u3002<\/p>\n<p><strong>\u7406\u89e3\u51b2\u7a81\u6807\u8bb0\uff1a\u8bfb\u61c2Git\u5728\u544a\u8bc9\u4f60\u4ec0\u4e48<\/strong><\/p>\n<p>\u5f53Git\u68c0\u6d4b\u5230\u51b2\u7a81\u65f6\uff0c\u5b83\u4f1a\u5728\u51b2\u7a81\u7684\u6587\u4ef6\u4e2d\u63d2\u5165\u7279\u6b8a\u7684\u6807\u8bb0\u3002\u7406\u89e3\u8fd9\u4e9b\u6807\u8bb0\u7684\u542b\u4e49\u662f\u89e3\u51b3\u51b2\u7a81\u7684\u7b2c\u4e00\u6b65\u3002<\/p>\n<pre><code class=\"c\">&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD\n\/\/ \u8fd9\u662f\u4f60\u5f53\u524d\u5206\u652f\u7684\u4ee3\u7801\nvoid function_a() {\n    printf(&quot;My implementation\/n&quot;);\n}\n=======\n\/\/ \u8fd9\u662f\u8981\u5408\u5e76\u7684\u5206\u652f\u7684\u4ee3\u7801\nvoid function_a() {\n    printf(&quot;Other implementation\/n&quot;);\n}\n&gt;&gt;&gt;&gt;&gt;&gt;&gt; feature\/new-function<\/code><\/pre>\n<ul>\n<li><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/code>\uff1a\u8868\u793a\u5f53\u524d\u5206\u652f\uff08\u901a\u5e38\u662f\u4f60\u6b63\u5728\u5de5\u4f5c\u7684\u5206\u652f\uff09\u7684\u4ee3\u7801\u5f00\u59cb<\/li>\n<li><code>=======<\/code>\uff1a\u5206\u9694\u7ebf\uff0c\u4e0a\u9762\u662f\u5f53\u524d\u5206\u652f\u7684\u4ee3\u7801\uff0c\u4e0b\u9762\u662f\u8981\u5408\u5e76\u7684\u5206\u652f\u7684\u4ee3\u7801<\/li>\n<li><code>&gt;&gt;&gt;&gt;&gt;&gt;&gt; branch-name<\/code>\uff1a\u8868\u793a\u8981\u5408\u5e76\u7684\u5206\u652f\u7684\u4ee3\u7801\u7ed3\u675f<\/li>\n<\/ul>\n<p>\u7406\u89e3\u4e86\u8fd9\u4e9b\u6807\u8bb0\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u6765\u51b3\u5b9a\u5982\u4f55\u5408\u5e76\u4ee3\u7801\u3002<\/p>\n<p><strong>\u4e09\u79cd\u57fa\u672c\u7684\u51b2\u7a81\u89e3\u51b3\u7b56\u7565<\/strong><\/p>\n<p>\u6839\u636e\u6211\u7684\u7ecf\u9a8c\uff0c\u5927\u90e8\u5206\u51b2\u7a81\u53ef\u4ee5\u7528\u4e09\u79cd\u57fa\u672c\u7b56\u7565\u6765\u89e3\u51b3\uff1a<\/p>\n<p><strong>1. \u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u7248\u672c<\/strong><\/p>\n<p>\u5f53\u4e24\u4e2a\u7248\u672c\u7684\u4ee3\u7801\u90fd\u80fd\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\uff0c\u4f46\u5b9e\u73b0\u65b9\u5f0f\u4e0d\u540c\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u7248\u672c\u3002<\/p>\n<pre><code class=\"c\">\/\/ \u5047\u8bbe\u6211\u4eec\u9009\u62e9\u4fdd\u7559\u5f53\u524d\u5206\u652f\u7684\u7248\u672c\nvoid function_a() {\n    printf(&quot;My implementation\/n&quot;);\n}<\/code><\/pre>\n<p>\u5220\u9664\u6240\u6709\u7684\u51b2\u7a81\u6807\u8bb0\uff0c\u53ea\u4fdd\u7559\u60f3\u8981\u7684\u4ee3\u7801\u5373\u53ef\u3002<\/p>\n<p><strong>2. \u5408\u5e76\u4e24\u4e2a\u7248\u672c\u7684\u529f\u80fd<\/strong><\/p>\n<p>\u6709\u65f6\u5019\uff0c\u4e24\u4e2a\u7248\u672c\u7684\u4ee3\u7801\u5b9e\u73b0\u4e86\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5b83\u4eec\u5408\u5e76\u8d77\u6765\u3002<\/p>\n<pre><code class=\"c\">\/\/ \u5408\u5e76\u540e\u7684\u4ee3\u7801\nvoid function_a() {\n    printf(&quot;My implementation\/n&quot;);\n    printf(&quot;Other implementation\/n&quot;);\n}<\/code><\/pre>\n<p><strong>3. \u5b8c\u5168\u91cd\u5199<\/strong><\/p>\n<p>\u5f53\u4e24\u4e2a\u7248\u672c\u7684\u4ee3\u7801\u90fd\u6709\u95ee\u9898\uff0c\u6216\u8005\u9700\u8981\u91c7\u7528\u5168\u65b0\u7684\u5b9e\u73b0\u65b9\u5f0f\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5220\u9664\u51b2\u7a81\u7684\u4ee3\u7801\uff0c\u91cd\u65b0\u5b9e\u73b0\u3002<\/p>\n<pre><code class=\"c\">\/\/ \u91cd\u65b0\u5b9e\u73b0\u7684\u4ee3\u7801\nvoid function_a() {\n    printf(&quot;New implementation combining both ideas\/n&quot;);\n}<\/code><\/pre>\n<p><strong>\u4f7f\u7528\u5de5\u5177\u8f85\u52a9\u89e3\u51b3\u51b2\u7a81<\/strong><\/p>\n<p>\u867d\u7136\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u7f16\u8f91\u51b2\u7a81\u6587\u4ef6\u6765\u89e3\u51b3\u51b2\u7a81\uff0c\u4f46\u4f7f\u7528\u4e13\u95e8\u7684\u5408\u5e76\u5de5\u5177\u4f1a\u66f4\u52a0\u9ad8\u6548\u548c\u51c6\u786e\u3002<\/p>\n<p><strong>\u56fe\u5f62\u5316\u5408\u5e76\u5de5\u5177<\/strong><\/p>\n<p>\u6211\u4e2a\u4eba\u6bd4\u8f83\u559c\u6b22\u4f7f\u7528KDiff3\u6216\u8005Beyond Compare\u8fd9\u6837\u7684\u56fe\u5f62\u5316\u5408\u5e76\u5de5\u5177\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e76\u6392\u663e\u793a\u4e09\u4e2a\u7248\u672c\u7684\u4ee3\u7801\uff1a\u5f53\u524d\u5206\u652f\u3001\u8981\u5408\u5e76\u7684\u5206\u652f\u3001\u4ee5\u53ca\u4e24\u8005\u7684\u5171\u540c\u7956\u5148\u3002<\/p>\n<pre><code class=\"bash\"># \u914d\u7f6eGit\u4f7f\u7528KDiff3\u4f5c\u4e3a\u5408\u5e76\u5de5\u5177\ngit config --global merge.tool kdiff3\n# \u5f53\u9047\u5230\u51b2\u7a81\u65f6\uff0c\u4f7f\u7528\u5408\u5e76\u5de5\u5177\ngit mergetool<\/code><\/pre>\n<p>\u56fe\u5f62\u5316\u5de5\u5177\u7684\u597d\u5904\u662f\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u5230\u4ee3\u7801\u7684\u5dee\u5f02\uff0c\u800c\u4e14\u63d0\u4f9b\u4e86\u4e00\u4e9b\u81ea\u52a8\u5408\u5e76\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5904\u7406\u4e00\u4e9b\u7b80\u5355\u7684\u51b2\u7a81\u3002<\/p>\n<p><strong>IDE\u96c6\u6210\u7684\u51b2\u7a81\u89e3\u51b3\u529f\u80fd<\/strong><\/p>\n<p>\u73b0\u4ee3\u7684IDE\u901a\u5e38\u90fd\u96c6\u6210\u4e86Git\u51b2\u7a81\u89e3\u51b3\u529f\u80fd\u3002\u6bd4\u5982\uff0cVSCode\u7684Git\u63d2\u4ef6\u53ef\u4ee5\u9ad8\u4eae\u663e\u793a\u51b2\u7a81\u533a\u57df\uff0c\u63d0\u4f9b&#8221;\u63a5\u53d7\u5f53\u524d\u4fee\u6539&#8221;\u3001&#8221;\u63a5\u53d7\u4f20\u5165\u4fee\u6539&#8221;\u3001&#8221;\u63a5\u53d7\u4e24\u8005\u4fee\u6539&#8221;\u7b49\u5feb\u6377\u64cd\u4f5c\u3002<\/p>\n<p>\u8fd9\u4e9b\u96c6\u6210\u529f\u80fd\u7684\u597d\u5904\u662f\u53ef\u4ee5\u5728\u719f\u6089\u7684\u7f16\u8f91\u73af\u5883\u4e2d\u89e3\u51b3\u51b2\u7a81\uff0c\u800c\u4e14\u901a\u5e38\u63d0\u4f9b\u4e86\u8bed\u6cd5\u9ad8\u4eae\u548c\u4ee3\u7801\u8865\u5168\u7b49\u529f\u80fd\uff0c\u51cf\u5c11\u4e86\u89e3\u51b3\u51b2\u7a81\u65f6\u51fa\u9519\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<p><strong>\u590d\u6742\u51b2\u7a81\u7684\u5206\u6b65\u89e3\u51b3\u6cd5<\/strong><\/p>\n<p>\u5f53\u9047\u5230\u7279\u522b\u590d\u6742\u7684\u51b2\u7a81\u65f6\uff0c\u6211\u901a\u5e38\u91c7\u7528\u5206\u6b65\u89e3\u51b3\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u5148\u5907\u4efd\u5f53\u524d\u72b6\u6001<\/strong><\/p>\n<pre><code class=\"bash\"># \u521b\u5efa\u4e00\u4e2a\u5907\u4efd\u5206\u652f\ngit branch backup-before-merge<\/code><\/pre>\n<p>\u8fd9\u6837\u5373\u4f7f\u89e3\u51b3\u51b2\u7a81\u65f6\u51fa\u9519\uff0c\u4e5f\u53ef\u4ee5\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\u91cd\u65b0\u5f00\u59cb\u3002<\/p>\n<p><strong>2. \u9010\u4e2a\u6587\u4ef6\u89e3\u51b3\u51b2\u7a81<\/strong><\/p>\n<pre><code class=\"bash\"># \u67e5\u770b\u6709\u51b2\u7a81\u7684\u6587\u4ef6\u5217\u8868\ngit status\n# \u9010\u4e2a\u89e3\u51b3\u51b2\u7a81\ngit add resolved_file1.c\ngit add resolved_file2.c<\/code><\/pre>\n<p>\u4e0d\u8981\u8bd5\u56fe\u4e00\u6b21\u6027\u89e3\u51b3\u6240\u6709\u51b2\u7a81\uff0c\u9010\u4e2a\u6587\u4ef6\u5904\u7406\u53ef\u4ee5\u964d\u4f4e\u51fa\u9519\u7684\u6982\u7387\u3002<\/p>\n<p><strong>3. \u7f16\u8bd1\u6d4b\u8bd5\u9a8c\u8bc1<\/strong><\/p>\n<p>\u6bcf\u89e3\u51b3\u4e00\u4e2a\u6587\u4ef6\u7684\u51b2\u7a81\uff0c\u6211\u90fd\u4f1a\u7f16\u8bd1\u4e00\u6b21\uff0c\u786e\u4fdd\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef\uff1a<\/p>\n<pre><code class=\"bash\">make clean &amp;&amp; make\n.\/test_program<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u53ca\u65e9\u53d1\u73b0\u8bed\u4e49\u51b2\u7a81\u6216\u8005\u5176\u4ed6\u95ee\u9898\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlLdA\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u4e03\u3001\u9ad8\u7ea7\u6280\u5de7\uff1a\u8ba9Git\u4e3a\u4f60\u6253\u5de5<\/h3>\n<p>\u5728\u638c\u63e1\u4e86\u57fa\u672c\u7684\u51b2\u7a81\u5904\u7406\u6280\u5de7\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u9ad8\u7ea7\u6280\u5de7\u6765\u8fdb\u4e00\u6b65\u51cf\u5c11Git\u51b2\u7a81\u7684\u75db\u82e6\u3002<\/p>\n<p><strong>Rebase vs Merge\uff1a\u9009\u62e9\u5408\u9002\u7684\u5408\u5e76\u7b56\u7565<\/strong><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7ecf\u5e38\u5f15\u8d77\u4e89\u8bba\u7684\u8bdd\u9898\u3002\u6211\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u5c1d\u8bd5\u8fc7\u4e24\u79cd\u7b56\u7565\uff0c\u5404\u6709\u4f18\u7f3a\u70b9\u3002<\/p>\n<p><strong>Merge\u7684\u4f18\u70b9\u548c\u7f3a\u70b9<\/strong><\/p>\n<p>Merge\u4f1a\u4fdd\u7559\u5b8c\u6574\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u53ef\u4ee5\u6e05\u695a\u5730\u770b\u5230\u5206\u652f\u7684\u5408\u5e76\u70b9\u3002\u4f46\u662f\uff0c\u9891\u7e41\u7684merge\u4f1a\u8ba9Git\u5386\u53f2\u53d8\u5f97\u590d\u6742\uff0c\u51fa\u73b0\u5f88\u591amerge commit\u3002<\/p>\n<pre><code class=\"bash\">git checkout master\ngit merge feature\/new-function<\/code><\/pre>\n<p>\u6211\u5728\u5916\u4f01\u5de5\u4f5c\u65f6\uff0c\u56e2\u961f\u91c7\u7528\u7684\u5c31\u662fmerge\u7b56\u7565\u3002\u597d\u5904\u662f\u5386\u53f2\u8bb0\u5f55\u5b8c\u6574\uff0c\u53ef\u4ee5\u8ffd\u8e2a\u6bcf\u4e2afeature\u7684\u5f00\u53d1\u8fc7\u7a0b\u3002\u4f46\u574f\u5904\u662fGit\u5386\u53f2\u56fe\u53d8\u5f97\u975e\u5e38\u590d\u6742\uff0c\u6709\u65f6\u5019\u5f88\u96be\u7406\u89e3\u4ee3\u7801\u7684\u6f14\u8fdb\u8fc7\u7a0b\u3002<\/p>\n<p><strong>Rebase\u7684\u4f18\u70b9\u548c\u7f3a\u70b9<\/strong><\/p>\n<p>Rebase\u4f1a\u91cd\u5199Git\u5386\u53f2\uff0c\u8ba9\u63d0\u4ea4\u8bb0\u5f55\u770b\u8d77\u6765\u66f4\u52a0\u7ebf\u6027\u548c\u6574\u6d01\u3002\u4f46\u662f\uff0crebase\u4f1a\u6539\u53d8commit\u7684hash\u503c\uff0c\u5728\u591a\u4eba\u534f\u4f5c\u65f6\u53ef\u80fd\u5f15\u8d77\u95ee\u9898\u3002<\/p>\n<pre><code class=\"bash\">git checkout feature\/new-function\ngit rebase master\ngit checkout master\ngit merge feature\/new-function<\/code><\/pre>\n<p>\u6211\u73b0\u5728\u7684\u56e2\u961f\u4e3b\u8981\u4f7f\u7528rebase\u7b56\u7565\u3002\u597d\u5904\u662fGit\u5386\u53f2\u975e\u5e38\u6e05\u6670\uff0c\u6bcf\u4e2afeature\u7684\u63d0\u4ea4\u90fd\u662f\u8fde\u7eed\u7684\u3002\u4f46\u9700\u8981\u56e2\u961f\u6210\u5458\u5bf9Git\u6709\u8f83\u6df1\u7684\u7406\u89e3\uff0c\u5426\u5219\u5bb9\u6613\u51fa\u9519\u3002<\/p>\n<p><strong>\u6211\u7684\u5efa\u8bae<\/strong><\/p>\n<p>\u5bf9\u4e8e\u516c\u5171\u5206\u652f\uff08\u5982master\uff09\uff0c\u5efa\u8bae\u4f7f\u7528merge\uff1b\u5bf9\u4e8e\u4e2a\u4eba\u5206\u652f\uff0c\u53ef\u4ee5\u4f7f\u7528rebase\u6765\u6574\u7406\u63d0\u4ea4\u5386\u53f2\u3002<\/p>\n<p><strong>\u4ea4\u4e92\u5f0fRebase\uff1a\u6574\u7406\u63d0\u4ea4\u5386\u53f2<\/strong><\/p>\n<p>\u4ea4\u4e92\u5f0frebase\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u7528\u6765\u6574\u7406\u63d0\u4ea4\u5386\u53f2\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u51b2\u7a81\u3002<\/p>\n<pre><code class=\"bash\"># \u6574\u7406\u6700\u8fd13\u6b21\u63d0\u4ea4\ngit rebase -i HEAD~3<\/code><\/pre>\n<p>\u5728\u4ea4\u4e92\u5f0frebase\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\uff1a<\/p>\n<ul>\n<li>\u5408\u5e76\u591a\u4e2a\u5c0f\u7684\u63d0\u4ea4<\/li>\n<li>\u4fee\u6539\u63d0\u4ea4\u4fe1\u606f<\/li>\n<li>\u91cd\u65b0\u6392\u5e8f\u63d0\u4ea4<\/li>\n<li>\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u63d0\u4ea4<\/li>\n<\/ul>\n<p>\u6211\u7684\u4e60\u60ef\u662f\u5728\u5408\u5e76\u5230\u4e3b\u5206\u652f\u4e4b\u524d\uff0c\u5148\u7528\u4ea4\u4e92\u5f0frebase\u6574\u7406\u4e00\u4e0b\u81ea\u5df1\u7684\u63d0\u4ea4\u5386\u53f2\uff0c\u628a\u4e00\u4e9b\u5c0f\u7684\u4fee\u590d\u548c\u683c\u5f0f\u8c03\u6574\u5408\u5e76\u5230\u4e3b\u8981\u7684\u529f\u80fd\u63d0\u4ea4\u4e2d\u3002\u8fd9\u6837\u53ef\u4ee5\u8ba9Git\u5386\u53f2\u66f4\u52a0\u6e05\u6670\uff0c\u4e5f\u51cf\u5c11\u4e86\u6f5c\u5728\u7684\u51b2\u7a81\u70b9\u3002<\/p>\n<p><strong>\u4f7f\u7528.gitattributes\u6587\u4ef6\u63a7\u5236\u5408\u5e76\u884c\u4e3a<\/strong><\/p>\n<p>Git\u5141\u8bb8\u6211\u4eec\u901a\u8fc7.gitattributes\u6587\u4ef6\u6765\u63a7\u5236\u7279\u5b9a\u6587\u4ef6\u7684\u5408\u5e76\u884c\u4e3a\u3002<\/p>\n<pre><code class=\"gitattributes\"># \u5bf9\u4e8e\u81ea\u52a8\u751f\u6210\u7684\u6587\u4ef6\uff0c\u4f7f\u7528&quot;ours&quot;\u7b56\u7565\n*.generated merge=ours\n# \u5bf9\u4e8e\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u4e0d\u5c1d\u8bd5\u5408\u5e76\n*.png binary\n*.jpg binary\n# \u5bf9\u4e8e\u7279\u5b9a\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f7f\u7528\u81ea\u5b9a\u4e49\u5408\u5e76\u9a71\u52a8\nconfig.ini merge=custom-config-merge<\/code><\/pre>\n<p>\u8fd9\u4e2a\u529f\u80fd\u5728\u5904\u7406\u4e00\u4e9b\u7279\u6b8a\u6587\u4ef6\u65f6\u975e\u5e38\u6709\u7528\u3002\u6bd4\u5982\uff0c\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7801\u6587\u4ef6\u901a\u5e38\u4e0d\u5e94\u8be5\u624b\u52a8\u5408\u5e76\uff0c\u800c\u5e94\u8be5\u91cd\u65b0\u751f\u6210\u3002<\/p>\n<p><strong>\u4f7f\u7528Git hooks\u81ea\u52a8\u5316\u5904\u7406<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Git hooks\u6765\u81ea\u52a8\u5316\u4e00\u4e9b\u51b2\u7a81\u5904\u7406\u7684\u6d41\u7a0b\u3002<\/p>\n<pre><code class=\"bash\">#!\/bin\/bash\n# post-merge hook\n# \u5728\u5408\u5e76\u540e\u81ea\u52a8\u8fd0\u884c\u6d4b\u8bd5\necho &quot;Running tests after merge...&quot;\nmake test\nif [ $? -ne 0 ]; then\n    echo &quot;Tests failed after merge, please check for conflicts&quot;\n    exit 1\nfi\necho &quot;All tests passed&quot;<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5728\u6bcf\u6b21\u5408\u5e76\u540e\u81ea\u52a8\u8fd0\u884c\u6d4b\u8bd5\uff0c\u53ca\u65e9\u53d1\u73b0\u8bed\u4e49\u51b2\u7a81\u6216\u5176\u4ed6\u95ee\u9898\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"750\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlRE7\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u516b\u3001\u81ea\u52a8\u5316\u5de5\u5177\u548cCI\/CD\uff1a\u8ba9\u673a\u5668\u5e2e\u6211\u4eec\u5904\u7406\u51b2\u7a81<\/h3>\n<p>\u968f\u7740DevOps\u7406\u5ff5\u7684\u666e\u53ca\uff0c\u81ea\u52a8\u5316\u5de5\u5177\u5728\u51cf\u5c11Git\u51b2\u7a81\u65b9\u9762\u53d1\u6325\u7740\u8d8a\u6765\u8d8a\u91cd\u8981\u7684\u4f5c\u7528\u3002\u6211\u5728\u73b0\u5728\u7684\u516c\u53f8\u5927\u529b\u63a8\u884c\u81ea\u52a8\u5316\uff0c\u6548\u679c\u975e\u5e38\u663e\u8457\u3002<\/p>\n<p><strong>\u6301\u7eed\u96c6\u6210\u7684\u4f5c\u7528<\/strong><\/p>\n<p>\u4e00\u4e2a\u597d\u7684CI\/CD\u6d41\u7a0b\u53ef\u4ee5\u5728\u4ee3\u7801\u5408\u5e76\u4e4b\u524d\u5c31\u53d1\u73b0\u6f5c\u5728\u7684\u95ee\u9898\uff0c\u5305\u62ec\u7f16\u8bd1\u9519\u8bef\u3001\u6d4b\u8bd5\u5931\u8d25\u3001\u4ee3\u7801\u89c4\u8303\u8fdd\u53cd\u7b49\u3002<\/p>\n<p>\u6211\u4eec\u7684CI\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<pre><code class=\"yaml\"># .github\/workflows\/ci.yml\nname: CI\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions\/checkout@v2\n    - name: Install dependencies\n      run: sudo apt-get install build-essential\n    - name: Check code format\n      run: |\n        find . -name &quot;*.c&quot; -o -name &quot;*.h&quot; | xargs clang-format --dry-run --Werror\n    - name: Build\n      run: make\n    - name: Run tests\n      run: make test\n    - name: Run static analysis\n      run: cppcheck --error-exitcode=1 src\/<\/code><\/pre>\n<p>\u8fd9\u4e2aCI\u6d41\u7a0b\u4f1a\u5728\u6bcf\u6b21push\u548cpull request\u65f6\u81ea\u52a8\u8fd0\u884c\uff0c\u68c0\u67e5\u4ee3\u7801\u683c\u5f0f\u3001\u7f16\u8bd1\u3001\u6d4b\u8bd5\u3001\u9759\u6001\u5206\u6790\u7b49\u3002\u5982\u679c\u4efb\u4f55\u4e00\u4e2a\u6b65\u9aa4\u5931\u8d25\uff0c\u5c31\u4e0d\u5141\u8bb8\u5408\u5e76\u4ee3\u7801\u3002<\/p>\n<p>\u8fd9\u6837\u7684\u597d\u5904\u662f\uff0c\u5373\u4f7f\u6709\u51b2\u7a81\uff0c\u81f3\u5c11\u53ef\u4ee5\u4fdd\u8bc1\u5408\u5e76\u540e\u7684\u4ee3\u7801\u662f\u53ef\u4ee5\u7f16\u8bd1\u548c\u901a\u8fc7\u57fa\u672c\u6d4b\u8bd5\u7684\u3002<\/p>\n<p><strong>\u81ea\u52a8\u5408\u5e76\u5de5\u5177<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u7b80\u5355\u7684\u51b2\u7a81\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u81ea\u52a8\u5408\u5e76\u5de5\u5177\u6765\u5904\u7406\u3002\u6bd4\u5982\uff0c\u5bf9\u4e8e\u914d\u7f6e\u6587\u4ef6\u7684\u51b2\u7a81\uff0c\u6211\u4eec\u5f00\u53d1\u4e86\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u5408\u5e76\u811a\u672c\uff1a<\/p>\n<pre><code class=\"bash\">#!\/bin\/bash\n# custom-config-merge.sh\n# \u81ea\u52a8\u5408\u5e76\u914d\u7f6e\u6587\u4ef6\u7684\u811a\u672c\n\nBASE=$1    # \u5171\u540c\u7956\u5148\u7248\u672c\nLOCAL=$2   # \u5f53\u524d\u5206\u652f\u7248\u672c  \nREMOTE=$3  # \u8981\u5408\u5e76\u7684\u5206\u652f\u7248\u672c\nMERGED=$4  # \u5408\u5e76\u7ed3\u679c\u6587\u4ef6\n\n# \u4f7f\u7528Python\u811a\u672c\u667a\u80fd\u5408\u5e76\u914d\u7f6e\u6587\u4ef6\npython3 merge_config.py &quot;$BASE&quot; &quot;$LOCAL&quot; &quot;$REMOTE&quot; &quot;$MERGED&quot;\nexit $?<\/code><\/pre>\n<p>\u8fd9\u4e2a\u811a\u672c\u53ef\u4ee5\u667a\u80fd\u5730\u5408\u5e76\u914d\u7f6e\u6587\u4ef6\uff0c\u6bd4\u5982\u81ea\u52a8\u5408\u5e76\u4e0d\u51b2\u7a81\u7684\u914d\u7f6e\u9879\uff0c\u5bf9\u4e8e\u51b2\u7a81\u7684\u914d\u7f6e\u9879\u6309\u7167\u9884\u5b9a\u7684\u4f18\u5148\u7ea7\u89c4\u5219\u6765\u5904\u7406\u3002<\/p>\n<p><strong>Pull Request\u7684\u81ea\u52a8\u68c0\u67e5<\/strong><\/p>\n<p>\u6211\u4eec\u5728GitHub\/GitLab\u4e0a\u8bbe\u7f6e\u4e86\u5404\u79cd\u81ea\u52a8\u68c0\u67e5\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u8986\u76d6\u7387\u5fc5\u987b\u8fbe\u523080%\u4ee5\u4e0a<\/li>\n<li>\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u5fc5\u987b\u901a\u8fc7<\/li>\n<li>\u4ee3\u7801\u5fc5\u987b\u7ecf\u8fc7\u81f3\u5c11\u4e24\u4e2a\u4eba\u7684\u5ba1\u67e5<\/li>\n<li>\u4e0d\u80fd\u6709\u660e\u663e\u7684\u5b89\u5168\u6f0f\u6d1e<\/li>\n<li>\u6587\u6863\u5fc5\u987b\u540c\u6b65\u66f4\u65b0<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u81ea\u52a8\u68c0\u67e5\u53ef\u4ee5\u5728\u4ee3\u7801\u5408\u5e76\u4e4b\u524d\u5c31\u53d1\u73b0\u5f88\u591a\u95ee\u9898\uff0c\u907f\u514d\u4e86\u95ee\u9898\u4ee3\u7801\u8fdb\u5165\u4e3b\u5206\u652f\u540e\u5f15\u8d77\u7684\u51b2\u7a81\u3002<\/p>\n<p><strong>\u667a\u80fd\u51b2\u7a81\u9884\u6d4b<\/strong><\/p>\n<p>\u6211\u4eec\u8fd8\u5f00\u53d1\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u51b2\u7a81\u9884\u6d4b\u5de5\u5177\uff0c\u53ef\u4ee5\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u63d0\u524d\u8b66\u544a\u53ef\u80fd\u7684\u51b2\u7a81\uff1a<\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/env python3\n# conflict_predictor.py\nimport git\nimport os\n\ndef predict_conflicts(repo_path):\n    repo = git.Repo(repo_path)\n    \n    # \u83b7\u53d6\u5f53\u524d\u5206\u652f\u548c\u4e3b\u5206\u652f\u7684\u5dee\u5f02\n    current_branch = repo.active_branch\n    master_branch = repo.heads.master\n    \n    # \u5206\u6790\u4fee\u6539\u7684\u6587\u4ef6\n    current_files = set()\n    for item in repo.index.diff(master_branch):\n        current_files.add(item.a_path)\n    \n    # \u5206\u6790\u5176\u4ed6\u5206\u652f\u7684\u4fee\u6539\n    potential_conflicts = []\n    for branch in repo.heads:\n        if branch == current_branch:\n            continue\n            \n        branch_files = set()\n        for item in repo.index.diff(branch):\n            branch_files.add(item.a_path)\n        \n        # \u627e\u5230\u5171\u540c\u4fee\u6539\u7684\u6587\u4ef6\n        common_files = current_files.intersection(branch_files)\n        if common_files:\n            potential_conflicts.append((branch.name, common_files))\n    \n    return potential_conflicts\n\nif __name__ == &quot;__main__&quot;:\n    conflicts = predict_conflicts(&quot;.&quot;)\n    if conflicts:\n        print(&quot;\u8b66\u544a\uff1a\u68c0\u6d4b\u5230\u6f5c\u5728\u51b2\u7a81&quot;)\n        for branch, files in conflicts:\n            print(f&quot;  \u4e0e\u5206\u652f {branch} \u5728\u4ee5\u4e0b\u6587\u4ef6\u53ef\u80fd\u51b2\u7a81\uff1a&quot;)\n            for file in files:\n                print(f&quot;    - {file}&quot;)\n    else:\n        print(&quot;\u672a\u68c0\u6d4b\u5230\u6f5c\u5728\u51b2\u7a81&quot;)<\/code><\/pre>\n<p>\u8fd9\u4e2a\u5de5\u5177\u53ef\u4ee5\u5b9a\u671f\u8fd0\u884c\uff0c\u63d0\u524d\u8b66\u544a\u5f00\u53d1\u8005\u53ef\u80fd\u7684\u51b2\u7a81\uff0c\u8ba9\u4ed6\u4eec\u6709\u65f6\u95f4\u534f\u8c03\u89e3\u51b3\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdkxnF\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u4e5d\u3001\u7279\u6b8a\u573a\u666f\u7684\u5904\u7406\uff1a\u90a3\u4e9b\u8ba9\u4eba\u5934\u75bc\u7684\u8fb9\u7f18\u60c5\u51b5<\/h3>\n<p>\u5728\u6211\u7684\u804c\u4e1a\u751f\u6daf\u4e2d\uff0c\u6211\u9047\u5230\u8fc7\u4e00\u4e9b\u7279\u6b8a\u7684Git\u51b2\u7a81\u573a\u666f\uff0c\u8fd9\u4e9b\u573a\u666f\u5f80\u5f80\u4e0d\u80fd\u7528\u5e38\u89c4\u65b9\u6cd5\u89e3\u51b3\uff0c\u9700\u8981\u4e00\u4e9b\u7279\u6b8a\u7684\u6280\u5de7\u3002<\/p>\n<p><strong>\u5927\u6587\u4ef6\u548c\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u51b2\u7a81<\/strong><\/p>\n<p>\u5f53\u591a\u4e2a\u4eba\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u5982\u56fe\u7247\u3001\u89c6\u9891\u3001\u7f16\u8bd1\u540e\u7684\u5e93\u6587\u4ef6\u7b49\uff09\u65f6\uff0cGit\u65e0\u6cd5\u8fdb\u884c\u667a\u80fd\u5408\u5e76\uff0c\u53ea\u80fd\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u7248\u672c\u3002<\/p>\n<p>\u6211\u9047\u5230\u8fc7\u4e00\u4e2a\u9879\u76ee\uff0c\u591a\u4e2a\u8bbe\u8ba1\u5e08\u540c\u65f6\u4fee\u6539\u4e86\u540c\u4e00\u4e2aUI\u539f\u578b\u6587\u4ef6\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6280\u672f\u624b\u6bb5\u65e0\u6cd5\u89e3\u51b3\u51b2\u7a81\uff0c\u53ea\u80fd\u901a\u8fc7\u4eba\u5de5\u534f\u8c03\u3002<\/p>\n<p>\u6211\u4eec\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff1a<\/p>\n<ol>\n<li>\u5efa\u7acb\u6587\u4ef6\u4fee\u6539\u7684\u9884\u7ea6\u673a\u5236\uff0c\u907f\u514d\u591a\u4eba\u540c\u65f6\u4fee\u6539\u540c\u4e00\u4e2a\u6587\u4ef6<\/li>\n<li>\u5bf9\u4e8e\u91cd\u8981\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff0c\u4f7f\u7528\u4e13\u95e8\u7684\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff08\u5982Git LFS\uff09<\/li>\n<li>\u5b9a\u671f\u5907\u4efd\u91cd\u8981\u6587\u4ef6\uff0c\u907f\u514d\u6570\u636e\u4e22\u5931<\/li>\n<\/ol>\n<p><strong>\u8de8\u5e73\u53f0\u5f00\u53d1\u7684\u6362\u884c\u7b26\u51b2\u7a81<\/strong><\/p>\n<p>\u5728\u8de8\u5e73\u53f0\u5f00\u53d1\u4e2d\uff0c\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u7684\u6362\u884c\u7b26\u4e0d\u540c\uff08Windows\u4f7f\u7528CRLF\uff0cUnix\/Linux\u4f7f\u7528LF\uff09\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u5927\u91cf\u65e0\u610f\u4e49\u7684\u51b2\u7a81\u3002<\/p>\n<pre><code class=\"bash\"># \u914d\u7f6eGit\u81ea\u52a8\u5904\u7406\u6362\u884c\u7b26\ngit config --global core.autocrlf true   # Windows\ngit config --global core.autocrlf input  # Mac\/Linux<\/code><\/pre>\n<p>\u6211\u4eec\u56e2\u961f\u73b0\u5728\u7edf\u4e00\u4f7f\u7528LF\u4f5c\u4e3a\u6362\u884c\u7b26\uff0c\u5e76\u5728.gitattributes\u6587\u4ef6\u4e2d\u660e\u786e\u6307\u5b9a\uff1a<\/p>\n<pre><code class=\"gitattributes\"># \u5f3a\u5236\u6240\u6709\u6587\u672c\u6587\u4ef6\u4f7f\u7528LF\u6362\u884c\u7b26\n* text=auto eol=lf<\/code><\/pre>\n<p><strong>\u5927\u89c4\u6a21\u91cd\u6784\u65f6\u7684\u51b2\u7a81\u5904\u7406<\/strong><\/p>\n<p>\u5f53\u8fdb\u884c\u5927\u89c4\u6a21\u4ee3\u7801\u91cd\u6784\u65f6\uff08\u5982\u91cd\u547d\u540d\u51fd\u6570\u3001\u91cd\u65b0\u7ec4\u7ec7\u6587\u4ef6\u7ed3\u6784\u7b49\uff09\uff0c\u5f88\u5bb9\u6613\u4e0e\u5176\u4ed6\u4eba\u7684\u4fee\u6539\u4ea7\u751f\u5927\u91cf\u51b2\u7a81\u3002<\/p>\n<p>\u6211\u7684\u5904\u7406\u7b56\u7565\u662f\uff1a<\/p>\n<ol>\n<li><strong>\u5206\u9636\u6bb5\u91cd\u6784<\/strong>\uff1a\u4e0d\u8981\u4e00\u6b21\u6027\u8fdb\u884c\u5927\u89c4\u6a21\u91cd\u6784\uff0c\u800c\u662f\u5206\u6210\u591a\u4e2a\u5c0f\u7684\u9636\u6bb5<\/li>\n<li><strong>\u63d0\u524d\u6c9f\u901a<\/strong>\uff1a\u91cd\u6784\u524d\u901a\u77e5\u56e2\u961f\uff0c\u6682\u505c\u5bf9\u76f8\u5173\u6587\u4ef6\u7684\u4fee\u6539<\/li>\n<li><strong>\u4f7f\u7528Git\u7684\u91cd\u547d\u540d\u68c0\u6d4b<\/strong>\uff1a\u5408\u7406\u5229\u7528Git\u7684rename detection\u529f\u80fd<\/li>\n<\/ol>\n<pre><code class=\"bash\"># \u63d0\u9ad8Git\u7684\u91cd\u547d\u540d\u68c0\u6d4b\u654f\u611f\u5ea6\ngit config diff.renames true\ngit config merge.renameLimit 999999<\/code><\/pre>\n<p><strong>\u7b2c\u4e09\u65b9\u5e93\u66f4\u65b0\u5f15\u8d77\u7684\u51b2\u7a81<\/strong><\/p>\n<p>\u5f53\u9879\u76ee\u4f9d\u8d56\u7684\u7b2c\u4e09\u65b9\u5e93\u66f4\u65b0\u65f6\uff0c\u53ef\u80fd\u4f1a\u4e0e\u672c\u5730\u7684\u4fee\u6539\u4ea7\u751f\u51b2\u7a81\u3002\u8fd9\u79cd\u60c5\u51b5\u7279\u522b\u5e38\u89c1\u4e8e\u76f4\u63a5\u4fee\u6539\u4e86\u7b2c\u4e09\u65b9\u5e93\u4ee3\u7801\u7684\u9879\u76ee\u3002<\/p>\n<p>\u6211\u7684\u5efa\u8bae\u662f\uff1a<\/p>\n<ol>\n<li><strong>\u907f\u514d\u76f4\u63a5\u4fee\u6539\u7b2c\u4e09\u65b9\u5e93<\/strong>\uff1a\u4f7f\u7528\u7ee7\u627f\u3001\u7ec4\u5408\u6216\u63d2\u4ef6\u673a\u5236\u6765\u6269\u5c55\u529f\u80fd<\/li>\n<li><strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177<\/strong>\uff1a\u901a\u8fc7npm\u3001pip\u3001cargo\u7b49\u5de5\u5177\u7ba1\u7406\u4f9d\u8d56<\/li>\n<li><strong>\u7ef4\u62a4\u672c\u5730\u8865\u4e01<\/strong>\uff1a\u5982\u679c\u5fc5\u987b\u4fee\u6539\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f7f\u7528Git\u7684patch\u529f\u80fd\u6765\u7ba1\u7406\u4fee\u6539<\/li>\n<\/ol>\n<pre><code class=\"bash\"># \u751f\u6210\u8865\u4e01\u6587\u4ef6\ngit format-patch origin\/master --stdout &gt; our-changes.patch\n# \u5728\u65b0\u7248\u672c\u4e0a\u5e94\u7528\u8865\u4e01\ngit apply our-changes.patch<\/code><\/pre>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlRE8\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u5341\u3001\u4ece\u5931\u8d25\u4e2d\u5b66\u4e60\uff1a\u90a3\u4e9b\u8ba9\u6211\u5370\u8c61\u6df1\u523b\u7684&#8221;\u7ffb\u8f66&#8221;\u7ecf\u5386<\/h3>\n<p>\u5728\u6211\u7684Git\u4f7f\u7528\u5386\u7a0b\u4e2d\uff0c\u6709\u51e0\u6b21\u4e25\u91cd\u7684&#8221;\u7ffb\u8f66&#8221;\u7ecf\u5386\uff0c\u867d\u7136\u5f53\u65f6\u5f88\u75db\u82e6\uff0c\u4f46\u8fd9\u4e9b\u7ecf\u5386\u6559\u4f1a\u4e86\u6211\u5f88\u591a\u5b9d\u8d35\u7684\u7ecf\u9a8c\u3002<\/p>\n<p><strong>&#8220;\u6d88\u5931&#8221;\u7684\u4ee3\u7801<\/strong><\/p>\n<p>\u6211\u6c38\u8fdc\u5fd8\u4e0d\u4e862017\u5e74\u7684\u90a3\u4e2a\u5468\u4e94\u4e0b\u5348\u3002\u6211\u5728\u89e3\u51b3\u4e00\u4e2a\u590d\u6742\u7684\u5408\u5e76\u51b2\u7a81\u65f6\uff0c\u4e0d\u5c0f\u5fc3\u6267\u884c\u4e86\u9519\u8bef\u7684Git\u547d\u4ee4\uff0c\u5bfc\u81f4\u6211\u4e00\u5468\u7684\u5de5\u4f5c\u6210\u679c\u5168\u90e8\u4e22\u5931\u3002<\/p>\n<p>\u5f53\u65f6\u7684\u60c5\u51b5\u662f\u8fd9\u6837\u7684\uff1a\u6211\u5728feature\u5206\u652f\u4e0a\u5f00\u53d1\u4e86\u4e00\u4e2a\u65b0\u529f\u80fd\uff0c\u4ee3\u7801\u5199\u4e86\u5927\u6982500\u884c\u3002\u5728\u5408\u5e76\u5230master\u5206\u652f\u65f6\u9047\u5230\u4e86\u590d\u6742\u7684\u51b2\u7a81\uff0c\u6211\u8bd5\u56fe\u4f7f\u7528<code>git reset --hard<\/code>\u6765\u56de\u5230\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u4f46\u641e\u9519\u4e86\u53c2\u6570\uff0c\u7ed3\u679c\u628a\u6211\u7684feature\u5206\u652f\u4e5f\u91cd\u7f6e\u4e86\u3002<\/p>\n<p>\u90a3\u79cd\u7edd\u671b\u7684\u5fc3\u60c5\u81f3\u4eca\u8bb0\u5fc6\u72b9\u65b0\u3002\u6211\u5728\u7535\u8111\u524d\u5750\u4e86\u5341\u5206\u949f\uff0c\u5b8c\u5168\u4e0d\u77e5\u9053\u8be5\u600e\u4e48\u529e\u3002\u5e78\u597d\uff0c\u540c\u4e8b\u544a\u8bc9\u6211Git\u6709reflog\u529f\u80fd\uff0c\u53ef\u4ee5\u627e\u56de&#8221;\u4e22\u5931&#8221;\u7684\u63d0\u4ea4\uff1a<\/p>\n<pre><code class=\"bash\"># \u67e5\u770b\u5f15\u7528\u65e5\u5fd7\ngit reflog\n# \u627e\u5230\u4e22\u5931\u7684\u63d0\u4ea4\uff0c\u6062\u590d\u5230\u8be5\u72b6\u6001\ngit reset --hard HEAD@{10}<\/code><\/pre>\n<p>\u6700\u7ec8\u6211\u627e\u56de\u4e86\u5927\u90e8\u5206\u4ee3\u7801\uff0c\u53ea\u635f\u5931\u4e86\u5f53\u5929\u4e0b\u5348\u7684\u5de5\u4f5c\u3002\u4ece\u90a3\u4ee5\u540e\uff0c\u6211\u517b\u6210\u4e86\u9891\u7e41\u63d0\u4ea4\u7684\u4e60\u60ef\uff0c\u5373\u4f7f\u662f\u4e34\u65f6\u7684\u3001\u4e0d\u5b8c\u6574\u7684\u4ee3\u7801\u4e5f\u4f1a\u63d0\u4ea4\u5230\u672c\u5730\uff0c\u8fd9\u6837\u5373\u4f7f\u51fa\u9519\u4e5f\u80fd\u5f88\u5bb9\u6613\u5730\u6062\u590d\u3002<\/p>\n<p><strong>\u8bef\u5220\u5206\u652f\u7684\u6559\u8bad<\/strong><\/p>\n<p>\u8fd8\u6709\u4e00\u6b21\uff0c\u6211\u5728\u6e05\u7406\u672c\u5730\u5206\u652f\u65f6\uff0c\u4e0d\u5c0f\u5fc3\u5220\u9664\u4e86\u4e00\u4e2a\u8fd8\u6ca1\u6709\u5408\u5e76\u7684\u91cd\u8981\u5206\u652f\u3002<\/p>\n<pre><code class=\"bash\"># \u6211\u672c\u6765\u60f3\u5220\u9664\u5df2\u7ecf\u5408\u5e76\u7684\u5206\u652f\ngit branch -d feature\/old-function\n# \u4f46\u4e0d\u5c0f\u5fc3\u5220\u9664\u4e86\u672a\u5408\u5e76\u7684\u5206\u652f\ngit branch -D feature\/important-function  # \u8fd9\u4e2a-D\u53c2\u6570\u5f3a\u5236\u5220\u9664\u4e86\u672a\u5408\u5e76\u7684\u5206\u652f<\/code><\/pre>\n<p>\u5f53\u6211\u610f\u8bc6\u5230\u8fd9\u4e2a\u9519\u8bef\u65f6\uff0c\u5fc3\u60c5\u7b80\u76f4\u8dcc\u5230\u4e86\u8c37\u5e95\u3002\u90a3\u4e2a\u5206\u652f\u4e0a\u6709\u6211\u4e24\u5929\u7684\u5de5\u4f5c\u6210\u679c\uff0c\u800c\u4e14\u6ca1\u6709push\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/p>\n<p>\u5e78\u597d\uff0cGit\u7684reflog\u518d\u6b21\u6551\u4e86\u6211\uff1a<\/p>\n<pre><code class=\"bash\"># \u67e5\u770b\u5206\u652f\u64cd\u4f5c\u7684\u65e5\u5fd7\ngit reflog --all\n# \u627e\u5230\u88ab\u5220\u9664\u5206\u652f\u7684\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\ngit checkout -b feature\/important-function &lt;commit-hash&gt;<\/code><\/pre>\n<p>\u8fd9\u6b21\u7ecf\u5386\u8ba9\u6211\u5b66\u4f1a\u4e86\u51e0\u4e2a\u91cd\u8981\u7684\u4e60\u60ef\uff1a<\/p>\n<ol>\n<li>\u5220\u9664\u5206\u652f\u524d\u603b\u662f\u5148\u68c0\u67e5\u662f\u5426\u5df2\u7ecf\u5408\u5e76<\/li>\n<li>\u91cd\u8981\u7684\u5206\u652f\u53ca\u65f6push\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/li>\n<li>\u5b9a\u671f\u68c0\u67e5\u548c\u6e05\u7406\u5206\u652f\uff0c\u4f46\u8981\u5c0f\u5fc3\u64cd\u4f5c<\/li>\n<\/ol>\n<p><strong>\u5f3a\u5236\u63a8\u9001\u7684\u707e\u96be<\/strong><\/p>\n<p>\u6700\u4e25\u91cd\u7684\u4e00\u6b21\u4e8b\u6545\u53d1\u751f\u5728\u6211\u521a\u5f00\u59cb\u4f7f\u7528rebase\u7684\u65f6\u5019\u3002\u6211\u5728\u516c\u5171\u5206\u652f\u4e0a\u8fdb\u884c\u4e86rebase\u64cd\u4f5c\uff0c\u7136\u540e\u5f3a\u5236\u63a8\u9001\u5230\u4e86\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u8986\u76d6\u4e86\u5176\u4ed6\u540c\u4e8b\u7684\u63d0\u4ea4\u3002<\/p>\n<pre><code class=\"bash\"># \u5371\u9669\u7684\u64cd\u4f5c\uff01\uff01\uff01\ngit push --force origin master<\/code><\/pre>\n<p>\u8fd9\u4e2a\u64cd\u4f5c\u76f4\u63a5\u5bfc\u81f4\u5176\u4ed6\u4e09\u4e2a\u540c\u4e8b\u7684\u5de5\u4f5c\u4e22\u5931\uff0c\u6211\u4eec\u4e0d\u5f97\u4e0d\u82b1\u4e86\u4e00\u6574\u5929\u7684\u65f6\u95f4\u6765\u6062\u590d\u4ee3\u7801\u3002\u90a3\u5929\u665a\u4e0a\uff0c\u6211\u88ab\u9879\u76ee\u7ecf\u7406\u53eb\u5230\u529e\u516c\u5ba4&#8221;\u8c08\u5fc3&#8221;\uff0c\u90a3\u79cd\u5c34\u5c2c\u548c\u81ea\u8d23\u7684\u5fc3\u60c5\u73b0\u5728\u60f3\u8d77\u6765\u8fd8\u5f88\u6df1\u523b\u3002<\/p>\n<p>\u4ece\u90a3\u4ee5\u540e\uff0c\u6211\u4eec\u56e2\u961f\u5efa\u7acb\u4e86\u4e25\u683c\u7684\u89c4\u5219\uff1a<\/p>\n<ol>\n<li>\u7edd\u4e0d\u5728\u516c\u5171\u5206\u652f\u4e0a\u4f7f\u7528rebase<\/li>\n<li>\u7edd\u4e0d\u4f7f\u7528<code>--force<\/code>\u63a8\u9001\u5230\u516c\u5171\u5206\u652f<\/li>\n<li>\u5982\u679c\u5fc5\u987b\u5f3a\u5236\u63a8\u9001\uff0c\u4f7f\u7528<code>--force-with-lease<\/code>\u53c2\u6570<\/li>\n<\/ol>\n<pre><code class=\"bash\"># \u76f8\u5bf9\u5b89\u5168\u7684\u5f3a\u5236\u63a8\u9001\ngit push --force-with-lease origin feature\/my-branch<\/code><\/pre>\n<p>\u8fd9\u4e2a\u53c2\u6570\u4f1a\u68c0\u67e5\u8fdc\u7a0b\u5206\u652f\u662f\u5426\u6709\u5176\u4ed6\u4eba\u7684\u65b0\u63d0\u4ea4\uff0c\u5982\u679c\u6709\u5c31\u62d2\u7edd\u63a8\u9001\uff0c\u907f\u514d\u8986\u76d6\u522b\u4eba\u7684\u5de5\u4f5c\u3002<\/p>\n<h3>\u5341\u4e00\u3001\u5de5\u5177\u63a8\u8350\uff1a\u90a3\u4e9b\u8ba9Git\u53d8\u5f97\u66f4\u53cb\u597d\u7684\u795e\u5668<\/h3>\n<p>\u7ecf\u8fc7\u8fd9\u4e9b\u5e74\u7684\u5b9e\u8df5\uff0c\u6211\u79ef\u7d2f\u4e86\u4e00\u4e9b\u975e\u5e38\u597d\u7528\u7684Git\u76f8\u5173\u5de5\u5177\uff0c\u8fd9\u4e9b\u5de5\u5177\u5927\u5927\u63d0\u9ad8\u4e86\u6211\u5904\u7406\u51b2\u7a81\u7684\u6548\u7387\u3002<\/p>\n<p><strong>\u547d\u4ee4\u884c\u5de5\u5177<\/strong><\/p>\n<p><strong>tig &#8211; \u7ec8\u7aef\u4e2d\u7684Git\u5386\u53f2\u6d4f\u89c8\u5668<\/strong><\/p>\n<p>\u8fd9\u662f\u6211\u6700\u559c\u6b22\u7684Git\u53ef\u89c6\u5316\u5de5\u5177\u4e4b\u4e00\u3002\u5728\u7ec8\u7aef\u4e2d\u5c31\u53ef\u4ee5\u6d4f\u89c8Git\u5386\u53f2\uff0c\u67e5\u770b\u5206\u652f\u56fe\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<pre><code class=\"bash\"># \u5b89\u88c5tig\uff08\u4ee5Ubuntu\u4e3a\u4f8b\uff09\nsudo apt-get install tig\n# \u4f7f\u7528tig\u6d4f\u89c8Git\u5386\u53f2\ntig\n# \u67e5\u770b\u7279\u5b9a\u6587\u4ef6\u7684\u5386\u53f2\ntig filename<\/code><\/pre>\n<p>tig\u7684\u597d\u5904\u662f\u53ef\u4ee5\u5728SSH\u8fde\u63a5\u7684\u670d\u52a1\u5668\u4e0a\u4f7f\u7528\uff0c\u800c\u4e14\u64cd\u4f5c\u901f\u5ea6\u5f88\u5feb\u3002<\/p>\n<p><strong>git-flow &#8211; \u6807\u51c6\u5316\u7684\u5206\u652f\u7ba1\u7406<\/strong><\/p>\n<p>git-flow\u63d0\u4f9b\u4e86\u4e00\u5957\u6807\u51c6\u5316\u7684\u5206\u652f\u7ba1\u7406\u6d41\u7a0b\uff0c\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u5206\u652f\u7ba1\u7406\u7684\u6df7\u4e71\u3002<\/p>\n<pre><code class=\"bash\"># \u521d\u59cb\u5316git-flow\ngit flow init\n# \u5f00\u59cb\u4e00\u4e2a\u65b0\u529f\u80fd\ngit flow feature start new-feature\n# \u5b8c\u6210\u529f\u80fd\u5f00\u53d1\ngit flow feature finish new-feature<\/code><\/pre>\n<p>\u867d\u7136git-flow\u7684\u6d41\u7a0b\u6bd4\u8f83\u91cd\uff0c\u4f46\u5bf9\u4e8e\u5927\u578b\u56e2\u961f\u6765\u8bf4\uff0c\u6807\u51c6\u5316\u7684\u6d41\u7a0b\u53ef\u4ee5\u907f\u514d\u5f88\u591a\u534f\u4f5c\u95ee\u9898\u3002<\/p>\n<p><strong>\u56fe\u5f62\u754c\u9762\u5de5\u5177<\/strong><\/p>\n<p><strong>SourceTree &#8211; \u5f3a\u5927\u7684Git GUI\u5de5\u5177<\/strong><\/p>\n<p>SourceTree\u662fAtlassian\u5f00\u53d1\u7684\u514d\u8d39Git GUI\u5de5\u5177\uff0c\u529f\u80fd\u975e\u5e38\u5f3a\u5927\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u590d\u6742\u7684\u5408\u5e76\u548c\u51b2\u7a81\u65f6\u5f88\u6709\u7528\u3002<\/p>\n<p>\u5b83\u7684\u53ef\u89c6\u5316\u5206\u652f\u56fe\u975e\u5e38\u6e05\u6670\uff0c\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u5230\u5206\u652f\u7684\u5408\u5e76\u5386\u53f2\u3002\u800c\u4e14\u5185\u7f6e\u4e86\u5f3a\u5927\u7684\u51b2\u7a81\u89e3\u51b3\u529f\u80fd\uff0c\u652f\u6301\u4e09\u65b9\u5408\u5e76\u3002<\/p>\n<p><strong>GitKraken &#8211; \u989c\u503c\u5f88\u9ad8\u7684Git\u5de5\u5177<\/strong><\/p>\n<p>GitKraken\u7684\u754c\u9762\u8bbe\u8ba1\u975e\u5e38\u6f02\u4eae\uff0c\u64cd\u4f5c\u4e5f\u5f88\u76f4\u89c2\u3002\u7279\u522b\u662f\u5b83\u7684\u4ea4\u4e92\u5f0frebase\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7\u62d6\u62fd\u6765\u91cd\u65b0\u6392\u5e8f\u63d0\u4ea4\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p><strong>VS Code\u7684Git\u63d2\u4ef6<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u4e3b\u8981\u4f7f\u7528VS Code\u5f00\u53d1\uff0c\u90a3\u4e48\u5b83\u5185\u7f6e\u7684Git\u63d2\u4ef6\u5df2\u7ecf\u8db3\u591f\u5f3a\u5927\u3002\u7279\u522b\u662fGitLens\u63d2\u4ef6\uff0c\u53ef\u4ee5\u663e\u793a\u6bcf\u884c\u4ee3\u7801\u7684Git\u4fe1\u606f\uff0c\u5bf9\u4e8e\u7406\u89e3\u4ee3\u7801\u5386\u53f2\u5f88\u6709\u5e2e\u52a9\u3002<\/p>\n<p><strong>\u5728\u7ebf\u670d\u52a1<\/strong><\/p>\n<p><strong>GitHub\/GitLab\u7684\u5408\u5e76\u8bf7\u6c42\u529f\u80fd<\/strong><\/p>\n<p>\u73b0\u4ee3\u7684Git\u6258\u7ba1\u670d\u52a1\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5408\u5e76\u8bf7\u6c42\uff08Pull Request\/Merge Request\uff09\u529f\u80fd\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u81ea\u52a8\u51b2\u7a81\u68c0\u6d4b<\/li>\n<li>\u5728\u7ebf\u51b2\u7a81\u89e3\u51b3<\/li>\n<li>\u4ee3\u7801\u5ba1\u67e5\u529f\u80fd<\/li>\n<li>\u81ea\u52a8\u5316\u6d4b\u8bd5\u96c6\u6210<\/li>\n<\/ul>\n<p>\u6211\u73b0\u5728\u7684\u56e2\u961f\u5927\u91cf\u4f7f\u7528GitHub\u7684Pull Request\u529f\u80fd\uff0c\u5f88\u591a\u7b80\u5355\u7684\u51b2\u7a81\u53ef\u4ee5\u76f4\u63a5\u5728\u7f51\u9875\u4e0a\u89e3\u51b3\uff0c\u4e0d\u9700\u8981\u5728\u672c\u5730\u5904\u7406\u3002<\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u811a\u672c\u548c\u522b\u540d<\/strong><\/p>\n<p>\u6211\u8fd8\u5199\u4e86\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684Git\u522b\u540d\u548c\u811a\u672c\u6765\u7b80\u5316\u5e38\u7528\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"bash\"># \u6211\u7684Git\u522b\u540d\u914d\u7f6e\ngit config --global alias.st status\ngit config --global alias.co checkout\ngit config --global alias.br branch\ngit config --global alias.unstage 'reset HEAD --'\ngit config --global alias.last 'log -1 HEAD'\ngit config --global alias.visual '!gitk'\ngit config --global alias.conflicts 'diff --name-only --diff-filter=U'\ngit config --global alias.sync '!git checkout master &amp;&amp; git pull &amp;&amp; git checkout - &amp;&amp; git rebase master'<\/code><\/pre>\n<p>\u8fd9\u4e9b\u522b\u540d\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u65e5\u5e38\u7684Git\u64cd\u4f5c\u6548\u7387\u3002<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"401\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdlLdC\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<h3>\u5341\u4e8c\u3001\u672a\u6765\u5c55\u671b\uff1aAI\u65f6\u4ee3\u7684Git\u534f\u4f5c<\/h3>\n<p>\u968f\u7740AI\u6280\u672f\u7684\u53d1\u5c55\uff0c\u6211\u76f8\u4fe1Git\u51b2\u7a81\u7684\u5904\u7406\u5c06\u4f1a\u53d8\u5f97\u8d8a\u6765\u8d8a\u667a\u80fd\u5316\u3002\u5df2\u7ecf\u6709\u4e00\u4e9b\u5de5\u5177\u5f00\u59cb\u5c1d\u8bd5\u4f7f\u7528AI\u6765\u81ea\u52a8\u89e3\u51b3\u51b2\u7a81\u3002<\/p>\n<p><strong>\u667a\u80fd\u51b2\u7a81\u9884\u6d4b<\/strong><\/p>\n<p>\u672a\u6765\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u53ef\u80fd\u4f1a\u5177\u5907\u66f4\u5f3a\u7684\u51b2\u7a81\u9884\u6d4b\u80fd\u529b\uff0c\u4e0d\u4ec5\u80fd\u63d0\u524d\u8b66\u544a\u53ef\u80fd\u7684\u51b2\u7a81\uff0c\u8fd8\u80fd\u5efa\u8bae\u6700\u4f73\u7684\u5f00\u53d1\u7b56\u7565\u6765\u907f\u514d\u51b2\u7a81\u3002<\/p>\n<p><strong>\u81ea\u52a8\u51b2\u7a81\u89e3\u51b3<\/strong><\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u5e38\u89c1\u7684\u51b2\u7a81\u6a21\u5f0f\uff0cAI\u53ef\u80fd\u80fd\u591f\u81ea\u52a8\u751f\u6210\u5408\u5e76\u65b9\u6848\uff0c\u751a\u81f3\u81ea\u52a8\u89e3\u51b3\u51b2\u7a81\u3002\u5f53\u7136\uff0c\u8fd9\u9700\u8981\u5927\u91cf\u7684\u8bad\u7ec3\u6570\u636e\u548c\u4e25\u683c\u7684\u5b89\u5168\u4fdd\u969c\u3002<\/p>\n<p><strong>\u667a\u80fd\u4ee3\u7801\u5ba1\u67e5<\/strong><\/p>\n<p>AI\u8f85\u52a9\u7684\u4ee3\u7801\u5ba1\u67e5\u53ef\u80fd\u4f1a\u66f4\u597d\u5730\u8bc6\u522b\u6f5c\u5728\u7684\u51b2\u7a81\u548c\u95ee\u9898\uff0c\u63d0\u4f9b\u66f4\u6709\u9488\u5bf9\u6027\u7684\u5efa\u8bae\u3002<\/p>\n<p><strong>\u8bed\u4e49\u7ea7\u522b\u7684\u7248\u672c\u63a7\u5236<\/strong><\/p>\n<p>\u672a\u6765\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u53ef\u80fd\u4e0d\u518d\u57fa\u4e8e\u884c\u7ea7\u522b\u7684\u5dee\u5f02\uff0c\u800c\u662f\u57fa\u4e8e\u8bed\u4e49\u7ea7\u522b\u7684\u53d8\u5316\u3002\u8fd9\u6837\u53ef\u4ee5\u66f4\u597d\u5730\u5904\u7406\u4ee3\u7801\u91cd\u6784\u3001\u683c\u5f0f\u53d8\u5316\u7b49\u95ee\u9898\u3002<\/p>\n<h3>\u7ed3\u8bed\uff1a\u62e5\u62b1\u51b2\u7a81\uff0c\u4e0eGit\u548c\u8c10\u5171\u5904<\/h3>\n<p>\u5199\u5230\u8fd9\u91cc\uff0c\u6211\u53d1\u73b0Git\u51b2\u7a81\u5176\u5b9e\u5c31\u50cf\u7a0b\u5e8f\u5458\u804c\u4e1a\u751f\u6daf\u4e2d\u7684\u5176\u4ed6\u6311\u6218\u4e00\u6837\uff0c\u770b\u8d77\u6765\u5f88\u53ef\u6015\uff0c\u4f46\u901a\u8fc7\u6b63\u786e\u7684\u65b9\u6cd5\u548c\u8db3\u591f\u7684\u5b9e\u8df5\uff0c\u662f\u5b8c\u5168\u53ef\u4ee5\u5f81\u670d\u7684\u3002<\/p>\n<p>\u56de\u987e\u6211\u8fd9\u5341\u5e74\u7684\u7f16\u7a0b\u7ecf\u5386\uff0c\u4ece\u6700\u521d\u9762\u5bf9Git\u51b2\u7a81\u65f6\u7684\u624b\u8db3\u65e0\u63aa\uff0c\u5230\u73b0\u5728\u80fd\u591f\u719f\u7ec3\u5730\u5904\u7406\u5404\u79cd\u590d\u6742\u60c5\u51b5\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u5145\u6ee1\u4e86\u632b\u6298\u548c\u6210\u957f\u3002\u6bcf\u4e00\u6b21\u51b2\u7a81\u90fd\u662f\u4e00\u6b21\u5b66\u4e60\u7684\u673a\u4f1a\uff0c\u6bcf\u4e00\u6b21\u89e3\u51b3\u95ee\u9898\u90fd\u8ba9\u6211\u5bf9Git\u7684\u7406\u89e3\u66f4\u52a0\u6df1\u5165\u3002<\/p>\n<p><strong>\u6700\u91cd\u8981\u7684\u5fc3\u5f97\u4f53\u4f1a<\/strong><\/p>\n<ol>\n<li><strong>\u9884\u9632\u80dc\u4e8e\u6cbb\u7597<\/strong>\uff1a\u901a\u8fc7\u826f\u597d\u7684\u56e2\u961f\u534f\u4f5c\u3001\u4ee3\u7801\u89c4\u8303\u3001\u5206\u652f\u7b56\u7565\u6765\u51cf\u5c11\u51b2\u7a81\u7684\u53d1\u751f\uff0c\u6bd4\u4e8b\u540e\u5904\u7406\u51b2\u7a81\u8981\u9ad8\u6548\u5f97\u591a\u3002<\/li>\n<li><strong>\u6c9f\u901a\u662f\u5173\u952e<\/strong>\uff1a\u5f88\u591aGit\u51b2\u7a81\u7684\u6839\u672c\u539f\u56e0\u4e0d\u662f\u6280\u672f\u95ee\u9898\uff0c\u800c\u662f\u6c9f\u901a\u95ee\u9898\u3002\u4fdd\u6301\u56e2\u961f\u4e4b\u95f4\u7684\u826f\u597d\u6c9f\u901a\uff0c\u53ef\u4ee5\u907f\u514d\u5f88\u591a\u4e0d\u5fc5\u8981\u7684\u51b2\u7a81\u3002<\/li>\n<li><strong>\u5de5\u5177\u8981\u7528\u597d<\/strong>\uff1a\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5904\u7406\u51b2\u7a81\u7684\u6548\u7387\u3002\u4e0d\u8981\u56fa\u6267\u5730\u53ea\u4f7f\u7528\u547d\u4ee4\u884c\uff0c\u56fe\u5f62\u5316\u5de5\u5177\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u786e\u5b9e\u66f4\u6709\u4f18\u52bf\u3002<\/li>\n<li><strong>\u6301\u7eed\u5b66\u4e60<\/strong>\uff1aGit\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u6709\u5f88\u591a\u9ad8\u7ea7\u529f\u80fd\u503c\u5f97\u5b66\u4e60\u3002\u6295\u5165\u65f6\u95f4\u5b66\u4e60\u8fd9\u4e9b\u529f\u80fd\uff0c\u957f\u671f\u6765\u770b\u7edd\u5bf9\u662f\u503c\u5f97\u7684\u3002<\/li>\n<li><strong>\u5efa\u7acb\u89c4\u8303<\/strong>\uff1a\u56e2\u961f\u8981\u6709\u7edf\u4e00\u7684Git\u5de5\u4f5c\u6d41\u7a0b\u548c\u89c4\u8303\uff0c\u8fd9\u6bd4\u4e2a\u4eba\u7684\u6280\u672f\u6c34\u5e73\u66f4\u91cd\u8981\u3002<\/li>\n<\/ol>\n<p><strong>\u7ed9\u65b0\u624b\u7a0b\u5e8f\u5458\u7684\u5efa\u8bae<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u662f\u4e00\u4e2a\u521a\u5f00\u59cb\u4f7f\u7528Git\u7684\u65b0\u624b\uff0c\u6211\u60f3\u7ed9\u4f60\u51e0\u4e2a\u5efa\u8bae\uff1a<\/p>\n<ol>\n<li><strong>\u4e0d\u8981\u5bb3\u6015\u51b2\u7a81<\/strong>\uff1aGit\u51b2\u7a81\u662f\u6b63\u5e38\u7684\uff0c\u6bcf\u4e2a\u7a0b\u5e8f\u5458\u90fd\u4f1a\u9047\u5230\u3002\u91cd\u8981\u7684\u662f\u5b66\u4f1a\u6b63\u786e\u5904\u7406\uff0c\u800c\u4e0d\u662f\u5bb3\u6015\u5b83\u3002<\/li>\n<li><strong>\u591a\u7ec3\u4e60<\/strong>\uff1a\u5728\u4e00\u4e9b\u4e0d\u91cd\u8981\u7684\u9879\u76ee\u4e0a\u591a\u7ec3\u4e60Git\u64cd\u4f5c\uff0c\u719f\u6089\u5404\u79cd\u547d\u4ee4\u548c\u573a\u666f\u3002<\/li>\n<li><strong>\u7406\u89e3\u539f\u7406<\/strong>\uff1a\u4e0d\u8981\u53ea\u8bb0\u547d\u4ee4\uff0c\u8981\u7406\u89e3Git\u7684\u5de5\u4f5c\u539f\u7406\u3002\u8fd9\u6837\u9047\u5230\u95ee\u9898\u65f6\u624d\u80fd\u7075\u6d3b\u5e94\u5bf9\u3002<\/li>\n<li><strong>\u5907\u4efd\u91cd\u8981\u5de5\u4f5c<\/strong>\uff1a\u5728\u8fdb\u884c\u590d\u6742\u64cd\u4f5c\u524d\uff0c\u603b\u662f\u5148\u521b\u5efa\u5907\u4efd\u3002Git\u6709\u5f88\u591a\u6062\u590d\u673a\u5236\uff0c\u4f46\u9884\u9632\u603b\u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/li>\n<li><strong>\u5bfb\u6c42\u5e2e\u52a9<\/strong>\uff1a\u9047\u5230\u590d\u6742\u95ee\u9898\u65f6\uff0c\u4e0d\u8981\u72ec\u81ea\u82e6\u82e6\u6323\u624e\u3002\u5411\u6709\u7ecf\u9a8c\u7684\u540c\u4e8b\u6c42\u52a9\uff0c\u5f80\u5f80\u80fd\u8282\u7701\u5927\u91cf\u65f6\u95f4\u3002<\/li>\n<\/ol>\n<p><strong>\u5bf9\u672a\u6765\u7684\u5c55\u671b<\/strong><\/p>\n<p>\u6211\u76f8\u4fe1\u968f\u7740\u5de5\u5177\u548c\u65b9\u6cd5\u7684\u4e0d\u65ad\u6539\u8fdb\uff0cGit\u51b2\u7a81\u4f1a\u53d8\u5f97\u8d8a\u6765\u8d8a\u5bb9\u6613\u5904\u7406\u3002\u4f46\u66f4\u91cd\u8981\u7684\u662f\uff0c\u6211\u4eec\u7a0b\u5e8f\u5458\u4e5f\u8981\u4e0d\u65ad\u63d0\u5347\u81ea\u5df1\u7684\u534f\u4f5c\u80fd\u529b\u548c\u6280\u672f\u6c34\u5e73\u3002<\/p>\n<p>\u6280\u672f\u5728\u8fdb\u6b65\uff0c\u4f46\u4eba\u4e0e\u4eba\u4e4b\u95f4\u7684\u534f\u4f5c\u6c38\u8fdc\u662f\u8f6f\u4ef6\u5f00\u53d1\u7684\u6838\u5fc3\u3002\u5b66\u4f1a\u5904\u7406Git\u51b2\u7a81\uff0c\u4e0d\u4ec5\u662f\u5728\u5b66\u4e60\u4e00\u4e2a\u6280\u672f\u6280\u80fd\uff0c\u66f4\u662f\u5728\u5b66\u4e60\u5982\u4f55\u4e0e\u4ed6\u4eba\u534f\u4f5c\uff0c\u5982\u4f55\u5728\u56e2\u961f\u4e2d\u6709\u6548\u5de5\u4f5c\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u60f3\u8bf4\uff1aGit\u51b2\u7a81\u867d\u7136\u8ba8\u538c\uff0c\u4f46\u5b83\u4e5f\u89c1\u8bc1\u4e86\u6211\u4eec\u7684\u6210\u957f\u3002\u4ece\u6700\u521d\u7684\u6050\u60e7\u548c\u8ff7\u832b\uff0c\u5230\u73b0\u5728\u7684\u4ece\u5bb9\u5e94\u5bf9\uff0c\u8fd9\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u7a0b\u5e8f\u5458\u6210\u957f\u7684\u7f29\u5f71\u3002<\/p>\n<p>\u613f\u6bcf\u4e00\u4e2a\u7a0b\u5e8f\u5458\u90fd\u80fd\u4e0eGit\u548c\u8c10\u5171\u5904\uff0c\u5728\u4ee3\u7801\u7684\u4e16\u754c\u91cc\u81ea\u7531\u98de\u7fd4\uff01<\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"400\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdkEIv\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<hr>\n<h3><em>\u5199\u8fd9\u7bc7\u6587\u7ae0\u7684\u65f6\u5019\uff0c\u6211\u56de\u60f3\u8d77\u4e86\u65e0\u6570\u4e2a\u4e0eGit\u51b2\u7a81\u6597\u4e89\u7684\u65e5\u65e5\u591c\u591c\u3002\u90a3\u4e9b\u75db\u82e6\u7684\u7ecf\u5386\u73b0\u5728\u770b\u6765\u90fd\u662f\u5b9d\u8d35\u7684\u8d22\u5bcc\uff0c\u5b83\u4eec\u8ba9\u6211\u6210\u4e3a\u4e86\u4e00\u4e2a\u66f4\u597d\u7684\u7a0b\u5e8f\u5458\u3002\u5e0c\u671b\u6211\u7684\u5206\u4eab\u80fd\u591f\u5e2e\u52a9\u66f4\u591a\u7684\u540c\u884c\uff0c\u8ba9\u5927\u5bb6\u5728Git\u7684\u8def\u4e0a\u5c11\u8d70\u4e00\u4e9b\u5f2f\u8def\u3002\u8bb0\u4f4f\uff0c\u6bcf\u4e00\u6b21\u51b2\u7a81\u90fd\u662f\u6210\u957f\u7684\u673a\u4f1a\uff0c\u6bcf\u4e00\u6b21\u89e3\u51b3\u95ee\u9898\u90fd\u8ba9\u6211\u4eec\u53d8\u5f97\u66f4\u5f3a\u3002\u52a0\u6cb9\uff0c\u540c\u884c\u4eec\uff01<\/em><\/h3>\n<p><strong>\u53e6\u5916\uff0c\u60f3\u8fdb\u5927\u5382\u7684\u540c\u5b66\uff0c\u4e00\u5b9a\u8981\u597d\u597d\u5b66\u7b97\u6cd5\uff0c\u8fd9\u662f\u9762\u8bd5\u5fc5\u5907\u7684\u3002\u8fd9\u91cc\u51c6\u5907\u4e86\u4e00\u4efd BAT \u5927\u4f6c\u603b\u7ed3\u7684 LeetCode \u5237\u9898\u5b9d\u5178\uff0c\u5f88\u591a\u4eba\u9760\u5b83\u4eec\u8fdb\u4e86\u5927\u5382\u3002<\/strong><\/p>\n<p><img decoding=\"async\" width=\"286\" height=\"83\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVdaCCY\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p><a href=\"https:\/\/link.segmentfault.com\/?enc=aGdOGxsqECQ5%2FUp%2F51yR%2Bg%3D%3D.98sRCWJrUCbCYjFWKhk4SXGIzfIJN6rzlctL1jPgLcyzodhvi4ADXxmn%2F1s0SiI%2F\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u5237\u9898 | LeetCode\u7b97\u6cd5\u5237\u9898\u795e\u5668\uff0c\u770b\u5b8c BAT \u968f\u4f60\u6311\uff01<\/a><\/p>\n<h4>\u6709\u6536\u83b7\uff1f\u5e0c\u671b\u8001\u94c1\u4eec\u6765\u4e2a\u4e09\u8fde\u51fb\uff0c\u7ed9\u66f4\u591a\u7684\u4eba\u770b\u5230\u8fd9\u7bc7\u6587\u7ae0<\/h4>\n<p><strong>\u63a8\u8350\u9605\u8bfb\uff1a<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=EpAQSyTZU0Whtwr%2Fu3snwQ%3D%3D.qMb%2FnsU9XbsUakb8HDPhCE69Mrl0iao1eiq1xRopxc1xs9LUTz9lZsE8RUppmKbm\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u3010\u826f\u8bb8\u5b66\u5802\u30112025\u5e74\u5d4c\u5165\u5f0f\u5982\u4f55\u9ad8\u85aa\u5165\u884c\uff1f<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=a4tB%2FOBM2E4VSOF2Ap%2BZ3w%3D%3D.S8mVadzR2WZbYvwdHKLofT6S4vZcjw910w8ruRaUgwFDD4EFwDbRIWDWgnS3zBsg\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u7f16\u7a0b\u8d44\u6599\u5927\u5168<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=LJF9DOlAk65tvaUhy2QcJg%3D%3D.%2FmGqkxr7AW5uBuJLL6%2BWN2dzRnuXzMo56mvNGUPtsQrqiP0Jxwea18WFwKp1j42b\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u7a0b\u5e8f\u5458\u5fc5\u5907\u8f6f\u4ef6\u8d44\u6e90<\/a><\/li>\n<\/ul>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=4qBThBtz831y7fX66%2BW2JQ%3D%3D.BE8%2B9cYGYwBA%2Fz3wStAimEYTWj5V4ds3Hk3R3w8CCzk%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">\u826f\u8bb8\u5d4c\u5165\u5f0f\u6559\u7a0b\u7f51<\/a>\uff0c\u6ee1\u6ee1\u90fd\u662f\u5e72\u8d27\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047117830\">https:\/\/segmentfault.com\/a\/1190000047117830<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7a0b\u5e8f\u5458\u5982\u4f55\u907f\u514dGit\u51b2\u7a81\uff1f\u4e00\u4e2a\u8001\u7801\u519c\u7684\u8840\u6cea\u53f2\u548c\u5b9e\u6218\u7ecf\u9a8c \u770b\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u7684\u5185\u5fc3\u77ac\u95f4\u6d8c\u8d77\u4e86\u65e0\u6570\u4e2a\u75db\u82e6\u7684\u56de\u5fc6\u3002\u4f5c\u4e3a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020948","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020948"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020948\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}