{"id":1421,"date":"2024-07-26T09:55:44","date_gmt":"2024-07-26T01:55:44","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=1421"},"modified":"2025-10-09T13:54:44","modified_gmt":"2025-10-09T05:54:44","slug":"git-03","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2024\/07\/26\/git-03\/","title":{"rendered":"Git Rebase \u7684\u4e24\u4e2a\u5e94\u7528\u573a\u666f"},"content":{"rendered":"<p>&emsp;&emsp;\u5728\u672c\u7ae0\u4e2d\u6211\u4eec\u5c06\u4ecb\u7ecd\u5e38\u89c1\u7684<code>git rebase<\/code>\u7528\u6cd5\u3002<\/p>\n<h2>\u4e00\u3001\u5408\u5e76commit<\/h2>\n<p>&emsp;&emsp;\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u5982\u4e0b\u7684<code>log<\/code>\uff1a<\/p>\n<pre><code class=\"language-log\">commit 72ff789d5a79cb0e79728bc86355c067b24a5b34 (HEAD -&gt; master)\nAuthor: SwordofMorning &lt;969211735@qq.com&gt;\nDate:   Thu Jul 25 14:53:56 2024 +0800\n\n    rebase_02\n\ncommit 0cd3a6179b7446de5e9f12e4a6cbd85c2553e959\nAuthor: SwordofMorning &lt;969211735@qq.com&gt;\nDate:   Thu Jul 25 14:53:33 2024 +0800\n\n    rebase_01\n\ncommit 3bbb67450967dd8de8f6271f8f8e60119b77c3f4 (origin\/master, origin\/HEAD)\nAuthor: SwordofMorning &lt;969211735@qq.com&gt;\nDate:   Thu Jul 25 11:04:09 2024 +0800\n\n    RV1126 05, Trick 02\n\ncommit 261762b3aeae2e52de8484424079bc3989c8ac44\nAuthor: SwordofMorning &lt;969211735@qq.com&gt;<\/code><\/pre>\n<p>&emsp;&emsp;\u6211\u4eec\u5e0c\u671b\u5408\u5e76\u4e24\u4e2a\u6700\u65b0\u7684\u3001\u672a\u63d0\u4ea4\u7684commit\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-sh\">git rebase -i HEAD~2<\/code><\/pre>\n<p>&emsp;&emsp;\u8fd9\u91cc\u7684\u7f16\u8f91\u5668\u4f7f\u7528vim\uff0c\u5982\u679c\u4f7f\u7528vscode\u5219\u4f1a\u9047\u5230\u795e\u79d8\u529b\u91cf\uff0cgitlens\u63d2\u4ef6\u4f3c\u4e4e\u4e5f\u4e0d\u652f\u6301\u5408\u5e76commit\u8fd9\u79cdrebase\u64cd\u4f5c\u3002\u7f16\u8f91\u5668\u4e2d\u4f1a\u51fa\u73b0\uff1a<\/p>\n<pre><code class=\"language-sh\">pick 0cd3a61 rebase_01\npick 72ff789 rebase_02\n\n# Rebase 3bbb674..72ff789 onto 3bbb674 (2 commands)\n#\n# Commands:\n# p, pick &lt;commit&gt; = use commit\n# r, reword &lt;commit&gt; = use commit, but edit the commit message\n# e, edit &lt;commit&gt; = use commit, but stop for amending\n# s, squash &lt;commit&gt; = use commit, but meld into previous commit\n# f, fixup &lt;commit&gt; = like &quot;squash&quot;, but discard this commit&#039;s log message\n# x, exec &lt;command&gt; = run command (the rest of the line) using shell\n# b, break = stop here (continue rebase later with &#039;git rebase --continue&#039;)\n# d, drop &lt;commit&gt; = remove commit\n# l, label &lt;label&gt; = label current HEAD with a name\n# t, reset &lt;label&gt; = reset HEAD to a label\n# m, merge [-C &lt;commit&gt; | -c &lt;commit&gt;] &lt;label&gt; [# &lt;oneline&gt;]\n# .       create a merge commit using the original merge commit&#039;s\n# .       message (or the oneline, if no original merge commit was\n# .       specified). Use -c &lt;commit&gt; to reword the commit message.\n#\n# These lines can be re-ordered; they are executed from top to bottom.\n#\n# If you remove a line here THAT COMMIT WILL BE LOST.\n#\n# However, if you remove everything, the rebase will be aborted.\n#<\/code><\/pre>\n<p>&emsp;&emsp;\u6211\u4eec\u5c06\u5176\u4e2d\u4fee\u6539\u4e3a\uff1a<\/p>\n<pre><code class=\"language-sh\">pick 0cd3a61 rebase_01\nsquash 72ff789 rebase_02<\/code><\/pre>\n<p><code>pick<\/code>\u8868\u793a\u4fdd\u7559\u5f53\u524dcommit\uff0c<code>squash<\/code>\u8868\u793a\u5c06\u5f53\u524dcommit\u4e0e\u4e0a\u4e00\u4e2acommit\u5408\u5e76\u3002\u4fdd\u5b58\u4e4b\u540e\u5219\u662f\u5408\u5e76\u540e\u7684commit\u4fe1\u606f\uff1a<\/p>\n<pre><code class=\"language-sh\"># This is a combination of 2 commits.\n# This is the 1st commit message:\n\nrebase_01\n\n# This is the commit message #2:\n\nrebase_02\n\n# Please enter the commit message for your changes. Lines starting\n# with &#039;#&#039; will be ignored, and an empty message aborts the commit.\n#\n# Date:      Thu Jul 25 14:53:33 2024 +0800\n#\n# interactive rebase in progress; onto 3bbb674\n# Last commands done (2 commands done):\n#    pick 0cd3a61 rebase_01\n#    squash 72ff789 rebase_02\n# No commands remaining.\n# You are currently rebasing branch &#039;master&#039; on &#039;3bbb674&#039;.\n#\n# Changes to be committed:\n#       new file:   rebase_01.txt\n#       new file:   rebase_02.txt\n#<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e4b\u540e\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u6700\u65b0\u7684\u4e24\u4e2acommit\u5df2\u7ecf\u88ab\u5408\u5e76\u4e86\u3002<\/p>\n<h2>\u4e8c\u3001\u5408\u5e76\u5206\u652f<\/h2>\n<p>&emsp;&emsp;\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u6709\u5982\u4e0b\u7684\u5de5\u4f5c\u6811\uff1a<\/p>\n<pre><code>(master)B -&gt; A \n(dev)D -&gt; C -&gt; B -&gt; A\n          \u2193\n(master)E -&gt; B -&gt; A \n(dev)D -&gt; C -&gt; E -&gt; B -&gt; A<\/code><\/pre>\n<p>&emsp;&emsp;\u6211\u4eec\u5728<code>(dev)B -&gt; A<\/code>\u4e0a\u63d0\u4ea4\u4e86<code>D -&gt; C -&gt; B<\/code>\uff1b\u53e6\u4e00\u4e2a\u4eba\u5728<code>(master)B -&gt; A<\/code>\u4e0a\u63d0\u4ea4\u4e86<code>E -&gt; B<\/code>\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528<code>rebase<\/code>\u6765\u5408\u5e76\u7684\u8bdd\uff0c\u5c06\u4f1a\u4ea7\u751f<code>D -&gt; C -&gt; E -&gt; B<\/code>\u7684\u7ebf\u6027\u63d0\u4ea4\u8bb0\u5f55\uff0c\u800c\u4e0d\u4f1a\u6709merge\u4e00\u6837\u7684\u4ea4\u53c9\u3002\u4e0b\u9762\u901a\u8fc7\u5177\u4f53\u7684\u4f8b\u5b50\u6765\u770b\u4e00\u4e0b\u3002<\/p>\n<p>&emsp;&emsp;\u4e0b\u9762\u6211\u4eec\u5728<code>master<\/code>\u4e0a\u6709\u4e00\u6761\u65b0\u7684commit\uff0c\u5728dev\u4e0a\u6709\u4e24\u6761commit\uff0c\u6211\u4eec\u5e0c\u671b\u5c06\u5176\u5408\u5e76\u3002<\/p>\n<figure style=\"width: 1545px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/01.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"1545\" height=\"638\" alt=\"\u56fe1\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/01.png\" width=\"1545\" height=\"638\" alt=\"\u56fe1\" class=\"size-full\" \/><\/noscript> \u56fe1\uff1amaster\u4e0a\u7684\u4fee\u6539<\/figcaption><\/figure>\n<figure style=\"width: 1530px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/02.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"1530\" height=\"628\" alt=\"\u56fe2\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/02.png\" width=\"1530\" height=\"628\" alt=\"\u56fe2\" class=\"size-full\" \/><\/noscript> \u56fe2\uff1adev\u4e0a\u7684\u4fee\u6539<\/figcaption><\/figure>\n<figure style=\"width: 1503px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/03.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"1503\" height=\"675\" alt=\"\u56fe3\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/03.png\" width=\"1503\" height=\"675\" alt=\"\u56fe3\" class=\"size-full\" \/><\/noscript> \u56fe3\uff1adev 02\u4e0a\u7684\u4fee\u6539<\/figcaption><\/figure>\n<p>\u6b64\u65f6\u6211\u4eec\u5207\u6362\u5230<code>dev<\/code>\u5206\u652f\uff0c\u4f7f\u7528\uff1a<\/p>\n<pre><code class=\"language-sh\"># \u5207\u6362\u5206\u652f\ngit checkout dev\n# \u5f00\u59cb\u5408\u5e76\ngit rebase master<\/code><\/pre>\n<p>\u6b64\u65f6\u6211\u4eec\u9700\u8981\u5904\u7406\u51b2\u7a81\uff0c\u5728\u5904\u7406\u5b8c\u6210\u4e4b\u540e\u4f7f\u7528<code>git status<\/code>\u6765\u786e\u8ba4\u662f\u5426\u5df2\u7ecf\u6ca1\u6709\u9700\u8981\u7ee7\u7eed\u7684\u4e8b\u9879\uff1a<\/p>\n<pre><code class=\"language-sh\">git status\ninteractive rebase in progress; onto 3369821\nLast commands done (2 commands done):\n   pick 6bf296f dev\n   pick 68ec855 dev 02\nNo commands remaining.\nYou are currently rebasing branch &#039;dev&#039; on &#039;3369821&#039;.\n  (all conflicts fixed: run &quot;git rebase --continue&quot;)\n\nChanges to be committed:\n  (use &quot;git restore --staged &lt;file&gt;...&quot; to unstage)\n        modified:   Computer Science\/Academic\/Git\/03.md\n\n        modified:   Computer Science\/Academic\/Git\/03.md<\/code><\/pre>\n<p>\u6b64\u65f6\u6211\u4eec\u8fd8\u9700\u8981\u7ee7\u7eed\uff1a<code>git rebase --continue<\/code>\uff0c\u76f4\u5230<code>git status<\/code>\u63d0\u793a\u6211\u4eec\uff1a<\/p>\n<pre><code class=\"language-sh\">nothing to commit, working tree clean<\/code><\/pre>\n<p>&emsp;&emsp;\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u6b64\u65f6\u7684\u5de5\u4f5c\u6811\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<figure style=\"width: 544px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/04.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"544\" height=\"339\" alt=\"\u56fe4\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/04.png\" width=\"544\" height=\"339\" alt=\"\u56fe4\" class=\"size-full\" \/><\/noscript> \u56fe4\uff1arebase\u4e4b\u540e\u7684\u5de5\u4f5c\u6811<\/figcaption><\/figure>\n<p>&emsp;&emsp;\u6211\u4eec\u5207\u6362\u5230<code>master<\/code>\u4e0a\uff0c\u5728<code>git merge dev<\/code>\u4e4b\u540e\u5220\u9664<code>dev<\/code>\u5206\u652f\uff0c\u5f97\u5230\uff1a<\/p>\n<figure style=\"width: 878px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\"   class=\"lazyload\" data-src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/05.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  width=\"878\" height=\"818\" alt=\"\u56fe5\" class=\"size-full\" \/ ><figcaption class=\"wp-caption-text\"><noscript><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cdn.swordofmorning.com\/SwordofMorning\/Article%20Images\/Git\/03\/05.png\" width=\"878\" height=\"818\" alt=\"\u56fe5\" class=\"size-full\" \/><\/noscript> \u56fe5\uff1a\u6700\u7ec8\u5f97\u5230\u7684\u5206\u652f<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;\u5728\u672c\u7ae0\u4e2d\u6211\u4eec\u5c06\u4ecb\u7ecd\u5e38\u89c1\u7684git rebase\u7528\u6cd5\u3002 \u4e00\u3001\u5408\u5e76commit &emsp;&emsp;\u5047\u8bbe\u6211\u4eec &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1421"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=1421"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1421\/revisions"}],"predecessor-version":[{"id":1422,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1421\/revisions\/1422"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=1421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=1421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=1421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}