{"id":21209,"date":"2024-11-19T08:49:03","date_gmt":"2024-11-19T00:49:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21209\/"},"modified":"2024-11-19T08:49:03","modified_gmt":"2024-11-19T00:49:03","slug":"git%e4%b8%8d%e5%b0%8f%e5%bf%83%e8%a6%86%e7%9b%96%e6%8f%90%e4%ba%a4%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21209\/","title":{"rendered":"git\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  \u5f53\u4e0d\u5c0f\u5fc3\u8986\u76d6 git \u63d0\u4ea4\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6062\u590d\uff1a\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u786e\u8ba4\u5df2\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u521b\u5efa\u65b0\u5206\u652f\u4ee5\u6062\u590d\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u91cd\u65b0\u63d0\u4ea4\u5df2\u8986\u76d6\u7684\u66f4\u6539\u3002\u5c06\u6062\u590d\u5206\u652f\u5408\u5e76\u56de\u4e3b\u5206\u652f\u3002\u63a8\u9001\u5408\u5e76\u7684\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u53ef\u9009\u5730\u5220\u9664\u6062\u590d\u5206\u652f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040912032623633.jpg\" class=\"aligncenter\" title=\"git\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"git\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 git \u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u4f1a\u4e0d\u5c0f\u5fc3\u8986\u76d6\u5df2\u7ecf\u63d0\u4ea4\u7684\u66f4\u6539\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u91cd\u8981\u7684\u4ee3\u7801\u6216\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6062\u590d\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u9a8c\u8bc1\u8986\u76d6\u7684\u63d0\u4ea4<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u4f7f\u7528 git log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u5e76\u786e\u8ba4\u5df2\u8986\u76d6\u7684\u63d0\u4ea4\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u5206\u652f<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u652f\u4ee5\u6062\u590d\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>git checkout -b recover-lost-commits<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u91cd\u65b0\u63d0\u4ea4\u8986\u76d6\u7684\u66f4\u6539<\/strong><\/p>\n<p>\u5207\u6362\u5230\u65b0\u5206\u652f\u540e\uff0c\u4f7f\u7528 git add \u548c git commit \u547d\u4ee4\u91cd\u65b0\u63d0\u4ea4\u5df2\u8986\u76d6\u7684\u66f4\u6539\u3002<\/p>\n<p><strong>4. \u5408\u5e76\u6062\u590d\u5206\u652f<\/strong><\/p>\n<p>\u5c06\u6062\u590d\u5206\u652f\u5408\u5e76\u56de\u4e3b\u5206\u652f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>git checkout master\ngit merge recover-lost-commits<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u63a8\u9001\u5408\u5e76<\/strong><\/p>\n<p>\u63a8\u9001\u5408\u5e76\u7684\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>git push origin master<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u5220\u9664\u6062\u590d\u5206\u652f\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<p>\u4e00\u65e6\u6062\u590d\u4e86\u8986\u76d6\u7684\u63d0\u4ea4\uff0c\u5c31\u53ef\u4ee5\u5b89\u5168\u5220\u9664\u6062\u590d\u5206\u652f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>git branch -d recover-lost-commits<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u5728\u8986\u76d6\u63d0\u4ea4\u4e4b\u524d\u5df2\u63a8\u9001\u66f4\u6539\uff0c\u5219\u9700\u8981\u5728\u6062\u590d\u63d0\u4ea4\u540e\u5f3a\u5236\u63a8\u9001\u3002<\/li>\n<li>\u5982\u679c\u8986\u76d6\u7684\u63d0\u4ea4\u304c\u542b\u307e\u5305\u542b\u4e86\u654f\u611f\u4fe1\u606f\uff0c\u5219\u9700\u8981\u91c7\u53d6\u5176\u4ed6\u6b65\u9aa4\u6765\u4fdd\u62a4\u8fd9\u4e9b\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e\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>\u5f53\u4e0d\u5c0f\u5fc3\u8986\u76d6 git \u63d0\u4ea4\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6062\u590d\uff1a\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u786e\u8ba4\u5df2\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u521b\u5efa\u65b0\u5206\u652f\u4ee5\u6062\u590d\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u91cd\u65b0\u63d0\u4ea4\u5df2\u8986\u76d6\u7684\u66f4\u6539\u3002\u5c06\u6062\u590d\u5206\u652f\u5408\u5e76\u56de\u4e3b\u5206\u652f\u3002\u63a8\u9001\u5408\u5e76\u7684\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u53ef\u9009\u5730\u5220\u9664\u6062\u590d\u5206\u652f\u3002 \u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u600e\u4e48\u529e \u5728\u4f7f\u7528 git \u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u4f1a\u4e0d\u5c0f\u5fc3\u8986\u76d6\u5df2\u7ecf\u63d0\u4ea4\u7684\u66f4\u6539\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u91cd\u8981\u7684\u4ee3\u7801\u6216\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6062\u590d\u4e0d\u5c0f\u5fc3\u8986\u76d6\u63d0\u4ea4\u7684\u6b65\u9aa4\uff1a 1. \u9a8c\u8bc1\u8986\u76d6\u7684\u63d0\u4ea4 \u9996\u5148\uff0c\u4f7f\u7528 git log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u5e76\u786e\u8ba4\u5df2\u8986\u76d6\u7684\u63d0\u4ea4\u3002 2. \u521b\u5efa\u5206\u652f \u521b\u5efa\u4e00\u4e2a\u65b0\u5206\u652f\u4ee5\u6062\u590d\u8986\u76d6\u7684\u63d0\u4ea4\u3002\u4f8b\u5982\uff1a git checkout -b recover-lost-commits \u767b\u5f55\u540e\u590d\u5236 3. \u91cd\u65b0\u63d0\u4ea4\u8986\u76d6\u7684\u66f4\u6539 \u5207\u6362\u5230\u65b0\u5206\u652f\u540e\uff0c\u4f7f\u7528 git add \u548c git commit \u547d\u4ee4\u91cd\u65b0\u63d0\u4ea4\u5df2\u8986\u76d6\u7684\u66f4\u6539\u3002 4. \u5408\u5e76\u6062\u590d\u5206\u652f \u5c06\u6062\u590d\u5206\u652f\u5408\u5e76\u56de\u4e3b\u5206\u652f\u3002\u4f8b\u5982\uff1a git checkout master git merge recover-lost-commits \u767b\u5f55\u540e\u590d\u5236 5. \u63a8\u9001\u5408\u5e76 \u63a8\u9001\u5408\u5e76\u7684\u66f4\u6539\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u4f8b\u5982\uff1a git push origin master \u767b\u5f55\u540e\u590d\u5236 6. \u5220\u9664\u6062\u590d\u5206\u652f\uff08\u53ef\u9009\uff09 \u4e00\u65e6\u6062\u590d\u4e86\u8986\u76d6\u7684\u63d0\u4ea4\uff0c\u5c31\u53ef\u4ee5\u5b89\u5168\u5220\u9664\u6062\u590d\u5206\u652f\u3002\u4f8b\u5982\uff1a git branch -d recover-lost-commits [&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-21209","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21209","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=21209"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21209\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}