{"id":18787,"date":"2024-11-19T12:56:57","date_gmt":"2024-11-19T04:56:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18787\/"},"modified":"2024-11-19T12:56:57","modified_gmt":"2024-11-19T04:56:57","slug":"%e8%81%8a%e8%81%8agithub%e4%b8%8a%e5%ae%9e%e7%8e%b0%e7%a6%81%e6%ad%a2%e6%96%b0%e5%bb%ba%e5%88%86%e6%94%af%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18787\/","title":{"rendered":"\u804a\u804aGitHub\u4e0a\u5b9e\u73b0\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>github\u662f\u4e00\u6b3e\u975e\u5e38\u53d7\u6b22\u8fce\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u62e5\u6709\u4f17\u591a\u5f00\u53d1\u8005\u5728\u4e0a\u9762\u5171\u540c\u5f00\u53d1\u9879\u76ee\u3002\u5728github\u4e0a\uff0c\u4e00\u4e2a\u9879\u76ee\u901a\u5e38\u4f1a\u6709\u591a\u4e2a\u5206\u652f(branch)\u8fdb\u884c\u5e76\u884c\u5f00\u53d1\uff0c\u5e76\u4e14\u65b0\u5efa\u5206\u652f\u662f\u975e\u5e38\u5bb9\u6613\u7684\u3002\u4f46\u662f\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u4f1a\u9700\u8981\u7981\u6b62\u5728\u67d0\u4e9b\u5206\u652f\u4e0a\u65b0\u5efa\u5206\u652f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728github\u4e0a\u5b9e\u73b0\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u65b9\u6cd5\u3002<\/p>\n<h4>\u4e00\u3001\u901a\u8fc7web\u754c\u9762\u7981\u6b62\u65b0\u5efa\u5206\u652f<\/h4>\n<p>\u9996\u5148\u767b\u5f55\u4f60\u7684GitHub\u8d26\u53f7\u5e76\u8fdb\u5165\u4f60\u8981\u64cd\u4f5c\u7684\u9879\u76ee\u9875\u9762\uff0c\u70b9\u51fb\u9875\u9762\u4e0a\u65b9\u7684\u201dsettings\u201d\u6309\u94ae\u8fdb\u5165\u9879\u76ee\u7684\u8bbe\u7f6e\u754c\u9762\u3002\u5728\u8bbe\u7f6e\u754c\u9762\u4e2d\u627e\u5230\u201dBranches\u201d\u9009\u9879\u5361<\/p>\n<p>\u5728\u201cBranches\u201d\u9009\u9879\u5361\u4e2d\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u6240\u6709\u7684\u5206\u652f\u5217\u8868\u4ee5\u53ca\u6bcf\u4e2a\u5206\u652f\u7684\u6743\u9650\u8bbe\u7f6e\u3002\u8981\u7981\u6b62\u65b0\u5efa\u5206\u652f\uff0c\u4f60\u9700\u8981\u5c06\u8981\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u201cCreate branch\u201d\u7684\u52fe\u9009\u6846\u53d6\u6d88\u52fe\u9009\u3002\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7981\u6b62\u5220\u9664\u5206\u652f\u4ee5\u53ca\u7981\u6b62\u5f3a\u5236\u63a8\u9001\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u7279\u6b8a\u7684\u5206\u652f\uff0c\u6bd4\u5982\u201dmaster\u201d\u5206\u652f\uff0c\u5f80\u5f80\u8981\u8bbe\u7f6e\u66f4\u52a0\u4e25\u683c\u7684\u6743\u9650\uff0c\u8fd9\u6837\u624d\u80fd\u6709\u6548\u9632\u6b62\u5206\u652f\u88ab\u8bef\u5220\u9664\u6216\u8005\u8bef\u4fee\u6539\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5c06master\u5206\u652f\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a\u201dAdmin\u201d\uff08\u5373\u53ea\u6709\u7ba1\u7406\u5458\u624d\u80fd\u4fee\u6539\u548c\u5220\u9664\u8be5\u5206\u652f\uff09\uff0c\u5176\u4ed6\u5206\u652f\u5219\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n<h4>\u4e8c\u3001\u901a\u8fc7Git\u547d\u4ee4\u7981\u6b62\u65b0\u5efa\u5206\u652f<\/h4>\n<p>\u9664\u4e86\u901a\u8fc7web\u754c\u9762\u8fdb\u884c\u5206\u652f\u6743\u9650\u7684\u8bbe\u7f6e\u4e4b\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7Git\u547d\u4ee4\u884c\u7981\u6b62\u65b0\u5efa\u5206\u652f\u3002\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u4f60\u9700\u8981\u5728\u672c\u5730\u514b\u9686\u9879\u76ee\uff0c\u5e76\u5c06\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u4fdd\u5b58\u5230\u8be5\u9879\u76ee\u672c\u5730\u6587\u4ef6\u5939\u4e2d\u3002\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p>1.\u6253\u5f00\u547d\u4ee4\u884c\u7ec8\u7aef\uff0c\u8fdb\u5165\u4f60\u8981\u514b\u9686\u7684\u9879\u76ee\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u514b\u9686\uff1a<\/p>\n<pre>git clone https:\/\/github.com\/username\/repo.git<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u91cc\u7684\u201dusername\u201d\u662f\u4f60\u7684GitHub\u8d26\u53f7\u540d\uff0c\u201crepo\u201d\u5219\u662f\u8981\u514b\u9686\u7684\u9879\u76ee\u540d\u79f0\u3002<\/p>\n<p>2.\u8fdb\u5165\u514b\u9686\u4e0b\u6765\u7684\u9879\u76ee\u6587\u4ef6\u5939\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210.git\u6587\u4ef6\u5939\uff1a<\/p>\n<pre>cd repo\ngit init<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>3.\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5c06\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u4fdd\u5b58\u5230.git\/hooks\u76ee\u5f55\u4e0b\uff1a<\/p>\n<pre>echo \"refname='refs\/heads\/*'\ndenyBranch() {\n    if [[ $1 =~ $refname ]]; then\n        echo \"Creation of new branches on the $refname branch has been disabled.\"\n    exit 1\n    fi\n}\ntrap 'denyBranch $refname' PREPARE_COMMIT_MSG\" &gt; .git\/hooks\/pre-push<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a\u201ddenyBranch\u201d\u7684\u51fd\u6570\uff0c\u5982\u679c\u6709\u4eba\u5c1d\u8bd5\u5728\u6307\u5b9a\u5206\u652f\u4e0a\u521b\u5efa\u65b0\u7684\u5206\u652f\uff0c\u8be5\u51fd\u6570\u5c31\u4f1a\u5f39\u51fa\u8b66\u544a\uff0c\u5e76\u963b\u6b62\u65b0\u5206\u652f\u7684\u521b\u5efa\u3002<\/p>\n<p>4.\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u5c06\u4fee\u6539\u4e0a\u4f20\u5230\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\uff1a<\/p>\n<pre>git add .\ngit commit -m \"disable new branch creation\"\ngit push --force<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u672c\u5730\u4ed3\u5e93\u4e2d\u7684\u4fee\u6539\u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u3002\u5f53\u9879\u76ee\u7ba1\u7406\u8005\u5728push\u4ee3\u7801\u7684\u65f6\u5019\uff0cGit\u4f1a\u81ea\u52a8\u8c03\u7528hook\u6587\u4ef6\uff0c\u68c0\u67e5\u662f\u5426\u6709\u65b0\u5efa\u5206\u652f\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u603b\u7ed3\uff1a<\/p>\n<p>\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u64cd\u4f5c\u5bf9\u4e8e\u4e00\u4e9b\u5f00\u53d1\u56e2\u961f\u6765\u8bf4\u975e\u5e38\u5fc5\u8981\uff0c\u8fd9\u53ef\u4ee5\u4fdd\u8bc1\u4ee3\u7801\u5e93\u4e2d\u7684\u5206\u652f\u4e0d\u88ab\u968f\u610f\u589e\u52a0\uff0c\u4ece\u800c\u5e2e\u52a9\u56e2\u961f\u66f4\u597d\u5730\u8fdb\u884c\u63a7\u5236\u548c\u7ba1\u7406\u4ee3\u7801\u8d28\u91cf\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e24\u79cd\u65b9\u6cd5\u5b9e\u73b0\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u64cd\u4f5c\uff0c\u8bfb\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u804a\u804aGitHub\u4e0a\u5b9e\u73b0\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u65b9\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>github\u662f\u4e00\u6b3e\u975e\u5e38\u53d7\u6b22\u8fce\u7684\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u62e5\u6709\u4f17\u591a\u5f00\u53d1\u8005\u5728\u4e0a\u9762\u5171\u540c\u5f00\u53d1\u9879\u76ee\u3002\u5728github\u4e0a\uff0c\u4e00\u4e2a\u9879\u76ee\u901a\u5e38\u4f1a\u6709\u591a\u4e2a\u5206\u652f(branch)\u8fdb\u884c\u5e76\u884c\u5f00\u53d1\uff0c\u5e76\u4e14\u65b0\u5efa\u5206\u652f\u662f\u975e\u5e38\u5bb9\u6613\u7684\u3002\u4f46\u662f\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u80fd\u4f1a\u9700\u8981\u7981\u6b62\u5728\u67d0\u4e9b\u5206\u652f\u4e0a\u65b0\u5efa\u5206\u652f\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728github\u4e0a\u5b9e\u73b0\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u65b9\u6cd5\u3002 \u4e00\u3001\u901a\u8fc7web\u754c\u9762\u7981\u6b62\u65b0\u5efa\u5206\u652f \u9996\u5148\u767b\u5f55\u4f60\u7684GitHub\u8d26\u53f7\u5e76\u8fdb\u5165\u4f60\u8981\u64cd\u4f5c\u7684\u9879\u76ee\u9875\u9762\uff0c\u70b9\u51fb\u9875\u9762\u4e0a\u65b9\u7684\u201dsettings\u201d\u6309\u94ae\u8fdb\u5165\u9879\u76ee\u7684\u8bbe\u7f6e\u754c\u9762\u3002\u5728\u8bbe\u7f6e\u754c\u9762\u4e2d\u627e\u5230\u201dBranches\u201d\u9009\u9879\u5361 \u5728\u201cBranches\u201d\u9009\u9879\u5361\u4e2d\uff0c\u4f60\u53ef\u4ee5\u770b\u5230\u6240\u6709\u7684\u5206\u652f\u5217\u8868\u4ee5\u53ca\u6bcf\u4e2a\u5206\u652f\u7684\u6743\u9650\u8bbe\u7f6e\u3002\u8981\u7981\u6b62\u65b0\u5efa\u5206\u652f\uff0c\u4f60\u9700\u8981\u5c06\u8981\u7981\u6b62\u65b0\u5efa\u5206\u652f\u7684\u201cCreate branch\u201d\u7684\u52fe\u9009\u6846\u53d6\u6d88\u52fe\u9009\u3002\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u7981\u6b62\u5220\u9664\u5206\u652f\u4ee5\u53ca\u7981\u6b62\u5f3a\u5236\u63a8\u9001\u3002 \u5bf9\u4e8e\u4e00\u4e9b\u7279\u6b8a\u7684\u5206\u652f\uff0c\u6bd4\u5982\u201dmaster\u201d\u5206\u652f\uff0c\u5f80\u5f80\u8981\u8bbe\u7f6e\u66f4\u52a0\u4e25\u683c\u7684\u6743\u9650\uff0c\u8fd9\u6837\u624d\u80fd\u6709\u6548\u9632\u6b62\u5206\u652f\u88ab\u8bef\u5220\u9664\u6216\u8005\u8bef\u4fee\u6539\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5c06master\u5206\u652f\u7684\u6743\u9650\u8bbe\u7f6e\u4e3a\u201dAdmin\u201d\uff08\u5373\u53ea\u6709\u7ba1\u7406\u5458\u624d\u80fd\u4fee\u6539\u548c\u5220\u9664\u8be5\u5206\u652f\uff09\uff0c\u5176\u4ed6\u5206\u652f\u5219\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u8bbe\u7f6e\u3002 \u4e8c\u3001\u901a\u8fc7Git\u547d\u4ee4\u7981\u6b62\u65b0\u5efa\u5206\u652f \u9664\u4e86\u901a\u8fc7web\u754c\u9762\u8fdb\u884c\u5206\u652f\u6743\u9650\u7684\u8bbe\u7f6e\u4e4b\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7Git\u547d\u4ee4\u884c\u7981\u6b62\u65b0\u5efa\u5206\u652f\u3002\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u4f60\u9700\u8981\u5728\u672c\u5730\u514b\u9686\u9879\u76ee\uff0c\u5e76\u5c06\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u4fdd\u5b58\u5230\u8be5\u9879\u76ee\u672c\u5730\u6587\u4ef6\u5939\u4e2d\u3002\u5177\u4f53\u64cd\u4f5c\u6b65\u9aa4\u5982\u4e0b\uff1a 1.\u6253\u5f00\u547d\u4ee4\u884c\u7ec8\u7aef\uff0c\u8fdb\u5165\u4f60\u8981\u514b\u9686\u7684\u9879\u76ee\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u514b\u9686\uff1a git clone https:\/\/github.com\/username\/repo.git \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u91cc\u7684\u201dusername\u201d\u662f\u4f60\u7684GitHub\u8d26\u53f7\u540d\uff0c\u201crepo\u201d\u5219\u662f\u8981\u514b\u9686\u7684\u9879\u76ee\u540d\u79f0\u3002 2.\u8fdb\u5165\u514b\u9686\u4e0b\u6765\u7684\u9879\u76ee\u6587\u4ef6\u5939\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210.git\u6587\u4ef6\u5939\uff1a cd repo git init \u767b\u5f55\u540e\u590d\u5236 3.\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5c06\u6743\u9650\u914d\u7f6e\u6587\u4ef6\u4fdd\u5b58\u5230.git\/hooks\u76ee\u5f55\u4e0b\uff1a echo &#8220;refname=&#8217;refs\/heads\/*&#8217; denyBranch() { if [[ $1 =~ $refname ]]; then echo &#8220;Creation of new branches on the $refname branch has been disabled.&#8221; exit 1 fi } trap &#8216;denyBranch $refname&#8217; PREPARE_COMMIT_MSG&#8221; &gt; .git\/hooks\/pre-push \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-18787","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18787"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18787\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18787"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18787"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}