{"id":8740,"date":"2017-06-18T11:00:20","date_gmt":"2017-06-18T03:00:20","guid":{"rendered":"https:\/\/ihower.tw\/blog\/?p=8740"},"modified":"2025-07-04T07:31:47","modified_gmt":"2025-07-03T23:31:47","slug":"git-worktree","status":"publish","type":"post","link":"https:\/\/ihower.tw\/blog\/8740-git-worktree","title":{"rendered":"Git worktree: \u540c\u6642\u958b\u591a\u500b\u5de5\u4f5c\u76ee\u9304"},"content":{"rendered":"<p>Git \u7684 <a href=\"https:\/\/git-scm.com\/docs\/git-worktree\">worktree<\/a> \u662f Git 2.5 \u65b0\u589e\u7684\u529f\u80fd\uff0c\u6709\u9ede\u76f8\u898b\u6068\u665a\u554a\u3002<\/p>\n<p>\u6709\u5728\u7528 Git \u7684\u90fd\u77e5\u9053\u5982\u679c\u5de5\u4f5c\u76ee\u9304(working tree)\u4fee\u6539\u5230\u4e00\u534a\u7684\u8a71\uff0c\u662f\u4e0d\u80fd\u96a8\u4fbf\u5207\u63db branch \u7684\u3002\u89e3\u6c7a\u65b9\u5f0f\u662f\u8981\u9ebb\u662f git stash \u5148\u66ab\u5b58\u8d77\u4f86\uff0c\u4e0d\u7136\u5c31\u662f\u5148\u66ab\u6642 commit \u7b49\u6703\u518d reset \u56de\u4f86\u3002\u9019\u90fd\u9084\u597d\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u9084\u662f\u6703\u78b0\u5230\u4e00\u4e9b\u9700\u8981\u540c\u6642\u8655\u7406\u4e0d\u540c branch \u7684\u60c5\u6cc1\uff0c\u4f8b\u5982\u60f3\u8981\u540c\u6642\u4fee\u6539\u6216\u5c0d\u7167\u4e0d\u540c branch\uff0c\u6216\u662f\u4e00\u908a\u8dd1\u6e2c\u8a66\u4e00\u908a\u7e7c\u7e8c\u5bebcode\uff0c\u751a\u81f3\u662f\u60f3\u540c\u6642\u958b\u767c\u6e2c\u8a66\u4e0d\u540c branch \u7b49\u7b49\u3002\u9019\u6642\u5019\u5c31\u5f97\u53e6\u5916 clone \u4e00\u500b\u76ee\u9304\uff0c\u4f46\u9019\u5c31\u662f\u9ebb\u7169\u7684\u958b\u59cb\uff0c\u4e0d\u540c\u7684 repo \u76ee\u9304\u8981\u600e\u9ebc\u540c\u6b65\u6700\u65b0\u7684\u4fee\u6539? \u91cd\u65b0\u8907\u88fd\u76ee\u9304? \u5148 git push \u518d pull \u4e00\u6b21? \u7e3d\u4e4b\u5c31\u662f\u6709\u9ede\u7e5e\u554a\u3002<\/p>\n<p><code>git worktree<\/code> \u9019\u500b\u795e\u5947\u7684\u6307\u4ee4\u53ef\u4ee5\u5275\u9020\u51fa\u53e6\u4e00\u500b\u5de5\u4f5c\u76ee\u9304\uff0c\u4f8b\u5982\uff1a<\/p>\n<div>\n<pre><code class=\"language-none\">$ git worktree add -b hotfix ..\/hotfix master\nPreparing ..\/hotfix (identifier hotfix)\nHEAD is now at 46d363dc XXX\n<\/code><\/pre>\n<\/div>\n<p>\u5982\u6b64\u5c31\u6703\u5728\u4e0a\u4e00\u5c64\u65b0\u5efa\u7acb\u4e00\u500b <code>hotfix<\/code> \u76ee\u9304\uff0c\u4e26\u65b0\u5efa\u4e00\u500b\u5206\u652f <code>hotfix<\/code>\u3002\u9019\u7a2e\u5de5\u4f5c\u76ee\u9304\u53eb\u505a linked working tree\u3002<\/p>\n<p><code>cd ..\/hotfix<\/code> \u5c31\u662f\u4e00\u500b\u4e7e\u6de8\u5f9e master \u5206\u51fa\u4f86\u7684 hotfix \u5206\u652f\uff0c\u53ef\u4ee5\u5728\u9019\u908a\u505a\u4e8b\u3002\u6700\u5f8c commit \u5b8c\u4e8b\u4e4b\u5f8c\uff0c\u76f4\u63a5 <code>rm -rf<\/code> \u780d\u6389\u9019\u500b hotfix \u76ee\u9304(\u653e\u5fc3\uff0c\u6771\u897f\u5df2\u7d93\u9032 branch\uff0c\u9019\u53ef\u4ee5\u780d\u6389\u4e86)\uff0c\u63a5\u8457 <code>git worktree prune<\/code> \u5c31\u6703\u6e05\u9664 linked working tree \u8a18\u9304\u4e86\u3002\u4e0d\u6e05\u9664\u4e5f\u6c92\u95dc\u4fc2\uff0c\u4e09\u500b\u6708\u5f8c\u4e5f\u6703\u81ea\u52d5\u6e05\u6389\u3002<\/p>\n<blockquote><p>\n\u4e0d\u904e\u5982\u679c\u4f60\u628a linked working tree \u653e\u5728\u6703\u88ab\u79fb\u9664\u7684\u88dd\u7f6e\u4e0a\uff0c\u4f8b\u5982\u5916\u63a5\u786c\u789f\u4e0a\uff0c\u9019\u6a23\u53ef\u80fd\u6703\u4e0d\u5c0f\u5fc3\u88ab Git \u6e05\u6389\u3002\u9019\u6642\u5019\u9700\u8981\u7528 git worktree lock \u6307\u4ee4\u3002\n<\/p><\/blockquote>\n<p>\u6700\u5f8c\uff0c<code>git worktree list<\/code> \u5247\u6703\u5217\u51fa\u76ee\u524d\u6240\u6709\u7684\u5de5\u4f5c\u76ee\u9304\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git \u7684 worktree \u662f Git 2.5 \u65b0\u589e\u7684\u529f\u80fd\uff0c\u6709\u9ede\u76f8\u898b\u6068\u665a\u554a\u3002 \u6709\u5728\u7528 Git \u7684\u90fd\u77e5\u9053\u5982\u679c\u5de5 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/ihower.tw\/blog\/8740-git-worktree\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008Git worktree: \u540c\u6642\u958b\u591a\u500b\u5de5\u4f5c\u76ee\u9304\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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[48],"tags":[],"class_list":["post-8740","post","type-post","status-publish","format-standard","hentry","category-git","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q6tG-2gY","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/8740","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=8740"}],"version-history":[{"count":9,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/8740\/revisions"}],"predecessor-version":[{"id":8752,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/posts\/8740\/revisions\/8752"}],"wp:attachment":[{"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/media?parent=8740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/categories?post=8740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ihower.tw\/blog\/wp-json\/wp\/v2\/tags?post=8740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}