{"id":10005978,"date":"2022-07-22T11:57:02","date_gmt":"2022-07-22T03:57:02","guid":{"rendered":"https:\/\/ityet.com\/?p=10005978"},"modified":"2022-07-22T11:57:02","modified_gmt":"2022-07-22T03:57:02","slug":"git%e9%85%8d%e7%bd%ae%e4%bb%a5%e5%8f%8a%e6%9b%bf%e6%8d%a2gerrit%e9%bb%98%e8%ae%a4commit-msg-hook","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10005978","title":{"rendered":"git\u914d\u7f6e\u4ee5\u53ca\u66ff\u6362gerrit\u9ed8\u8ba4commit-msg hook"},"content":{"rendered":"<h3>Git \u914d\u7f6e\u89c4\u8303<\/h3>\n<h4>\u914d\u7f6e\u7528\u6237\u540d\u548c\u90ae\u4ef6<\/h4>\n<p>\u4e3a\u4e86\u63d0\u4ea4\u8bb0\u5f55\u4fbf\u4e8e\u8bc6\u522b\uff0c\u914d\u7f6e\u4e2d\u6587\u540d\uff0c\u90ae\u7bb1\u914d\u7f6e\u6210<code>gitlab<\/code>\u6ce8\u518c\u90ae\u7bb1<\/p>\n<pre><code class=\"shell\">git config --global user.name &quot;\u4e2d\u6587\u59d3\u540d&quot;  \ngit config --global user.email &quot;email@[email.com&quot;<\/code><\/pre>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p><code>user.name<\/code> \u914d\u7f6e\u89c4\u5219: <code>name#\u5de5\u53f7<\/code> \u793a\u4f8b  <code>git config --global user.name &quot;\u5f20\u4e09#A00003&quot;<\/code><\/p>\n<p><code>user.email<\/code> \u914d\u7f6e\u89c4\u5219: \u7edf\u4e00\u4f7f\u7528\u516c\u53f8\u7684\u90ae\u7bb1\u3002\u793a\u4f8b <code>git config --global user.email &quot;san.zhang@casstime.com&quot;<\/code><\/p>\n<h4>\u4fdd\u6301\u4ed3\u5e93\u4e2d\u4ee5 <code>LF<\/code> \u6362\u884c<\/h4>\n<pre><code class=\"shell\">git config --global core.autocrlf input \/\/ \u56e0\u4e3alinux\u670d\u52a1\u9ed8\u8ba4\u4f7f\u7528LF\u4f5c\u4e3a\u6362\u884c\u7b26\u683c\u5f0f<\/code><\/pre>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=SVQtdDW6VqnIbvLOwJPW4A%3D%3D.tsvR1aHnN3e1Aq2uRM0CtlquuvS%2Fs6KlNBZgDEcfjxmv4AS3qOL4HjeqjTUlaL0m\" rel=\"nofollow\">git core.autocrlf\u914d\u7f6e\u8bf4\u660e<\/a><\/p>\n<h4>git\u4e2d\u6587\u8def\u5f84\u540d\u79f0\u4e71\u7801<\/h4>\n<pre><code class=\"shell\">git config --global gui.encoding utf-8  \ngit config --global core.quotepath false<\/code><\/pre>\n<h4>\u8ba9<code>git mergetool<\/code>\u4e0d\u518d\u751f\u6210\u70e6\u4eba\u7684\u5907\u4efd\u6587\u4ef6\uff08<code>*.orig<\/code>\uff09<\/h4>\n<pre><code class=\"shell\">git config --global mergetool.keepBackup false<\/code><\/pre>\n<h4>\u8ba9\u6587\u4ef6\u540d\u533a\u5206\u5927\u5c0f\u5199<\/h4>\n<pre><code class=\"shell\">git config --global core.ignorecase false<\/code><\/pre>\n<h4>\u4e0d\u4fee\u6539\u6587\u4ef6\u6a21\u5f0f(\u6587\u4ef6mode\u53d8\u5316\u4e0d\u63d0\u4ea4\u5230\u4ed3\u5e93)<\/h4>\n<pre><code class=\"shell\">git config --add --global core.filemode false<\/code><\/pre>\n<h4>\u6587\u4ef6\u91cd\u547d\u540d\u4e0d\u751f\u6548\uff08\u5927\u5c0f\u5199\u4e0d\u654f\u611f\uff09\u65f6\uff0c\u8bf7\u4f7f\u7528 <code>git mv<\/code> \u91cd\u547d\u540d<\/h4>\n<pre><code class=\"shell\">git mv lineConfig.js LineConfig.js<\/code><\/pre>\n<p><strong>\u4e3a\u4e86\u65b9\u4fbf\u60a8\u7684\u914d\u7f6e\uff0c\u60a8\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u4ee5\u4e0b\u811a\u672c<\/strong> <code>git_config_default.sh<\/code><\/p>\n<pre><code class=\"shell\"># git_config_default.sh\n# \u914d\u7f6e\u7528\u6237\u540d\u548c\u90ae\u4ef6\n# \u4e3a\u4e86\u63d0\u4ea4\u8bb0\u5f55\u4fbf\u4e8e\u8bc6\u522b\uff0c\u914d\u7f6e\u4e2d\u6587\u540d\uff0c\u90ae\u7bb1\u914d\u7f6e\u6210gitlab\u6ce8\u518c\u90ae\u7bb1\n# user.name \u914d\u7f6e\u89c4\u5219: name#\u5de5\u53f7  \u793a\u4f8b   git config --global user.name &quot;\u8c2d\u667a\u519b#A00015&quot;  \n# user.email \u914d\u7f6e\u89c4\u5219: \u7edf\u4e00\u4f7f\u7528\u516c\u53f8\u7684\u90ae\u7bb1\u3002\u793a\u4f8b git config --global user.email &quot;zhijun.tan@casstime.com&quot;  \n\nread -p &quot;\u8bf7\u8f93\u5165\u60a8\u7684\u59d3\u540d\u548c\u5de5\u53f7\uff0c\u793a\u4f8b\u4e3a\uff1a\u738b\u6c38\u6797#A00514.\u8f93\u5165\u540e\u8bf7\u6309[enter]\u952e\u7ed3\u675f\u3002&quot; USER_NAME\ngit config --global user.name &quot;$USER_NAME&quot; \necho &quot;\u8bbe\u7f6e\u540e user.name \u503c\u4e3a &quot;\ngit config user.name\n# TODO user.name \u7b26\u5408\u6b63\u5219 [\/u4e00-\/u9fa5]{2,}#[A-B]\/d{5} \u624d\u53ef\u4ee5\u7ee7\u7eed\u8f93\u5165\n\nread -p &quot;\u8bf7\u8f93\u5165\u60a8\u5728gitlab\u4e0a\u6ce8\u518c\u7684\u516c\u53f8\u90ae\u7bb1\uff0c\u793a\u4f8b\u4e3a\uff1ayonglin.wang@casstime.com.\u8f93\u5165\u540e\u8bf7\u6309[enter]\u952e\u7ed3\u675f\u3002&quot; USER_EMAIL\ngit config --global user.email &quot;$USER_EMAIL&quot; \necho &quot;\u8bbe\u7f6e\u540e user.email \u503c\u4e3a &quot;\ngit config user.email\n\n#\u4fdd\u6301\u4ed3\u5e93\u4e2d\u4ee5 LF \u6362\u884c\ngit config --global core.autocrlf input\necho &quot;git config --global core.autocrlf input&quot;\n\n#git\u4e2d\u6587\u8def\u5f84\u540d\u79f0\u4e71\u7801\ngit config --global gui.encoding utf-8   \ngit config --global core.quotepath false\necho &quot;git config --global gui.encoding utf-8&quot;\necho &quot;git config --global core.quotepath false&quot;\n\n#\u8ba9git mergetool\u4e0d\u518d\u751f\u6210\u70e6\u4eba\u7684\u5907\u4efd\u6587\u4ef6\uff08*.orig\uff09\ngit config --global mergetool.keepBackup false\necho &quot;git config --global mergetool.keepBackup false&quot;\n\n#\u8ba9\u6587\u4ef6\u540d\u533a\u5206\u5927\u5c0f\u5199\ngit config --global core.ignorecase false\necho &quot;git config --global core.ignorecase false&quot;\n\n#\u4e0d\u4fee\u6539\u6587\u4ef6\u6a21\u5f0f(\u6587\u4ef6mode\u53d8\u5316\u4e0d\u63d0\u4ea4\u5230\u4ed3\u5e93)\ngit config --add --global core.filemode false\necho &quot;git config --add --global core.filemode false&quot;<\/code><\/pre>\n<p>\u4f7f\u7528\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p><strong>Windows<\/strong><\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u628a<code>git_config_default.sh<\/code>\u53e6\u5b58\u5230\u6307\u5b9a\u7684\u7cfb\u7edf\u76ee\u5f55\u4e0b\uff1b<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u5728\u8be5\u76ee\u5f55\u53f3\u952e \u9009\u62e9\u3010Git Bash Here\u3011\u8fdb\u5165Git\u547d\u4ee4\u884c\u754c\u9762\uff1b<\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<pre><code class=\"shell\">chmod 777 git_config_default.sh\n\n.\/git_config_default.sh \/\/ \u6267\u884cgit_config_default.sh\u811a\u672c<\/code><\/pre>\n<p>\u6267\u884c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZo\" alt=\"image2022-2-28_17-41-42.png\" title=\"image2022-2-28_17-41-42.png\" loading=\"lazy\" ><\/p>\n<p><strong>Mac<\/strong> <\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u628a<code>git_config_default.sh<\/code>\u53e6\u5b58\u5230\u6307\u5b9a\u7684\u7cfb\u7edf\u76ee\u5f55\u4e0b\uff1b<\/p>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u5728\u8be5\u76ee\u5f55\u53f3\u952e \u9009\u62e9\u3010\u8fdb\u5165\u7ec8\u7aef\u3011\u8fdb\u5165<code>Git<\/code>\u547d\u4ee4\u884c\u754c\u9762\uff1b<\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4<\/p>\n<pre><code class=\"shell\">chmod 777 git_config_default.sh\n.\/git_config_default.sh<\/code><\/pre>\n<p>\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZo\" alt=\"image2022-2-28_17-41-42.png\" title=\"image2022-2-28_17-41-42.png\" loading=\"lazy\" ><\/p>\n<h3>Git \u63d0\u4ea4\u89c4\u8303<\/h3>\n<h4>\u76ee\u7684<\/h4>\n<p><code>git commit<\/code>\u4fe1\u606f\u4f5c\u4e3a\u4e00\u4e2a\u57fa\u7840\u7684\u4ea4\u4e92\u7a97\u53e3\uff0c\u65e2\u53ef\u4ee5\u5feb\u901f\u786e\u5b9a\u63d0\u4ea4\u5f71\u54cd\u3001\u5173\u8054\u8bbe\u8ba1\u6587\u6863\u3001\u5173\u8054\u7f3a\u9677<code>bug<\/code>\u5355\u3001\u540e\u7eed\u8fd8\u80fd\u5bf9\u9879\u76ee\u6216\u56e2\u961f\u5de5\u4f5c\u8fdb\u884c\u6eaf\u6e90\u6539\u8fdb\u3002<\/p>\n<p><code>git commit<\/code>\u4fe1\u606f\u7684\u89c4\u8303\u5316\uff0c\u65e2\u4f53\u73b0\u5f00\u53d1\u540c\u5b66\u7684\u4e13\u4e1a\u7d20\u517b\uff0c\u4e5f\u5c5e\u4e8e\u516c\u53f8\u7684\u8fc7\u7a0b\u8d44\u4ea7\uff0c\u56e0\u6b64\u5bf9<code>git commit<\/code>\u63d0\u4ea4\u7684\u89c4\u8303\u8bbe\u8ba1\u5982\u4e0b\u3002<\/p>\n<h4>\u89c4\u8303<\/h4>\n<p>\u5728<code>commit<\/code>\u63d0\u4ea4\u89c4\u8303\u4e2d\uff0c\u660e\u786e\u672c\u6b21\u63d0\u4ea4\u683c\u5f0f<\/p>\n<p>\u3010\u63d0\u4ea4\u7c7b\u578b\u3011<\/p>\n<p>\u200b       \u660e\u786e \u4e00\u6b21\u4ee3\u7801\u63d0\u4ea4\u7684\u76ee\u7684\u3002\u8981\u4e48\u662f\u65b0\u589e\u529f\u80fd\uff08<code>feat<\/code>\uff09\uff0c\u8981\u4e48\u662f\u4fee\u590d<code>bug<\/code>\uff08<code>fix<\/code>\uff09\uff0c\u518d\u8005\u4f9d\u8d56\u3001\u6784\u5efa\u3001\u914d\u7f6e\u5347\u7ea7\u3001\u6d4b\u8bd5\u4ee3\u7801\u7b49\u7b49\uff08<code>other<\/code>\uff09\u3002<\/p>\n<p>\u3010\u63d0\u4ea4\u8bf4\u660e\u3011<\/p>\n<p>\u200b       \u660e\u786e\u63d0\u4ea4\u76ee\u7684\u540e\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u770b\u770b\u5177\u4f53\u5185\u5bb9\u3002\u901a\u8fc7\u5173\u952e\u5b57\u63cf\u8ff0\u63d0\u4ea4\u8be6\u60c5\uff0c\u66f4\u660e\u786e\u7684\u4f20\u9012\u63d0\u4ea4\u7684\u4ef7\u503c\u3002<\/p>\n<p>\u3010\u76f8\u5173\u94fe\u63a5\u3011<\/p>\n<p>\u200b       \u65b9\u4fbf\u652f\u6301\u63a5\u53e3\u8bbe\u8ba1\u3001<code>story<\/code>\u8bbe\u8ba1\u3001\u9700\u6c42\u3001<code>bug<\/code>\u63cf\u8ff0\u7b49\u4e0d\u540c\u7c7b\u578b\u4ee3\u7801\u63d0\u4ea4\u7684\u9700\u6c42\uff0c\u6211\u4eec\u540c\u65f6\u652f\u6301<code>JIRA<\/code>\u3001<code>confluence<\/code>\u94fe\u63a5\u3002<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u4f7f\u7528\uff0c\u6211\u4eec\u91c7\u7528<code>Angular<\/code>\u89c4\u8303\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre><code>git\u63d0\u4ea4\u89c4\u8303\n\n\u89c4\u8303\u8bf4\u660e\n      \u63d0\u4ea4\u7c7b\u578b(\u5fc5\u987b)\uff1a\n        feat\uff08\u65b0\u589e\u529f\u80fd\uff09\n        fix\uff08\u4fee\u590dbug\uff09\n        other\uff08\u4f9d\u8d56\uff0c\u6784\u5efa\u3001CI\u3001\u683c\u5f0f\u7b49\uff0c\u53ef\u901a\u8fc7\u63d0\u4ea4\u4fe1\u606f\u8bf4\u660e\uff09\n      \u63d0\u4ea4\u8bf4\u660e (\u5fc5\u987b)\uff1a\u63cf\u8ff0\u6b64\u6b21\u63d0\u4ea4\u6240\u4fee\u6539\u7684\u5185\u5bb9\uff08\u957f\u5ea6\u9650\u52362~100\uff0c \u7ea6\u5b9a\u8bf4\u660e\u4e2d\u4e0d\u8981\u5305\u542b&quot;[]&quot;, \u4f1a\u5f71\u54cd\u6821\u9a8c\u89c4\u5219\uff09\n      \u76f8\u5173\u94fe\u63a5 (\u5fc5\u987b)\uff1aJira \u94fe\u63a5\u6216 Confluence \u94fe\u63a5 \n\u89c4\u8303\u683c\u5f0f\n      \u63d0\u4ea4\u7c7b\u578b:  \u63d0\u4ea4\u8bf4\u660e  [\u76f8\u5173\u94fe\u63a5] \n\u63d0\u4ea4\u793a\u4f8b \n     feat:  git\u63d0\u4ea4\u89c4\u8303\u8bf4\u660e  [https:\/\/jira.casstime.com\/EC0001] <\/code><\/pre>\n<p>\u5173\u4e8e\u89c4\u8303\u7684\u5e38\u89c1\u95ee\u9898<\/p>\n<p><strong>\u95ee\u98981\uff1a<code>story<\/code>\u7f16\u5199\u6216\u8005\u53d1\u5e03\u9636\u6bb5\u6ca1\u6709<code>jira<\/code>\uff0c\u5f3a\u5236<code>jira<\/code>\u7f16\u53f7\u7684\u4e0d\u77e5\u9053\u5982\u4f55\u586b\u5199\uff0c\u53ea\u80fd\u63d0\u524d\u521b\u5efa<code>Jira<\/code><\/strong><\/p>\n<p>\u9488\u5bf9\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u548c\u5f00\u53d1\u540c\u5b66\u8fdb\u884c\u4e86\u6c9f\u901a\uff0c\u6211\u4eec\u628a\u4e4b\u524d\u5f3a\u5236\u8981\u6c42\u586b\u5199<code>jira<\/code>\u7f16\u53f7 \u6539\u6210\u4e86\u5f3a\u5236\u8981\u6c42\u586b\u5199\u76f8\u5173\u94fe\u63a5\uff0c\u8fd9\u6837\u5728<code>story<\/code>\u8bbe\u8ba1\u9636\u6bb5\u53ef\u4ee5\u586b\u5199 <code>story<\/code>\u7684<code>confluence<\/code>\u5730\u5740\uff0c \u53d1\u5e03\u9636\u6bb5\u53ef\u586b\u5199<code>checklist<\/code>\u5730\u5740\u3002<\/p>\n<p><strong>\u95ee\u98982\uff1a\u63d0\u4ea4\u7c7b\u578b\u592a\u5c11\uff0c\u4e0d\u77e5\u9053\u5982\u4f55\u9009\u62e9\uff0c\u6bd4\u5982\u8bf4\u4ee5\u4e0b\u573a\u666f\uff0c\u4fee\u6539<code>ci<\/code>\uff0c \u6b63\u5f0f\u7248\u672c\u6253\u5305\uff0c\u8c03\u6574\u4ee3\u7801\u683c\u5f0f\uff0c\u4ee3\u7801\u91cd\u6784\uff0c\u6027\u80fd\u4f18\u5316\u7b49\u7b49<\/strong><\/p>\n<p>\u9488\u5bf9\u8fd9\u4e2a\u95ee\u9898 \uff0c\u6211\u4eec\u8fd8\u662f\u575a\u6301\u4e0d\u589e\u52a0\u65b0\u7684\u7c7b\u578b\uff0c\u4f46\u662f\u628a\u539f\u6765\u7684<code>refactor<\/code>\u4fee\u6539\u4e3a<code>other<\/code>\u3002<\/p>\n<ul>\n<li>\u4e0d\u589e\u52a0\u63d0\u4ea4\u7c7b\u578b\u7684\u539f\u56e0<\/li>\n<\/ul>\n<p>\u200b        \u4e00\u4e2a\u539f\u56e0\u4e3a\u4e86\u7ea6\u675f\u63d0\u4ea4\u65f6\u7684\u4ee3\u7801\u5b8c\u6574\u6027\uff0c\u6211\u4eec\u63a8\u8350\u7684\u662f\u4e00\u6b21\u63d0\u4ea4\u5bf9\u5e94\u7684\u4e00\u4e2a\u5177\u4f53\u7684<code>story<\/code>\u529f\u80fd\uff0c\u4e0d\u63a8\u8350\u4e00\u4e2a\u529f\u80fd\u51fa\u73b0\u591a\u6b21\u63d0\u4ea4\u7684\u60c5\u51b5 \uff0c\u5982\u679c\u7c7b\u578b\u7ed9\u7684\u592a\u591a\uff0c\u90a3\u4e48\u6211\u968f\u610f\u4fee\u6539\u4e00\u6b21\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u6709\u5bf9\u5e94\u7684\u7c7b\u578b\u6765\u9009\u62e9\uff0c\u4ee3\u7801\u5b8c\u6574\u6027\u4e0a\u5c31\u6ca1\u6709\u7ea6\u675f\u6027\u3002\u53e6\u4e00\u4e2a\u539f\u56e0\u4e5f\u662f\u8d8a\u7b80\u5355\u8d8a\u5bb9\u6613\u7406\u89e3\uff0c\u6bcf\u4e2a\u4eba\u90fd\u6709\u81ea\u5df1\u7684\u7406\u89e3\uff0c\u6bd4\u5982\u8bf4\uff0c\u6211\u4fee\u6539\u4e86\u4e00\u4e2a<code>pom<\/code>\u7684\u7248\u672c\u91cd\u65b0\u6253\u5305\uff0c\u4f46\u662f\u73b0\u5728\u7c7b\u578b\u6709 <code>ci<\/code> \u548c <code>build<\/code>\uff0c\u90a3\u8fd9\u4e2a\u573a\u666f\u8be5\u5982\u4f55\u9009\u62e9\uff0c\u76f8\u4fe1\u6709\u4eba\u4f1a\u8ba4\u4e3a\u662f<code>ci<\/code>\uff0c\u4e5f\u6709\u4eba\u4f1a\u8ba4\u4e3a\u662f<code>build<\/code><\/p>\n<ul>\n<li>\u63d0\u4ea4\u7c7b\u578b\u5982\u4f55\u9009\u62e9<\/li>\n<\/ul>\n<p>\u200b        \u9488\u5bf9\u4ee3\u7801\u91cd\u6784\uff0c\u6027\u80fd\u4f18\u5316\u8fd92\u4e2a\u573a\u666f\u6ca1\u6709\u7c7b\u578b\uff0c\u4ece\u8fed\u4ee3\u7684\u89d2\u5ea6\u8bf4\uff0c\u8fd92\u4e2a\u573a\u666f\u4e5f\u662f\u5c5e\u4e8e\u589e\u52a0\u65b0\u529f\u80fd\u6216\u8005\u4fee\u590d<code>bug<\/code>\uff0c\u56e0\u4e3a\u505a2\u4e2a\u4efb\u52a1\u7684\u65f6\u5019\uff0c\u80af\u5b9a\u662f\u9700\u8981\u5bf9\u5e94\u7684<code>story<\/code>\u6216<code>jira<\/code>\u6765\u8ddf\u8e2a\u3002 \u53ef\u80fd\u786e\u5b9e\u4f1a\u5b58\u5728\u4e00\u4e9b\u573a\u666f\u9700\u8981\u7279\u6b8a\u8c03\u6574\uff0c\u4f46\u662f\u4e00\u822c\u8fd9\u79cd\u573a\u666f\u90fd\u662f\u4f4e\u9891\u7684\uff0c\u9009\u62e9<code>other<\/code>\uff0c\u52a0\u4e0a\u5bf9\u5e94\u7684\u63cf\u8ff0\u5373\u53ef\uff0c\u5927\u5bb6\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\u7b26\u5408<code>angular<\/code>\u63d0\u4ea4\u7684\u90a3\u4e9b\u7c7b\u578b\u73b0\u5728\u53d8\u6210\u4e86\u5b50\u7c7b\u578b\uff0c\u53ea\u662f\u8bf4\u8fd9\u4e2a\u5b50\u7c7b\u578b\u662f\u653e\u5230\u4e86\u63cf\u8ff0\u5f53\u4e2d<\/p>\n<h4>\u6821\u9a8c<\/h4>\n<p>\u6b64\u8282\u4e3b\u8981\u662f\u63cf\u8ff0\u73b0\u6709\u5de5\u7a0b\u9879\u76ee\u5982\u4f55\u96c6\u6210<code>commit-msg hook<\/code>\u5bf9<code>Commit<\/code>\u4fe1\u606f\u8fdb\u884c\u9a8c\u8bc1\u3002\u521d\u6b65\u60f3\u6cd5\u662f\u5229\u7528<code>git<\/code>\u7684<code>hooks<\/code>\u6765\u8fdb\u884c\u9a8c\u8bc1\uff0c\u5f53\u6267\u884c<code>git commit<\/code> \u547d\u4ee4\u540e\uff0c\u4fbf\u4f1a\u81ea\u52a8\u89e6\u53d1\u6b64<code>hook<\/code>\uff0c\u7136\u540e\u5bf9\u63d0\u4ea4\u7684<code>commit<\/code> \u4fe1\u606f\u8fdb\u884c\u683c\u5f0f\u7684\u9a8c\u8bc1\u3002<\/p>\n<blockquote>\n<p>\u5c0f\u63d0\u793a<\/p>\n<p><code>Git Hook<\/code> \u5927\u81f4\u5206\u4e3a\u4e24\u79cd\uff0c\u4e00\u4e2a\u5728\u670d\u52a1\u7aef\uff0c\u4e00\u79cd\u653e\u5728\u672c\u5730\u3002\u5176\u4e2d\uff0c\u672c\u5730\u7684 <code>hook<\/code> \u4e0d\u53d7\u7248\u672c\u63a7\u5236\u5668\u7684\u7ba1\u7406\uff0c\u4e5f\u5c31\u662f\u8bf4\u6211\u4eec\u6ca1\u529e\u6cd5\u628a\u5199\u597d\u7684 <code>hook<\/code> \u811a\u672c\u653e\u5728<code>.git\/hooks<\/code>\u4e0b\u9762\uff0c\u7136\u540e\u63a8\u9001\u5230\u4ed3\u5e93\uff0c\u4f9b\u5c0f\u4f19\u4f34\u4eec\u4e0b\u8f7d\u3001\u4f7f\u7528\uff08\u9664\u975e\u81ea\u5df1\u5c06<code>hook<\/code>\u6587\u4ef6\u624b\u52a8\u590d\u5236\u5230\u9879\u76ee\u7684<code>.\/git\/hooks<\/code>\u76ee\u5f55\u4e0b\uff09<\/p>\n<p>\u7ecf\u8fc7\u5bf9<code>gerrit<\/code>\u4ee3\u7801\u5ba1\u6838\u5e73\u53f0\u7684\u5206\u6790\uff0c\u6211\u4eec\u5df2\u7ecf\u89e3\u51b3\u4e86\u9700\u8981\u5f00\u53d1\u540c\u5b66\u624b\u52a8\u6267\u884c\u547d\u4ee4\u4e0b\u8f7d<code>commit-hooks<\/code>\u7684\u95ee\u9898\uff0c\u5bf9\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u540c\u5b66\u53ef\u53c2\u8003\u4e0b\u9762\uff1a<\/p>\n<\/blockquote>\n<p><strong><code>gerrit<\/code>\u5982\u4f55\u66ff\u6362\u9ed8\u8ba4\u7684<code>commit-hook<\/code>\u6587\u4ef6<\/strong><\/p>\n<p>\u5982\u4f55\u96c6\u6210\u6211\u4eec\u81ea\u5b9a\u4e49<code>hook<\/code>\u8fdb\u884c\u63d0\u4ea4\u4fe1\u606f\u68c0\u67e5\u4e0a\uff0c\u5e76\u4e14\u8ba9\u5f00\u53d1\u540c\u5b66\u4ec0\u4e48\u90fd\u4e0d\u7528\u505a\u4fbf\u53ef\u83b7\u53d6\u5230\u6211\u4eec\u63d0\u4f9b\u7684\u89c4\u8303\u68c0\u67e5<code>hooks<\/code>\uff1f\u8d77\u521d\u9047\u5230\u4e86\u5f88\u591a\u95ee\u9898\uff0c\u547d\u4ee4\u884c\u3001\u63d2\u4ef6\u65b9\u5f0f\u90fd\u8fdb\u884c\u8fc7\u5c1d\u8bd5\uff0c\u4f46\u662f\u90fd\u6ca1\u6709\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u8fd8\u662f\u9700\u8981\u5f00\u53d1\u540c\u5b66\u624b\u52a8\u6267\u884c\u624d\u884c\uff0c\u4e3a\u4e86\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c<\/p>\n<p>\u6211\u4eec\u9996\u5148\u5728<code>gerrit<\/code>\u4ee3\u7801\u5ba1\u6838\u5e73\u53f0\u4e0a<code>clone<\/code>\u4e00\u4e2a\u5de5\u7a0b\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code class=\"shell\">clone\u5de5\u7a0b\u547d\u4ee4\n\n## SSH\u65b9\u5f0f\ngit clone &quot;ssh:\/\/a00514@gerrit.casstime.net:29418\/open\/icec-cloud-job&quot; &amp;&amp; scp -p -P 29418 a00514@gerrit.casstime.net:hooks\/commit-msg &quot;icec-cloud-job\/.git\/hooks\/&quot;\n\n## HTTP\u65b9\u5f0f\ngit clone &quot;http:\/\/a00514@gerrit.casstime.net:8087\/a\/open\/icec-cloud-job&quot; &amp;&amp; (cd &quot;icec-cloud-job&quot; &amp;&amp; mkdir -p .git\/hooks &amp;&amp; curl -Lo `git rev-parse --git-dir`\/hooks\/commit-msg http:\/\/a00514@gerrit.casstime.net:8087\/tools\/hooks\/commit-msg; chmod +x `git rev-parse --git-dir`\/hooks\/commit-msg)\n\n## ANONYMOUS HTTP\u65b9\u5f0f\ngit clone &quot;http:\/\/gerrit.casstime.net:8087\/open\/icec-cloud-job&quot; &amp;&amp; (cd &quot;icec-cloud-job&quot; &amp;&amp; mkdir -p .git\/hooks &amp;&amp; curl -Lo `git rev-parse --git-dir`\/hooks\/commit-msg http:\/\/gerrit.casstime.net:8087\/tools\/hooks\/commit-msg; chmod +x `git rev-parse --git-dir`\/hooks\/commit-msg)<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u547d\u4ee4\u88ab\u5206\u4e3a\u4e862\u4e2a\u90e8\u5206\uff0c\u4e00\u4e2a\u90e8\u5206\u662f\u6267\u884c<code>clone<\/code>\u4ee3\u7801\u64cd\u4f5c\uff0c \u4e00\u4e2a\u90e8\u5206\u662f\u6267\u884c\u4e0b\u8f7d<code>gerrit<\/code>\u63d0\u4f9b<code>hooks<\/code>\u64cd\u4f5c\uff0c\u7531\u6b64\u53ef\u77e5\uff0c<code>gerrit<\/code>\u662f\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u7684<code>commit-hook<\/code>\u6587\u4ef6\u7684\uff0c\u6211\u4eec\u53ea\u8981\u5bf9\u5176\u8fdb\u884c\u66ff\u6362\u5373\u53ef\u3002<\/p>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u7684\u5206\u6790\uff0c\u6211\u4eec\u505a\u4e86\u4ee5\u4e0b\u7684\u64cd\u4f5c\u6b65\u9aa4<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZp\" alt=\"image2022-5-19_15-54-40.png\" title=\"image2022-5-19_15-54-40.png\" loading=\"lazy\" ><\/p>\n<blockquote><p>\u6ce8\uff1a\u6587\u6863\u4e2d\u7684<code>lib<\/code>\u4f4d\u7f6e\u662f\u9519\u8bef\u7684\uff0c\u771f\u6b63\u9700\u8981\u66ff\u6362\u662f\u622a\u56fe\u4e2d\u7684<code>lib<\/code>\u5305\uff0c\u66ff\u6362\u5b8c\u6210\u91cd\u542f\u65e2\u53ef\uff0c \u4e0d\u9700\u8981\u6267\u884c\u521d\u59cb\u5316\u7b49\u6b65\u9aa4<\/p><\/blockquote>\n<h4>\u64cd\u4f5c\u6b65\u9aa4<\/h4>\n<blockquote>\n<p>\u5c0f\u63d0\u793a \uff08\u524d\u7aef\u5f00\u53d1\u540c\u5b66\u6ce8\u610f\uff09<\/p>\n<p><code>git<\/code>\u63d0\u4ea4\u89c4\u8303\u8bd5\u884c\u7684\u8fc7\u7a0b\u4e2d\uff0c\u524d\u7aef\u5de5\u7a0b\u7684\u597d\u50cf\u662f\u96c6\u6210\u4e86\u4e00\u4e2a<code>husky<\/code>\u63d2\u4ef6\uff0c\u8986\u76d6\u4e86\u5de5\u7a0b<code>.git\/hooks<\/code>\u4e0b\u7684\u6587\u4ef6\uff0c\u9488\u5bf9\u8fd9\u4e2a\u60c5\u51b5\uff0c\u524d\u7aef\u8fd9\u8fb9\u7684\u5de5\u7a0b\uff0c\u7531<code>SE<\/code>\u81ea\u5df1\u51b3\u5b9a\u662f\u7ee7\u7eed\u4f7f\u7528 <code>husky<\/code>\u63d2\u4ef6 \u6216\u8005 \u4f7f\u7528\u6211\u4eec\u63a8\u8350\u7684\u65b9\u5f0f<\/p>\n<\/blockquote>\n<p>1\u3001\u5982\u679c\u662f\u8fd8\u672a<code>clone<\/code>\u7684\u5de5\u7a0b\uff0c\u6b63\u5e38<code>clone<\/code>\u5de5\u7a0b\u5373\u53ef\uff0c\u5176\u5b83\u7684\u4ec0\u4e48\u90fd\u4e0d\u7528\u505a\uff0c\u6211\u4eec\u5df2\u7ecf\u66ff\u6362\u4e86<code>gerrit<\/code>\u9ed8\u8ba4\u7684<code>commi-hook<\/code>\u6587\u4ef6\uff0c\u6821\u9a8c\u6587\u4ef6\u4f1a\u968f<code>clone<\/code>\u547d\u4ee4\u81ea\u52a8\u514b\u9686\u5230\u5de5\u7a0b\u7684<code>.git\/hooks<\/code>\u76ee\u5f55\u4e0b\u3002<\/p>\n<p>2\u3001\u5982\u679c\u662f\u5728<code>git<\/code>\u63d0\u4ea4\u89c4\u8303\u89c4\u8303\u63a8\u884c\u4e4b\u524d\u5df2\u7ecf<code>clone<\/code>\u5230\u4e86\u672c\u5730\u7684\u5de5\u7a0b\uff0c\u5219\u9700\u8981\u81ea\u5df1\u624b\u52a8\u6267\u884c\u547d\u4ee4\u4e0b\u8f7d<code>commit-hook<\/code>\uff0c\u547d\u4ee4\u5982\u4e0b<\/p>\n<p><strong>hook\u4e0b\u8f7d\u547d\u4ee4<\/strong><\/p>\n<pre><code class=\"shell\"># \u5982\u679cclone\u7684\u9879\u76ee\u662fgerrit\u9879\u76ee\uff0c\u5219\u6267\u884c\u6b64\u547d\u4ee4\ncurl -Lo .git\/hooks\/commit-msg http:\/\/10.2.43.24:3311\/commit-msg\n \n# \u5982\u679cclone\u7684\u9879\u76ee\u662fgitlab\u9879\u76ee\uff0c\u5219\u6267\u884c\u6b64\u547d\u4ee4\ncurl -Lo .git\/hooks\/commit-msg http:\/\/10.2.43.24:3311\/commit-msg-nogerrit<\/code><\/pre>\n<p>3\u3001\u6267\u884c\u540e\uff0c\u6253\u5f00\u9879\u76ee<code>.git\/hooks<\/code>\u76ee\u5f55\u4e0b\u7684<code>commit-msg<\/code>\u6587\u4ef6\uff0c\u5982\u679c\u770b\u5230\u4ee5\u4e0b\u4fe1\u606f\uff0c\u8bf4\u660e\u5df2\u7ecf\u6210\u529f\u4e0b\u8f7d\u4e86<code>commit-hook<\/code><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZq\" alt=\"image2022-4-18_10-7-28.png\" title=\"image2022-4-18_10-7-28.png\" loading=\"lazy\" ><\/p>\n<h4>\u793a\u4f8b<\/h4>\n<p>\u6a21\u62df\u4e00\u4e2a\u4e0d\u7b26\u5408\u89c4\u8303\u7684\u63d0\u4ea4\uff0c\u5f53\u6267\u884c<code>commit<\/code>\u52a8\u4f5c\u540e\uff0c\u4f1a\u63d0\u793a\u4e0d\u7b26\u5408\u89c4\u8303\uff0c\u7136\u540e\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u76f8\u5e94\u7684\u63d0\u4ea4\u89c4\u8303\u8bf4\u660e<\/p>\n<ul>\n<li>\u793a\u4f8b1\uff1a\u6a21\u62df\u547d\u4ee4\u884c\u63d0\u4ea4\u4e0d\u901a\u8fc7<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZr\" alt=\"image2022-4-13_15-4-10.png\" title=\"image2022-4-13_15-4-10.png\" loading=\"lazy\" ><\/p>\n<ul>\n<li>\u793a\u4f8b2\uff1a\u6a21\u62df<code>IDEA<\/code> \u63d0\u4ea4\u4e0d\u901a\u8fc7<\/li>\n<\/ul>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVc0xZs\" alt=\"image2022-4-13_15-4-58.png\" title=\"image2022-4-13_15-4-58.png\" loading=\"lazy\" ><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042037321\">https:\/\/segmentfault.com\/a\/1190000042037321<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git \u914d\u7f6e\u89c4\u8303 \u914d\u7f6e\u7528\u6237\u540d\u548c\u90ae\u4ef6 \u4e3a\u4e86\u63d0\u4ea4\u8bb0\u5f55\u4fbf\u4e8e\u8bc6\u522b\uff0c\u914d\u7f6e\u4e2d\u6587\u540d\uff0c\u90ae\u7bb1\u914d\u7f6e\u6210gitlab\u6ce8\u518c\u90ae\u7bb1 git  [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10005978","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10005978","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"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10005978"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10005978\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10005978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10005978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10005978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}