{"id":3843,"date":"2010-02-15T15:12:39","date_gmt":"2010-02-15T07:12:39","guid":{"rendered":"http:\/\/ihower.tw\/blog\/?p=3843"},"modified":"2024-04-21T18:50:20","modified_gmt":"2024-04-21T10:50:20","slug":"git-pull-rebase","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/3843-git-pull-rebase","title":{"rendered":"\u4f7f\u7528 git rebase \u907f\u514d\u7121\u8b02\u7684 merge"},"content":{"rendered":"<blockquote><p>\u95dc\u65bc Git \u53ef\u4ee5\u53c3\u8003\u6211\u7684 <a href=\"https:\/\/ihower.tw\/git\/\">Git \u7248\u672c\u63a7\u5236<\/a> \u8ab2\u7a0b\u8cc7\u6599<\/p><\/blockquote>\n<blockquote><p>\n  \u53ef\u4ee5\u9032\u4e00\u6b65\u53c3\u8003 <a href=\"https:\/\/ihower.tw\/blog\/archives\/6704\">Git rebase \u548c merge \u5408\u4f75\u64cd\u4f5c\u793a\u7bc4\u9304\u5f71<\/a>\n<\/p><\/blockquote>\n<p>git pull \u9810\u8a2d\u7684\u884c\u70ba\u662f\u5c07\u9060\u7aef\u7684 repo. \u8207\u672c\u5730\u7684 repo. \u5408\u4f75\uff0c\u9019\u4e5f\u662f DVCS \u7684\u521d\u8877\uff0c\u5c07\u5169\u500b branch \u5408\u4f75\u3002\u4f46\u662f\uff0c\u5f88\u591a\u6642\u5019\u6703\u767c\u751f\u4ee5\u4e0b\u9019\u7a2e\u60c5\u5f62\uff1a<\/p>\n<p><a href=\"http:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge.jpg\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3844\" data-permalink=\"https:\/\/ihower.tw\/blog\/3843-git-pull-rebase\/git-merge\" data-orig-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge.jpg\" data-orig-size=\"211,376\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"git-merge\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge-168x300.jpg\" data-large-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge.jpg\" class=\"alignnone size-full wp-image-3844\" title=\"git-merge\" src=\"http:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge.jpg\" alt=\"\" width=\"211\" height=\"376\" srcset=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge.jpg 211w, https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2010\/02\/git-merge-168x300.jpg 168w\" sizes=\"auto, (max-width: 211px) 100vw, 211px\" \/><\/a><\/p>\n<p>\u9019\u662f\u56e0\u70ba\uff0c\u6211\u5011\u5718\u968a\u7684\u958b\u767c\u6a21\u5f0f\u662f\u672c\u5730\u7684 branch \u548c\u9060\u7aef\u7684 branch \u6703\u540c\u6b65\u5730\u975e\u5e38\u983b\u7e41(\u901a\u5e38\u5c31\u662f\u540c\u540d\u7a31\u7684 branch\uff0c\u4f8b\u5982 master)\uff0c\u9019\u5169\u500b branch \u5e7e\u4e4e\u662f\u5b8c\u5168\u540c\u6b65\u3002\u9019\u6642\u5019\u5c31\u6703\u767c\u73fe\u9019\u4e9b merge \u52d5\u4f5c\u5176\u5be6\u6c92\u6709\u5fc5\u8981\uff0c\u6703\u9020\u6210\u7dda\u5716\u7121\u8b02\u7684\u8907\u96dc\u3002\u9019\u6642\u5019\uff0c\u6703\u63a8\u85a6\u4f7f\u7528\u4ee5\u4e0b\u9019\u500b\u6307\u4ee4\uff1a<\/p>\n<pre> git pull --rebase<\/pre>\n<p>\u52a0\u4e0a rebase \u7684\u610f\u601d\u662f\uff0c\u6703\u5148 1.\u628a\u672c\u5730 repo. \u5f9e\u4e0a\u6b21 pull \u4e4b\u5f8c\u7684\u8b8a\u66f4\u66ab\u5b58\u8d77\u4f86 2. \u56de\u5fa9\u5230\u4e0a\u6b21 pull \u6642\u7684\u60c5\u6cc1 3. \u5957\u7528\u9060\u7aef\u7684\u8b8a\u66f4 4. \u6700\u5f8c\u518d\u5957\u7528\u525b\u66ab\u5b58\u4e0b\u4f86\u7684\u672c\u5730\u8b8a\u66f4\u3002\u8a73\u7d30\u8aaa\u660e\u53ef\u4ee5\u53c3\u8003 <a href=\"http:\/\/www.gitready.com\/advanced\/2009\/02\/11\/pull-with-rebase.html\">pull with rebase<\/a>\u3002<\/p>\n<p>\u756b\u5716\u8aaa\u660e\u4e00\u4e0b\u597d\u4e86:<\/p>\n<p>\u5047\u8a2d\u5408\u4f75\u524d\u662f\u9019\u6a23\uff1a<\/p>\n<pre>      D---E master\n     \/\nA---B---C---F origin\/master\n<\/pre>\n<p>\u4f7f\u7528 merge \u5408\u4f75\u5f8c\uff1a<\/p>\n<pre>      D--------E  \n     \/          \\\nA---B---C---F----G   master, origin\/master\n<\/pre>\n<p>\u5982\u679c\u662f rebase \u7684\u65b9\u5f0f\uff0c\u5c31\u4e0d\u6703\u6709 G \u5408\u4f75\u9ede\uff1a<\/p>\n<pre>A---B---C---F---D'---E'   master, origin\/master\n<\/pre>\n<p>\u6ce8\u610f\u5230\uff0c\u5176\u4e2d D&#8217;, E&#8217; \u7684 commit SHA \u5e8f\u865f\u8ddf\u672c\u4f86 D, E \u662f\u4e0d\u540c\u7684\uff0c\u56e0\u70ba\u7b97\u662f\u780d\u6389\u91cd\u65b0 commit \u4e86\u3002<\/p>\n<p>\u4f60\u6703\u554f\u8aaa\uff0c\u6709 conflict \u600e\u9ebc\u8fa6? rebase \u8ddf merge \u985e\u4f3c\uff0c\u51fa\u73fe conflict \u4e00\u6703\u66ab\u505c rebase \u52d5\u4f5c\uff0c\u9700\u8981\u4f60\u624b\u52d5\u4fee\u5fa9\u5f8c\uff0c\u7136\u5f8c\u624d\u53ef\u4ee5\u7e7c\u7e8c\u52d5\u4f5c\u3002\u9019\u4e5f\u662f rebase \u6bd4 merge \u8907\u96dc\u4e00\u9ede\u7684\u5730\u65b9\uff1amerge \u5982\u679c\u767c\u751f conflict\uff0c\u4f60\u53ea\u9700\u8981\u89e3\u6c7a\u885d\u7a81\u4e00\u6b21\uff0c\u7136\u5f8c commit \u51fa\u53bb\u5c31\u5b8c\u6210\u4e86\u3002\u800c rebase \u7684 conflict \u53ef\u80fd\u6703\u767c\u751f\u5728\u4e0a\u8ff0\u6b65\u9a5f 4 \u7684\u6bcf\u4e00\u6b21\u91cd\u65b0\u5957\u7528\u4e0a\uff0c\u6240\u4ee5\u53ef\u80fd\u9700\u8981\u89e3\u6c7a\u885d\u7a81\u597d\u5e7e\u6b21 (rebase \u6642\u6240\u8b02\u7684\u89e3\u6c7a\u885d\u7a81\uff0c\u5176\u5be6\u662f\u76f4\u63a5\u4fee\u6539\u4f60\u4e4b\u524d\u7684\u8b8a\u66f4\u5167\u5bb9\uff0c\u6240\u4ee5\u4e0a\u5716\u4e2d\u8b8a\u6210 D&#8217; \u8ddf E&#8217; )\u3002<\/p>\n<p>\u6240\u4ee5\u5230\u5e95\u4f55\u6642\u8a72\u7528 merge? \u4f55\u6642\u53ef\u4ee5 rebase? \u4f60\u53ef\u80fd\u5fc3\u7406\u4e5f\u6709\u7b54\u6848\u4e86\uff0c\u5982\u679c\u4f60\u4fee\u6539\u6bd4\u8f03\u591a\uff0c\u9810\u671f\u6703\u6709\u8f03\u591a\u7684 conflict\uff0c\u5efa\u8b70\u7528 merge (\u4e0d\u904e\uff0c\u5982\u679c\u662f\u591a\u6b21\u5927\u7bc4\u570d\u7684\u4e3b\u984c\u5f0f\u4fee\u6539\uff0c\u90a3\u662f\u4e0d\u662f\u61c9\u8a72\u4e00\u958b\u59cb\u5c31\u591a\u958b\u4e00\u500b branch \u4f86\u505a\u5462?)\u3002\u5982\u679c\u4fee\u6539\u7bc4\u570d\u8f03\u5c0f\uff0c\u4e0d\u592a\u9810\u671f\u6709 conflict\uff0c\u5247\u5efa\u8b70\u53ef\u4ee5\u52a0\u4e0a rebase \u53c3\u6578\u3002<\/p>\n<p>\u5982\u679c\u60f3\u8981\u628a rebase \u7576\u505a git pull \u7684\u9810\u8a2d\u503c\uff0c\u53ef\u4ee5\u5728\u5c08\u6848\u7684 .git\/config \u52a0\u4e0a<\/p>\n<pre><code>\n[branch \"master\"]\n  remote = origin\n  merge = refs\/heads\/master\n  rebase = true\n<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u52a0\u5230 ~\/.gitconfig \u8b93\u6240\u6709\u7684 tracked branches \u90fd\u81ea\u52d5\u5957\u7528\u9019\u500b\u8a2d\u5b9a\uff1a<\/p>\n<pre><code>\n[branch]  \n  autosetuprebase = always\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95dc\u65bc Git \u53ef\u4ee5\u53c3\u8003\u6211\u7684 Git \u7248\u672c\u63a7\u5236 \u8ab2\u7a0b\u8cc7\u6599 \u53ef\u4ee5\u9032\u4e00\u6b65\u53c3\u8003 Git rebase \u548c merge  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/3843-git-pull-rebase\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u4f7f\u7528 git rebase \u907f\u514d\u7121\u8b02\u7684 merge\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[48],"tags":[],"class_list":["post-3843","post","type-post","status-publish","format-standard","hentry","category-git","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-ZZ","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/3843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/comments?post=3843"}],"version-history":[{"count":36,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/3843\/revisions"}],"predecessor-version":[{"id":12076,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/3843\/revisions\/12076"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=3843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=3843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=3843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}