{"id":5691,"date":"2011-05-16T12:56:02","date_gmt":"2011-05-16T04:56:02","guid":{"rendered":"http:\/\/ihower.tw\/blog\/?p=5691"},"modified":"2025-07-04T08:37:38","modified_gmt":"2025-07-04T00:37:38","slug":"no-parent-git-branch","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/5691-no-parent-git-branch","title":{"rendered":"\u5982\u4f55\u5efa\u7acb\u4e00\u500b\u6c92\u6709 Parent \u7684\u7368\u7acb Git branch"},"content":{"rendered":"<p>\u9996\u5148\uff0c\u4f60\u4e00\u5b9a\u6703\u554f\u5e79\u561b\u9019\u6a23\u505a\u3002\u6211\u5728\u4e0a\u56de\u7684<a href=\"\/blog\/archives\/5391\">Git \u6f14\u8b1b<\/a>\u4e2d\u6709\u63d0\u5230\uff1a\u5728 Git\uff0c\u4f60\u53ef\u4ee5\u5efa\u7acb\u6beb\u4e0d\u76f8\u95dc\u7684\u5206\u652f\uff0c\u7528\u4f86\u4fdd\u5b58\u5176\u4ed6\u8cc7\u8a0a\uff0c\u5c31\u50cf\u76ee\u9304\u4e00\u6a23\u3002\u9019 Branch \u7684\u7528\u9014\u4e0d\u6703\u88ab Merge \u9032\u958b\u767c\u4e3b\u5e79\uff0c\u662f\u5b8c\u5168\u7368\u7acb\u7684\u3002<\/p>\n<p>\u5be6\u52d9\u4e0a\u7684\u4e00\u500b\u61c9\u7528\uff0c\u5c31\u662f Github \u63d0\u4f9b\u7684 <a href=\"http:\/\/pages.github.com\/\">Github Pages<\/a> \u529f\u80fd\uff0c\u53ea\u8981\u4f60\u5728\u5c08\u6848\u4e0b\u958b\u4e00\u500b branch \u53eb\u505a gh-pages\uff0c\u90a3\u9019\u500b branch \u7684\u5167\u5bb9\u5c31\u6703\u8b8a\u6210\u975c\u614b\u7db2\u9801\u3002\u6211\u4e4b\u524d\u7684\u4f5c\u6cd5\u662f\u5148\u5206\u652f\u51fa\u4f86\uff0c\u7136\u5f8c\u518d commit \u4e00\u6b21\u780d\u6389\u6240\u6709\u6a94\u6848\u3002\u96d6\u7136\u7d50\u679c\u662fok\u53ef\u4ee5\u7528\u5566\uff0c\u4f46\u662f\u7e3d\u89ba\u5f97 gh-pages \u9019 branch \u6709 parent \u5c31\u662f\u610f\u601d\u4e0d\u5c0d\u52c1\uff0c\u5b83\u662f\u5b8c\u5168\u7368\u7acb\u65bc\u4e3b\u5e79\u7684\uff0c\u4e0d\u61c9\u8a72\u6709 parent \u8cc7\u8a0a\u3002<\/p>\n<p>\u525b\u7a81\u7136\u60f3\u5230\u9019\u500b\u554f\u984c\u53ef\u4ee5 google \u770b\u770b(<a href=\"http:\/\/pages.github.com\/\">Github Pages<\/a>\u4e0a\u5176\u5be6\u4e5f\u6709\u5beb XD)\uff0c\u9084\u771f\u7684\u6709\uff1a<\/p>\n<h3>\u65b9\u6cd5\u4e00 (<a href=\"http:\/\/madduck.net\/blog\/2007.07.11:creating-a-git-branch-without-ancestry\/\">source<\/a>)<\/h3>\n<p>\u56e0\u70ba git branch \u9810\u8a2d\u662f\u5f9e HEAD \u5206\u652f\uff0c\u6240\u4ee5\u53ef\u4ee5\u9019\u6a23 Hack HEAD\uff1a<\/p>\n<pre>\necho ref: refs\/heads\/newbranch > .git\/HEAD\ngit rm -rf .   # \u780d\u6389\u6240\u6709\u6a94\u6848\u91cd\u4f86\n.....   # \u52a0\u65b0\u6a94\u6848\ngit add .\ngit commit -m 'create new branch'\n<\/pre>\n<h3>\u65b9\u6cd5\u4e8c(<a href=\"https:\/\/git.wiki.kernel.org\/index.php\/GitTips#How_to_create_a_new_branch_that_has_no_ancestor\">source<\/a>)<\/h3>\n<p>Git 1.7.2 \u4e4b\u5f8c\u7248\u672c\u6709\u652f\u63f4 &#8211;orphan \u53c3\u6578\uff1a<\/p>\n<pre>\ngit checkout --orphan newbranch\ngit rm -rf .    # \u780d\u6389\u6240\u6709\u6a94\u6848\u91cd\u4f86\n...  # \u52a0\u65b0\u6a94\u6848\ngit add .\ngit commit -m 'create new branch'\n<\/pre>\n<h3>\u65b9\u6cd5\u4e09(<a href=\"http:\/\/pages.github.com\/\">source<\/a>)<\/h3>\n<pre>\ngit symbolic-ref HEAD refs\/heads\/newbranch\nrm .git\/index\ngit clean -fdx\n...  # \u52a0\u65b0\u6a94\u6848\ngit add .\ngit commit -m 'create new branch'\n<\/pre>\n<p>\u7d50\u679c\u5c31\u50cf\u662f\u9019\u6a23\uff0cmaster \u8ddf newbranch \u7684\u7bc0\u9ede\u5b8c\u5168\u662f\u5206\u958b\u7684\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5698\" data-permalink=\"https:\/\/ihower.tw\/blog\/5691-no-parent-git-branch\/gitx-no-parent-branch\" data-orig-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch.png\" data-orig-size=\"358,211\" 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=\"GitX-no-parent-branch\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch-300x176.png\" data-large-file=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch.png\" src=\"http:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch.png\" alt=\"\" title=\"GitX-no-parent-branch\" width=\"358\" height=\"211\" class=\"alignnone size-full wp-image-5698\" srcset=\"https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch.png 358w, https:\/\/ihower.tw\/blog\/wp-content\/uploads\/2011\/05\/GitX-no-parent-branch-300x176.png 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u4f60\u4e00\u5b9a\u6703\u554f\u5e79\u561b\u9019\u6a23\u505a\u3002\u6211\u5728\u4e0a\u56de\u7684Git \u6f14\u8b1b\u4e2d\u6709\u63d0\u5230\uff1a\u5728 Git\uff0c\u4f60\u53ef\u4ee5\u5efa\u7acb\u6beb\u4e0d\u76f8\u95dc\u7684\u5206\u652f\uff0c\u7528\u4f86\u4fdd\u5b58\u5176\u4ed6 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/5691-no-parent-git-branch\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u5982\u4f55\u5efa\u7acb\u4e00\u500b\u6c92\u6709 Parent \u7684\u7368\u7acb Git branch\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-5691","post","type-post","status-publish","format-standard","hentry","category-git","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-1tN","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/5691","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=5691"}],"version-history":[{"count":20,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/5691\/revisions"}],"predecessor-version":[{"id":12903,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/5691\/revisions\/12903"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=5691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=5691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=5691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}