{"id":21566,"date":"2024-11-19T15:45:53","date_gmt":"2024-11-19T07:45:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21566\/"},"modified":"2024-11-19T15:45:53","modified_gmt":"2024-11-19T07:45:53","slug":"git-stash%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e6%8e%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21566\/","title":{"rendered":"git stash\u600e\u4e48\u5220\u9664\u6389"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5220\u9664 git \u6682\u5b58\uff1a1. \u53d6\u6d88\u6682\u5b58\u5355\u4e2a\u6587\u4ef6\uff1a\u4f7f\u7528 git restore &#8211;staged \u547d\u4ee4\u30022. \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6\uff1a\u4f7f\u7528 git reset head \u547d\u4ee4\u30023. \u53d6\u6d88\u6682\u5b58\u90e8\u5206\u66f4\u6539\uff1a\u4f7f\u7528 git restore &#8211;staged &#8211;patch \u547d\u4ee4\u9009\u62e9\u6027\u5730\u6062\u590d\u66f4\u6539\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/31\/2024053100093371689.jpg\" class=\"aligncenter\" title=\"git stash\u600e\u4e48\u5220\u9664\u6389\u63d2\u56fe\" alt=\"git stash\u600e\u4e48\u5220\u9664\u6389\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 Git \u6682\u5b58\uff1f<\/strong><\/p>\n<p>Git \u6682\u5b58\u662f\u4e00\u79cd\u6682\u65f6\u7684\u5b58\u50a8\u533a\u57df\uff0c\u7528\u4e8e\u5b58\u50a8\u6682\u672a\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u7684\u66f4\u6539\u3002\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5220\u9664\u6682\u5b58\u4ee5\u6e05\u7406\u5de5\u4f5c\u533a\u6216\u89e3\u51b3\u51b2\u7a81\u3002<\/p>\n<p>\u8981\u5220\u9664 Git \u6682\u5b58\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<p><strong>1. \u53d6\u6d88\u6682\u5b58\u5355\u4e2a\u6587\u4ef6\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528  restore &#8211;staged \u547d\u4ee4\u4ece\u6682\u5b58\u4e2d\u6062\u590d\u5355\u4e2a\u6587\u4ef6\u3002 <\/li>\n<\/ul>\n<p><strong>2. \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 git reset HEAD \u547d\u4ee4\u53d6\u6d88\u6682\u5b58\u6240\u6709\u5df2\u6682\u5b58\u7684\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>3. \u53d6\u6d88\u6682\u5b58\u90e8\u5206\u66f4\u6539\uff1a<\/strong><\/p>\n<ul>\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528 git restore &#8211;staged &#8211;patch \u547d\u4ee4\u9009\u62e9\u6027\u5730\u6062\u590d\u90e8\u5206\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre># \u53d6\u6d88\u6682\u5b58 myfile.txt\ngit restore --staged myfile.txt\n\n# \u53d6\u6d88\u6682\u5b58\u6240\u6709\u5df2\u6682\u5b58\u7684\u6587\u4ef6\ngit reset HEAD\n\n# \u9009\u62e9\u6027\u5730\u6062\u590d myfile.txt \u4e2d\u7684\u66f4\u6539\ngit restore --staged --patch myfile.txt<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5220\u9664\u6682\u5b58\u4e0d\u4f1a\u5f71\u54cd\u5df2\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u7684\u66f4\u6539\u3002\u5b83\u53ea\u4f1a\u4ece\u6682\u5b58\u4e2d\u5220\u9664\u60a8\u6b63\u5728\u8fdb\u884c\u7684\u66f4\u6539\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f stash\u600e\u4e48\u5220\u9664\u6389\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>\u8981\u5220\u9664 git \u6682\u5b58\uff1a1. \u53d6\u6d88\u6682\u5b58\u5355\u4e2a\u6587\u4ef6\uff1a\u4f7f\u7528 git restore &#8211;staged \u547d\u4ee4\u30022. \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6\uff1a\u4f7f\u7528 git reset head \u547d\u4ee4\u30023. \u53d6\u6d88\u6682\u5b58\u90e8\u5206\u66f4\u6539\uff1a\u4f7f\u7528 git restore &#8211;staged &#8211;patch \u547d\u4ee4\u9009\u62e9\u6027\u5730\u6062\u590d\u66f4\u6539\u3002 \u5982\u4f55\u5220\u9664 Git \u6682\u5b58\uff1f Git \u6682\u5b58\u662f\u4e00\u79cd\u6682\u65f6\u7684\u5b58\u50a8\u533a\u57df\uff0c\u7528\u4e8e\u5b58\u50a8\u6682\u672a\u63d0\u4ea4\u5230\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u7684\u66f4\u6539\u3002\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5220\u9664\u6682\u5b58\u4ee5\u6e05\u7406\u5de5\u4f5c\u533a\u6216\u89e3\u51b3\u51b2\u7a81\u3002 \u8981\u5220\u9664 Git \u6682\u5b58\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a 1. \u53d6\u6d88\u6682\u5b58\u5355\u4e2a\u6587\u4ef6\uff1a \u4f7f\u7528 restore &#8211;staged \u547d\u4ee4\u4ece\u6682\u5b58\u4e2d\u6062\u590d\u5355\u4e2a\u6587\u4ef6\u3002 2. \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6\uff1a \u4f7f\u7528 git reset HEAD \u547d\u4ee4\u53d6\u6d88\u6682\u5b58\u6240\u6709\u5df2\u6682\u5b58\u7684\u6587\u4ef6\u3002 3. \u53d6\u6d88\u6682\u5b58\u90e8\u5206\u66f4\u6539\uff1a \u60a8\u53ef\u4ee5\u4f7f\u7528 git restore &#8211;staged &#8211;patch \u547d\u4ee4\u9009\u62e9\u6027\u5730\u6062\u590d\u90e8\u5206\u66f4\u6539\u3002 \u793a\u4f8b\uff1a # \u53d6\u6d88\u6682\u5b58 myfile.txt git restore &#8211;staged [&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-21566","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21566","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=21566"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21566\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}