{"id":21523,"date":"2024-11-19T11:35:38","date_gmt":"2024-11-19T03:35:38","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21523\/"},"modified":"2024-11-19T11:35:38","modified_gmt":"2024-11-19T03:35:38","slug":"git-rebase%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21523\/","title":{"rendered":"git rebase\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  git rebase \u7528\u4e8e\u91cd\u65b0\u5e94\u7528\u63d0\u4ea4\u5230\u65b0\u57fa\u51c6\uff0c\u4ee5\u6e05\u7406\u5386\u53f2\u6216\u91cd\u65b0\u5b9a\u4f4d\u5206\u652f\u3002\u4f7f\u7528\u65b9\u6cd5\uff1a\u521b\u5efa\u76ee\u6807\u5206\u652f\u9009\u62e9\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u6267\u884c git rebase \u547d\u4ee4\uff0c\u6307\u5b9a\u76ee\u6807\u5206\u652f\u548c\u63d0\u4ea4\u8303\u56f4\u89e3\u51b3\u51b2\u7a81\u7ee7\u7eed\u91cd\u65b0\u5e94\u7528\u5269\u4f59\u7684\u63d0\u4ea4\u9a8c\u8bc1\u66f4\u6539\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053023123567938.jpg\" class=\"aligncenter\" title=\"git rebase\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"git rebase\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528  rebase<\/strong><\/p>\n<p><strong>\u4ec0\u4e48\u662f git rebase\uff1f<\/strong><\/p>\n<p>git rebase \u662f\u4e00\u4e2a Git \u547d\u4ee4\uff0c\u7528\u4e8e\u91cd\u65b0\u5e94\u7528\u6307\u5b9a\u7684\u63d0\u4ea4\u5230\u4e00\u4e2a\u65b0\u7684\u57fa\u51c6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u5c06\u63d0\u4ea4\u4ece\u5f53\u524d\u5206\u652f\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u5206\u652f\u6216\u63d0\u4ea4\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u4f7f\u7528 git rebase\uff1f<\/strong><\/p>\n<ul>\n<li> <strong>\u6e05\u7406\u63d0\u4ea4\u5386\u53f2\uff1a<\/strong>rebase \u53ef\u4ee5\u7528\u6765\u6e05\u7406\u63d0\u4ea4\u5386\u53f2\uff0c\u5408\u5e76\u5c0f\u63d0\u4ea4\u6216\u6d88\u9664\u4e0d\u5fc5\u8981\u7684\u5408\u5e76\u63d0\u4ea4\u3002<\/li>\n<li> <strong>\u91cd\u65b0\u5b9a\u4f4d\u5206\u652f\uff1a<\/strong>rebase \u53ef\u4ee5\u7528\u6765\u5c06\u5206\u652f\u79fb\u52a8\u5230\u65b0\u57fa\u51c6\uff0c\u4f8b\u5982\u5408\u5e76\u8fdc\u7a0b\u5206\u652f\u6216\u89e3\u51b3\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u4f7f\u7528 git rebase<\/strong><\/p>\n<p><strong>1. \u51c6\u5907\u4e00\u4e2a\u76ee\u6807\u5206\u652f<\/strong><br \/>\u5728\u5f00\u59cb rebase \u4e4b\u524d\uff0c\u521b\u5efa\u4e00\u4e2a\u76ee\u6807\u5206\u652f\uff0c\u8be5\u5206\u652f\u5c06\u6210\u4e3a\u63d0\u4ea4\u7684\u65b0\u57fa\u51c6\u3002<\/p>\n<pre>git checkout -b new-base  # \u521b\u5efa new-base \u5206\u652f<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u9009\u62e9\u63d0\u4ea4<\/strong><br \/>\u4f7f\u7528 git log \u547d\u4ee4\u786e\u5b9a\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u3002<\/p>\n<pre>git log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u6267\u884c rebase<\/strong><br \/>\u4f7f\u7528 git rebase \u547d\u4ee4\uff0c\u540e\u8ddf\u76ee\u6807\u5206\u652f\u7684\u540d\u79f0\u548c\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u8303\u56f4\u3002<\/p>\n<pre>git rebase new-base HEAD~3  # \u91cd\u65b0\u5e94\u7528 HEAD \u4e4b\u524d\u7684 3 \u4e2a\u63d0\u4ea4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u89e3\u51b3\u51b2\u7a81<\/strong><br \/>\u5728 rebase \u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u51b2\u7a81\uff0c\u9700\u8981\u624b\u52a8\u89e3\u51b3\u3002\u5728\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u51b2\u7a81\u6587\u4ef6\u5e76\u4fee\u6539\u5b83\u4eec\u4ee5\u89e3\u51b3\u51b2\u7a81\u3002<\/p>\n<pre># \u4fdd\u5b58\u66f4\u6539\u5e76\u9000\u51fa\u7f16\u8f91\u5668\ngit add .\n# \u63d0\u4ea4\u89e3\u51b3\u7684\u51b2\u7a81\ngit commit --amend<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u5b8c\u6210 rebase<\/strong><br \/>\u89e3\u51b3\u6240\u6709\u51b2\u7a81\u540e\uff0c\u4f7f\u7528 git rebase &#8211;continue \u547d\u4ee4\u7ee7\u7eed\u91cd\u65b0\u5e94\u7528\u5269\u4f59\u7684\u63d0\u4ea4\u3002<\/p>\n<pre>git rebase --continue<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u67e5\u770b\u66f4\u6539<\/strong><br \/>\u4f7f\u7528 git log \u547d\u4ee4\u9a8c\u8bc1 rebase \u662f\u5426\u6210\u529f\u3002<\/p>\n<pre>git log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f rebase\u600e\u4e48\u7528\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>git rebase \u7528\u4e8e\u91cd\u65b0\u5e94\u7528\u63d0\u4ea4\u5230\u65b0\u57fa\u51c6\uff0c\u4ee5\u6e05\u7406\u5386\u53f2\u6216\u91cd\u65b0\u5b9a\u4f4d\u5206\u652f\u3002\u4f7f\u7528\u65b9\u6cd5\uff1a\u521b\u5efa\u76ee\u6807\u5206\u652f\u9009\u62e9\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u6267\u884c git rebase \u547d\u4ee4\uff0c\u6307\u5b9a\u76ee\u6807\u5206\u652f\u548c\u63d0\u4ea4\u8303\u56f4\u89e3\u51b3\u51b2\u7a81\u7ee7\u7eed\u91cd\u65b0\u5e94\u7528\u5269\u4f59\u7684\u63d0\u4ea4\u9a8c\u8bc1\u66f4\u6539 \u5982\u4f55\u4f7f\u7528 rebase \u4ec0\u4e48\u662f git rebase\uff1f git rebase \u662f\u4e00\u4e2a Git \u547d\u4ee4\uff0c\u7528\u4e8e\u91cd\u65b0\u5e94\u7528\u6307\u5b9a\u7684\u63d0\u4ea4\u5230\u4e00\u4e2a\u65b0\u7684\u57fa\u51c6\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5b83\u5c06\u63d0\u4ea4\u4ece\u5f53\u524d\u5206\u652f\u79fb\u52a8\u5230\u53e6\u4e00\u4e2a\u5206\u652f\u6216\u63d0\u4ea4\u3002 \u4e3a\u4ec0\u4e48\u4f7f\u7528 git rebase\uff1f \u6e05\u7406\u63d0\u4ea4\u5386\u53f2\uff1arebase \u53ef\u4ee5\u7528\u6765\u6e05\u7406\u63d0\u4ea4\u5386\u53f2\uff0c\u5408\u5e76\u5c0f\u63d0\u4ea4\u6216\u6d88\u9664\u4e0d\u5fc5\u8981\u7684\u5408\u5e76\u63d0\u4ea4\u3002 \u91cd\u65b0\u5b9a\u4f4d\u5206\u652f\uff1arebase \u53ef\u4ee5\u7528\u6765\u5c06\u5206\u652f\u79fb\u52a8\u5230\u65b0\u57fa\u51c6\uff0c\u4f8b\u5982\u5408\u5e76\u8fdc\u7a0b\u5206\u652f\u6216\u89e3\u51b3\u51b2\u7a81\u3002 \u5982\u4f55\u4f7f\u7528 git rebase 1. \u51c6\u5907\u4e00\u4e2a\u76ee\u6807\u5206\u652f\u5728\u5f00\u59cb rebase \u4e4b\u524d\uff0c\u521b\u5efa\u4e00\u4e2a\u76ee\u6807\u5206\u652f\uff0c\u8be5\u5206\u652f\u5c06\u6210\u4e3a\u63d0\u4ea4\u7684\u65b0\u57fa\u51c6\u3002 git checkout -b new-base # \u521b\u5efa new-base \u5206\u652f \u767b\u5f55\u540e\u590d\u5236 2. \u9009\u62e9\u63d0\u4ea4\u4f7f\u7528 git log \u547d\u4ee4\u786e\u5b9a\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u3002 git log \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 3. \u6267\u884c rebase\u4f7f\u7528 git rebase \u547d\u4ee4\uff0c\u540e\u8ddf\u76ee\u6807\u5206\u652f\u7684\u540d\u79f0\u548c\u8981\u91cd\u65b0\u5e94\u7528\u7684\u63d0\u4ea4\u8303\u56f4\u3002 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-21523","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21523","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=21523"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21523\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}