{"id":21204,"date":"2024-11-19T11:50:27","date_gmt":"2024-11-19T03:50:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21204\/"},"modified":"2024-11-19T11:50:27","modified_gmt":"2024-11-19T03:50:27","slug":"git%e6%8f%90%e4%ba%a4%e5%88%b0%e4%ba%86master%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21204\/","title":{"rendered":"git\u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  \u5f53 git \u63d0\u4ea4\u610f\u5916\u63d0\u4ea4\u5230 master \u5206\u652f\u65f6\uff0c\u5904\u7406\u65b9\u6cd5\u6709\uff1a\u56de\u6eda\u63d0\u4ea4\u521b\u5efa\u65b0\u5206\u652f\u5e76\u5408\u5e76\u91cd\u7f6e master \u5206\u652f\u5220\u9664\u5e76\u91cd\u65b0\u521b\u5efa master \u5206\u652f\u9009\u62e9\u65b9\u6cd5\u9700\u8003\u8651\u4ee3\u7801\u7834\u574f\u6027\u3001\u5de5\u4f5c\u91cf\u548c\u5386\u53f2\u8bb0\u5f55\u4fdd\u7559\u9700\u6c42\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040911482090206.jpg\" class=\"aligncenter\" title=\"git\u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"git\u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e<\/strong><\/p>\n<p>\u5f53\u4f60\u610f\u5916\u5c06\u4ee3\u7801\u63d0\u4ea4\u5230master\u5206\u652f\u65f6\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u56de\u6eda<\/strong><\/p>\n<ul>\n<li>\u68c0\u67e5\u4ee3\u7801\u662f\u5426\u5177\u6709\u7834\u574f\u6027\uff0c\u6216\u662f\u5426\u53ef\u5b89\u5168\u64a4\u9500\u3002<\/li>\n<li>\n<p>\u5982\u679c\u53ef\u4ee5\u5b89\u5168\u64a4\u9500\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u56de\u6eda\u63d0\u4ea4\uff1a<\/p>\n<pre>git revert COMMIT_HASH<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>2. \u521b\u5efa\u65b0\u5206\u652f\u5e76\u5408\u5e76<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u652f\u5e76\u5305\u542b\u610f\u5916\u63d0\u4ea4\u3002<\/li>\n<li>\n<p>\u5408\u5e76\u8be5\u5206\u652f\u5230master\u5206\u652f\uff1a<\/p>\n<pre>git checkout -b new-branch\ngit merge master\ngit push origin new-branch\ngit checkout master\ngit merge new-branch<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>3. \u91cd\u7f6emaster\u5206\u652f<\/strong><\/p>\n<ul>\n<li>\u5c06master\u5206\u652f\u91cd\u7f6e\u5230\u610f\u5916\u63d0\u4ea4\u524d\u7684\u72b6\u6001\u3002\u8b66\u544a\uff1a\u8fd9\u5c06\u5220\u9664\u8be5\u63d0\u4ea4\u4ee5\u540e\u7684\u6240\u6709\u63d0\u4ea4\u3002<\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u7f6emaster\u5206\u652f\uff1a<\/p>\n<pre>git reset --hard COMMIT_HASH_BEFORE_UNWANTED_COMMIT<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>4. \u5220\u9664\u5e76\u91cd\u65b0\u521b\u5efamaster\u5206\u652f<\/strong><\/p>\n<ul>\n<li>\u5220\u9664master\u5206\u652f\u5e76\u91cd\u65b0\u521b\u5efa\u5b83\u3002\u8b66\u544a\uff1a\u8fd9\u5c06\u5220\u9664\u5206\u652f\u4e0a\u7684\u6240\u6709\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002<\/li>\n<li>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664master\u5206\u652f\uff1a<\/p>\n<pre>git branch -D master<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u91cd\u65b0\u521b\u5efamaster\u5206\u652f\uff1a<\/p>\n<pre>git checkout -b master<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff1f<\/strong><\/p>\n<p>\u9009\u62e9\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u4ee5\u4e0b\u56e0\u7d20\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u7684\u7834\u574f\u6027<\/li>\n<li>\u63d0\u4ea4\u540e\u7684\u5de5\u4f5c\u91cf<\/li>\n<li>\u662f\u5426\u9700\u8981\u4fdd\u7559\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u6267\u884c\u4efb\u4f55\u64cd\u4f5c\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u4f60\u6709\u4ee3\u7801\u7684\u5907\u4efd\u3002<\/li>\n<li>\u8bf7\u4ed4\u7ec6\u8003\u8651\u5f71\u54cd\uff0c\u5e76\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u6700\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e\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>\u5f53 git \u63d0\u4ea4\u610f\u5916\u63d0\u4ea4\u5230 master \u5206\u652f\u65f6\uff0c\u5904\u7406\u65b9\u6cd5\u6709\uff1a\u56de\u6eda\u63d0\u4ea4\u521b\u5efa\u65b0\u5206\u652f\u5e76\u5408\u5e76\u91cd\u7f6e master \u5206\u652f\u5220\u9664\u5e76\u91cd\u65b0\u521b\u5efa master \u5206\u652f\u9009\u62e9\u65b9\u6cd5\u9700\u8003\u8651\u4ee3\u7801\u7834\u574f\u6027\u3001\u5de5\u4f5c\u91cf\u548c\u5386\u53f2\u8bb0\u5f55\u4fdd\u7559\u9700\u6c42\u3002 \u63d0\u4ea4\u5230\u4e86master\u600e\u4e48\u529e \u5f53\u4f60\u610f\u5916\u5c06\u4ee3\u7801\u63d0\u4ea4\u5230master\u5206\u652f\u65f6\uff0c\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u89e3\u51b3\uff1a 1. \u76f4\u63a5\u56de\u6eda \u68c0\u67e5\u4ee3\u7801\u662f\u5426\u5177\u6709\u7834\u574f\u6027\uff0c\u6216\u662f\u5426\u53ef\u5b89\u5168\u64a4\u9500\u3002 \u5982\u679c\u53ef\u4ee5\u5b89\u5168\u64a4\u9500\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u56de\u6eda\u63d0\u4ea4\uff1a git revert COMMIT_HASH \u767b\u5f55\u540e\u590d\u5236 2. \u521b\u5efa\u65b0\u5206\u652f\u5e76\u5408\u5e76 \u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u652f\u5e76\u5305\u542b\u610f\u5916\u63d0\u4ea4\u3002 \u5408\u5e76\u8be5\u5206\u652f\u5230master\u5206\u652f\uff1a git checkout -b new-branch git merge master git push origin new-branch git checkout master git merge new-branch \u767b\u5f55\u540e\u590d\u5236 3. \u91cd\u7f6emaster\u5206\u652f \u5c06master\u5206\u652f\u91cd\u7f6e\u5230\u610f\u5916\u63d0\u4ea4\u524d\u7684\u72b6\u6001\u3002\u8b66\u544a\uff1a\u8fd9\u5c06\u5220\u9664\u8be5\u63d0\u4ea4\u4ee5\u540e\u7684\u6240\u6709\u63d0\u4ea4\u3002 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u7f6emaster\u5206\u652f\uff1a git reset &#8211;hard COMMIT_HASH_BEFORE_UNWANTED_COMMIT \u767b\u5f55\u540e\u590d\u5236 4. \u5220\u9664\u5e76\u91cd\u65b0\u521b\u5efamaster\u5206\u652f \u5220\u9664master\u5206\u652f\u5e76\u91cd\u65b0\u521b\u5efa\u5b83\u3002\u8b66\u544a\uff1a\u8fd9\u5c06\u5220\u9664\u5206\u652f\u4e0a\u7684\u6240\u6709\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002 \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5220\u9664master\u5206\u652f\uff1a git [&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-21204","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21204","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=21204"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21204\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}