{"id":53532,"date":"2023-09-17T18:30:37","date_gmt":"2023-09-17T10:30:37","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=53532"},"modified":"2023-09-17T18:30:42","modified_gmt":"2023-09-17T10:30:42","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8git%e4%b8%ad%e5%88%a0%e9%99%a4%e4%b8%80%e4%b8%aa%e4%bb%93%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/53532.html","title":{"rendered":"\u5982\u4f55\u5728Git\u4e2d\u5220\u9664\u4e00\u4e2a\u4ed3\u5e93"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u5728Git\u4e2d\u5220\u9664\u4e00\u4e2a\u4ed3\u5e93\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\uff0c\u5206\u522b\u662f\uff1a\u4e00\u3001\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93\uff1b\u4e8c\u3001\u4ece\u672c\u5730\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93\u3002\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93\u7684\u6b65\u9aa4\u6709\uff1a1. \u767b\u5f55\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff1b2. \u627e\u5230\u4ed3\u5e93\uff1b3. \u8fdb\u5165\u4ed3\u5e93\u8bbe\u7f6e\uff1b4. \u5220\u9664\u4ed3\u5e93\uff1b5. \u786e\u8ba4\u5220\u9664\uff1b6. \u7b49\u5f85\u5220\u9664\u5b8c\u6210\uff1b7. \u5220\u9664\u5b8c\u6210\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u767b\u5f55\u5230\u6258\u7ba1\u4f60\u9879\u76ee\u7684\u8fdc\u7a0b\u4ed3\u5e93\u5e73\u53f0\uff0c\u5982GitHub\u3001GitLab\u6216Bitbucket\u3002<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"680\" height=\"421\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/09\/3-2-1.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-53534\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93<\/h2>\n\n\n\n<ol>\n<li><strong>\u767b\u5f55\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/strong>\uff1a\u9996\u5148\uff0c\u4f60\u9700\u8981\u767b\u5f55\u5230\u6258\u7ba1\u4f60\u9879\u76ee\u7684\u8fdc\u7a0b\u4ed3\u5e93\u5e73\u53f0\uff0c\u5982GitHub\u3001GitLab\u6216Bitbucket\u3002<\/li>\n\n\n\n<li><strong>\u627e\u5230\u4ed3\u5e93<\/strong>\uff1a\u5728\u4ed3\u5e93\u5217\u8868\u6216\u4eea\u8868\u677f\u4e0a\u627e\u5230\u4f60\u8981\u5220\u9664\u7684\u4ed3\u5e93\u3002<\/li>\n\n\n\n<li><strong>\u8fdb\u5165\u4ed3\u5e93\u8bbe\u7f6e<\/strong>\uff1a\u901a\u5e38\uff0c\u5728\u4ed3\u5e93\u9875\u9762\u7684\u53f3\u4e0a\u89d2\u6216\u5de6\u4fa7\u8fb9\u680f\u6709\u4e00\u4e2a\u201c\u8bbe\u7f6e\u201d\u9009\u9879\u3002\u70b9\u51fb\u8fdb\u5165\u4ed3\u5e93\u8bbe\u7f6e\u9875\u9762\u3002<\/li>\n\n\n\n<li><strong>\u5220\u9664\u4ed3\u5e93<\/strong>\uff1a\u5728\u4ed3\u5e93\u8bbe\u7f6e\u9875\u9762\uff0c\u901a\u5e38\u4f1a\u6709\u4e00\u4e2a\u201c\u5220\u9664\u4ed3\u5e93\u201d\u6216\u7c7b\u4f3c\u7684\u9009\u9879\u3002\u70b9\u51fb\u8fd9\u4e2a\u9009\u9879\u3002<\/li>\n\n\n\n<li><strong>\u786e\u8ba4\u5220\u9664<\/strong>\uff1a\u7cfb\u7edf\u4f1a\u8981\u6c42\u4f60\u8fdb\u884c\u6700\u540e\u7684\u786e\u8ba4\u3002\u53ef\u80fd\u9700\u8981\u8f93\u5165\u4f60\u7684\u5bc6\u7801\u6216\u8fdb\u884c\u5176\u4ed6\u8eab\u4efd\u9a8c\u8bc1\u3002\u8bf7\u4ed4\u7ec6\u9605\u8bfb\u8b66\u544a\uff0c\u786e\u4fdd\u4f60\u771f\u7684\u60f3\u8981\u5220\u9664\u4ed3\u5e93\u3002<\/li>\n\n\n\n<li><strong>\u7b49\u5f85\u5220\u9664\u5b8c\u6210<\/strong>\uff1a\u4e00\u65e6\u786e\u8ba4\u5220\u9664\uff0c\u7cfb\u7edf\u4f1a\u5f00\u59cb\u5220\u9664\u4ed3\u5e93\u3002\u8fd9\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4ed3\u5e93\u7684\u5927\u5c0f\u548c\u5e73\u53f0\u7684\u6027\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u5220\u9664\u5b8c\u6210<\/strong>\uff1a\u4e00\u65e6\u5220\u9664\u5b8c\u6210\uff0c\u4f60\u5c06\u6536\u5230\u901a\u77e5\uff0c\u5e76\u4e14\u4ed3\u5e93\u5c06\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u5e73\u53f0\u4e0a\u5b8c\u5168\u5220\u9664\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u4ece\u672c\u5730\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u754c\u9762<\/strong><\/h3>\n\n\n\n<p>\u5728\u4f60\u7684\u8ba1\u7b97\u673a\u4e0a\uff0c\u8fdb\u5165\u672c\u5730\u4ed3\u5e93\u7684\u76ee\u5f55\uff0c\u5e76\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u79fb\u9664\u8fdc\u7a0b\u4ed3\u5e93\u8fde\u63a5<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u7684\u672c\u5730\u4ed3\u5e93\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u6709\u5173\u8054\uff0c\u8bf7\u5148\u79fb\u9664\u8fdc\u7a0b\u4ed3\u5e93\u8fde\u63a5\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u8fde\u63a5\u4ece\u672c\u5730\u4ed3\u5e93\u4e2d\u5220\u9664\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote remove &lt;\u8fdc\u7a0b\u4ed3\u5e93\u540d\u79f0&gt;<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u8fdc\u7a0b\u4ed3\u5e93\u540d\u79f0\u662f&#8221;origin&#8221;\uff0c\u5219\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote remove origin<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u5220\u9664\u672c\u5730\u4ed3\u5e93\u76ee\u5f55<\/strong><\/h3>\n\n\n\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5220\u9664\u672c\u5730\u4ed3\u5e93\u7684\u76ee\u5f55\u53ca\u5176\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git rm -r &lt;\u672c\u5730\u4ed3\u5e93\u76ee\u5f55&gt;\r<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u672c\u5730\u4ed3\u5e93\u76ee\u5f55\u540d\u4e3a&#8221;my_project&#8221;\uff0c\u5219\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git rm -r my_project<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u63d0\u4ea4\u66f4\u6539<\/strong><\/h3>\n\n\n\n<p>\u63d0\u4ea4\u5220\u9664\u64cd\u4f5c\u7684\u66f4\u6539\u5230Git\u5386\u53f2\u8bb0\u5f55\u4e2d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git commit -m \"\u5220\u9664\u672c\u5730\u4ed3\u5e93\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. \u5220\u9664Git\u5386\u53f2\u8bb0\u5f55\uff08\u53ef\u9009\uff09<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c\u4f60\u5e0c\u671b\u4eceGit\u5386\u53f2\u8bb0\u5f55\u4e2d\u5b8c\u5168\u5220\u9664\u4ed3\u5e93\u7684\u6240\u6709\u75d5\u8ff9\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch &lt;\u672c\u5730\u4ed3\u5e93\u76ee\u5f55&gt;' HEAD<\/code><\/pre>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u547d\u4ee4\uff0c\u614e\u91cd\u4f7f\u7528\u3002\u5b83\u5c06\u6c38\u4e45\u5220\u9664\u4ed3\u5e93\u7684\u6240\u6709\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. \u6e05\u7406\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6<\/strong><\/h3>\n\n\n\n<p>\u5220\u9664\u672c\u5730\u4ed3\u5e93\u76ee\u5f55\u540e\uff0c\u8fd8\u9700\u8981\u624b\u52a8\u5220\u9664\u4e0d\u518d\u9700\u8981\u7684\u6587\u4ef6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. \u5b8c\u6210\u5220\u9664<\/strong><\/h3>\n\n\n\n<p>\u4ed3\u5e93\u7684\u5220\u9664\u64cd\u4f5c\u5df2\u7ecf\u5b8c\u6210\u3002\u786e\u4fdd\u5907\u4efd\u4e86\u91cd\u8981\u6570\u636e\uff0c\u5e76\u4e14\u4e0d\u518d\u9700\u8981\u8be5\u4ed3\u5e93\u7684\u4efb\u4f55\u5185\u5bb9\u3002<\/p>\n\n\n\n<p><strong>\u5e38\u89c1\u95ee\u7b54\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u5220\u9664\u672c\u5730\u4ed3\u5e93\u540e\uff0cGit\u5386\u53f2\u8bb0\u5f55\u662f\u5426\u4f1a\u88ab\u5b8c\u5168\u6e05\u9664\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1a\u4e0d\u4e00\u5b9a\u3002\u5220\u9664\u672c\u5730\u4ed3\u5e93\u540e\uff0cGit\u5386\u53f2\u8bb0\u5f55\u53ef\u80fd\u4ecd\u7136\u5b58\u5728\uff0c\u7279\u522b\u662f\u5982\u679c\u6ca1\u6709\u6267\u884cGit\u5386\u53f2\u8bb0\u5f55\u6e05\u7406\u7684\u64cd\u4f5c\u3002\u5982\u679c\u4f60\u5e0c\u671b\u4eceGit\u5386\u53f2\u8bb0\u5f55\u4e2d\u5b8c\u5168\u5220\u9664\u4ed3\u5e93\u7684\u6240\u6709\u75d5\u8ff9\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Git\u547d\u4ee4\u6765\u6e05\u7406\u5386\u53f2\u8bb0\u5f55\u3002\u4f46\u8bf7\u6ce8\u610f\uff0c\u8fd9\u662f\u4e00\u4e2a\u6f5c\u5728\u5371\u9669\u7684\u64cd\u4f5c\uff0c\u5e94\u8be5\u8c28\u614e\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4f1a\u6c38\u4e45\u5220\u9664\u5386\u53f2\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u662f\u5426\u53ef\u4ee5\u6062\u590d\u5df2\u5220\u9664\u7684Git\u4ed3\u5e93\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1a\u4e00\u65e6\u5220\u9664\u4e86Git\u4ed3\u5e93\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u662f\u4e0d\u53ef\u6062\u590d\u7684\u3002\u56e0\u6b64\uff0c\u5728\u6267\u884c\u5220\u9664\u64cd\u4f5c\u4e4b\u524d\uff0c\u52a1\u5fc5\u786e\u4fdd\u4f60\u4e0d\u518d\u9700\u8981\u8be5\u4ed3\u5e93\u4e2d\u7684\u4efb\u4f55\u5185\u5bb9\uff0c\u5e76\u5907\u4efd\u4e86\u91cd\u8981\u6570\u636e\u3002\u5982\u679c\u4ec5\u5220\u9664\u4e86\u672c\u5730\u4ed3\u5e93\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93\u6765\u91cd\u65b0\u83b7\u53d6\u4ee3\u7801\u3002\u5982\u679c\u5220\u9664\u4e86\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u53ea\u80fd\u4f9d\u8d56\u5907\u4efd\u6216\u534f\u4f5c\u4f19\u4f34\u7684\u590d\u5236\u6765\u6062\u590d\u4e22\u5931\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u6709\u6ca1\u6709\u5b89\u5168\u63aa\u65bd\u6765\u9632\u6b62\u610f\u5916\u5220\u9664Git\u4ed3\u5e93\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1a\u662f\u7684\uff0c\u4e3a\u9632\u6b62\u610f\u5916\u5220\u9664\uff0c\u901a\u5e38\u5728\u5220\u9664\u64cd\u4f5c\u4e4b\u524d\u4f1a\u8981\u6c42\u7528\u6237\u8fdb\u884c\u6700\u540e\u7684\u786e\u8ba4\u3002\u8fd9\u53ef\u80fd\u6d89\u53ca\u8f93\u5165\u5bc6\u7801\u6216\u6267\u884c\u5176\u4ed6\u8eab\u4efd\u9a8c\u8bc1\u6b65\u9aa4\u3002\u6b64\u5916\uff0c\u5728\u5220\u9664Git\u4ed3\u5e93\u4e4b\u524d\uff0c\u5efa\u8bae\u4ed4\u7ec6\u9605\u8bfb\u5220\u9664\u64cd\u4f5c\u7684\u8b66\u544a\u4fe1\u606f\uff0c\u786e\u4fdd\u4f60\u771f\u7684\u60f3\u8981\u6267\u884c\u5220\u9664\u64cd\u4f5c\u3002\u4fdd\u6301\u8c28\u614e\uff0c\u5c24\u5176\u662f\u5f53\u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\u65f6\uff0c\u56e0\u4e3a\u8fd9\u53ef\u80fd\u4f1a\u5f71\u54cd\u9879\u76ee\u7684\u534f\u4f5c\u4f19\u4f34\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5728Git\u4e2d\u5220\u9664\u4e00\u4e2a\u4ed3\u5e93\u5206\u4e3a\u4e24\u79cd\u60c5\u51b5\uff0c\u5206\u522b\u662f\uff1a\u4e00\u3001\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93\uff1b\u4e8c\u3001\u4ece\u672c\u5730\u4ed3\u5e93\u4e2d\u5220\u9664\u4ed3\u5e93\u3002\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u5220 [&hellip;]","protected":false},"author":4,"featured_media":53535,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[2454,2451,1163],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/53532"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=53532"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/53532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/53535"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=53532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=53532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=53532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}