{"id":21222,"date":"2024-11-19T10:24:49","date_gmt":"2024-11-19T02:24:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21222\/"},"modified":"2024-11-19T10:24:49","modified_gmt":"2024-11-19T02:24:49","slug":"git%e9%94%99%e8%af%af%e6%8f%90%e4%ba%a4%e5%90%8e%e5%a6%82%e4%bd%95%e8%bf%98%e5%8e%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21222\/","title":{"rendered":"git\u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f"},"content":{"rendered":"<blockquote><p>\n  \u5982\u679c git \u63d0\u4ea4\u9519\u8bef\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fd8\u539f\uff1a\u786e\u5b9a\u8981\u8fd8\u539f\u7684\u63d0\u4ea4\uff0c\u5e76\u8bb0\u4e0b\u5176 sha1 \u54c8\u5e0c\u503c\u3002\u4f7f\u7528 git reset &#8211;soft \u547d\u4ee4\u91cd\u7f6e git \u7d22\u5f15\u3002\u4fee\u6539\u53d7\u9519\u8bef\u63d0\u4ea4\u5f71\u54cd\u7684\u6587\u4ef6\u3002\u4f7f\u7528 git add \u548c git commit &#8211;amend \u6dfb\u52a0\u5e76\u63d0\u4ea4\u66f4\u6539\u3002\uff08\u53ef\u9009\uff09\u4f7f\u7528 git push &#8211;force \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/09\/2024040913002612336.jpg\" class=\"aligncenter\" title=\"git\u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f\u63d2\u56fe\" alt=\"git\u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f\u63d2\u56fe\" \/><\/p>\n<p><strong>Git \u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5982\u679c\u6211\u5728 Git \u4e2d\u63d0\u4ea4\u4e86\u4e00\u4e2a\u9519\u8bef\u7684\u66f4\u6539\uff0c\u5982\u4f55\u8fd8\u539f\u5b83\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u8fd8\u539f\u9519\u8bef\u63d0\u4ea4\u7684\u8fc7\u7a0b\u4e3b\u8981\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u786e\u5b9a\u8981\u8fd8\u539f\u7684\u63d0\u4ea4<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528  log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u3002<\/li>\n<li>\u627e\u5230\u5305\u542b\u9519\u8bef\u66f4\u6539\u7684\u63d0\u4ea4\u3002<\/li>\n<li>\u6ce8\u610f\u8be5\u63d0\u4ea4\u7684 SHA1 \u54c8\u5e0c\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 2\uff1a\u91cd\u7f6e Git \u7d22\u5f15<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 git reset &#8211;soft \u547d\u4ee4\u5c06 Git \u7d22\u5f15\u91cd\u7f6e\u5230\u9519\u8bef\u63d0\u4ea4\u4e4b\u524d\u7684\u72b6\u6001\u3002 <\/li>\n<li>\u6b64\u547d\u4ee4\u4e0d\u4f1a\u89e6\u53ca\u5de5\u4f5c\u533a\u4e2d\u7684\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 3\uff1a\u4fee\u6539\u6587\u4ef6<\/strong><\/p>\n<ul>\n<li>\u5728\u5de5\u4f5c\u533a\u4e2d\u5bf9\u53d7\u9519\u8bef\u63d0\u4ea4\u5f71\u54cd\u7684\u6587\u4ef6\u8fdb\u884c\u5fc5\u8981\u7684\u4fee\u6539\u3002<\/li>\n<li>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216 Git \u7f16\u8f91\u547d\u4ee4\uff08\u5982 git commit &#8211;amend) \u66f4\u6539\u6587\u4ef6\u7684\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 4\uff1a\u63d0\u4ea4\u66f4\u6539<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 git add \u547d\u4ee4\u5c06\u4fee\u6539\u7684\u6587\u4ef6\u6dfb\u52a0\u5230 Git \u6682\u5b58\u533a\u3002<\/li>\n<li>\u4f7f\u7528 git commit &#8211;amend \u547d\u4ee4\u63d0\u4ea4\u6682\u5b58\u533a\u7684\u66f4\u6539\uff0c\u5e76\u7528\u6b63\u786e\u7684\u66f4\u6539\u53d6\u4ee3\u9519\u8bef\u7684\u63d0\u4ea4\u3002<\/li>\n<\/ul>\n<p><strong>\u6b65\u9aa4 5\uff1a\u5f3a\u5236\u63a8\u9001\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u60a8\u5df2\u5c06\u9519\u8bef\u63d0\u4ea4\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u5219\u53ef\u80fd\u9700\u8981\u4f7f\u7528 git push &#8211;force \u547d\u4ee4\u5f3a\u5236\u63a8\u9001\u6b63\u786e\u7684\u63d0\u4ea4\u3002<\/li>\n<li> <strong>\u6ce8\u610f\uff1a<\/strong>\u4ec5\u5728\u60a8\u786e\u5b9a\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u6ca1\u6709\u5176\u4ed6\u8d21\u732e\u8005\u65f6\u624d\u4f7f\u7528\u6b64\u547d\u4ee4\uff0c\u5426\u5219\u53ef\u80fd\u4f1a\u8986\u76d6\u5176\u4ed6\u4eba\u7684\u66f4\u6539\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u60a8\u53ea\u60f3\u6062\u590d\u5355\u4e2a\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528 git checkout \u547d\u4ee4\u3002 <\/li>\n<li>\u5982\u679c\u60a8\u9700\u8981\u8fd8\u539f\u591a\u4e2a\u63d0\u4ea4\uff0c\u53ef\u4ee5\u5c06 git reset \u547d\u4ee4\u4e0e git reflog \u547d\u4ee4\u7ed3\u5408\u4f7f\u7528\u3002<\/li>\n<li>\u59cb\u7ec8\u5907\u4efd\u60a8\u7684\u5de5\u4f5c\u533a\uff0c\u4ee5\u9632\u4e07\u4e00\u9700\u8981\u6062\u590d\u66f4\u65e9\u7684\u7248\u672c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f\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>\u5982\u679c git \u63d0\u4ea4\u9519\u8bef\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fd8\u539f\uff1a\u786e\u5b9a\u8981\u8fd8\u539f\u7684\u63d0\u4ea4\uff0c\u5e76\u8bb0\u4e0b\u5176 sha1 \u54c8\u5e0c\u503c\u3002\u4f7f\u7528 git reset &#8211;soft \u547d\u4ee4\u91cd\u7f6e git \u7d22\u5f15\u3002\u4fee\u6539\u53d7\u9519\u8bef\u63d0\u4ea4\u5f71\u54cd\u7684\u6587\u4ef6\u3002\u4f7f\u7528 git add \u548c git commit &#8211;amend \u6dfb\u52a0\u5e76\u63d0\u4ea4\u66f4\u6539\u3002\uff08\u53ef\u9009\uff09\u4f7f\u7528 git push &#8211;force \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002 Git \u9519\u8bef\u63d0\u4ea4\u540e\u5982\u4f55\u8fd8\u539f \u95ee\u9898\uff1a\u5982\u679c\u6211\u5728 Git \u4e2d\u63d0\u4ea4\u4e86\u4e00\u4e2a\u9519\u8bef\u7684\u66f4\u6539\uff0c\u5982\u4f55\u8fd8\u539f\u5b83\uff1f \u56de\u7b54\uff1a \u8fd8\u539f\u9519\u8bef\u63d0\u4ea4\u7684\u8fc7\u7a0b\u4e3b\u8981\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u6b65\u9aa4 1\uff1a\u786e\u5b9a\u8981\u8fd8\u539f\u7684\u63d0\u4ea4 \u4f7f\u7528 log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u3002 \u627e\u5230\u5305\u542b\u9519\u8bef\u66f4\u6539\u7684\u63d0\u4ea4\u3002 \u6ce8\u610f\u8be5\u63d0\u4ea4\u7684 SHA1 \u54c8\u5e0c\u503c\u3002 \u6b65\u9aa4 2\uff1a\u91cd\u7f6e Git \u7d22\u5f15 \u4f7f\u7528 git reset &#8211;soft \u547d\u4ee4\u5c06 Git \u7d22\u5f15\u91cd\u7f6e\u5230\u9519\u8bef\u63d0\u4ea4\u4e4b\u524d\u7684\u72b6\u6001\u3002 \u6b64\u547d\u4ee4\u4e0d\u4f1a\u89e6\u53ca\u5de5\u4f5c\u533a\u4e2d\u7684\u6587\u4ef6\u3002 \u6b65\u9aa4 3\uff1a\u4fee\u6539\u6587\u4ef6 \u5728\u5de5\u4f5c\u533a\u4e2d\u5bf9\u53d7\u9519\u8bef\u63d0\u4ea4\u5f71\u54cd\u7684\u6587\u4ef6\u8fdb\u884c\u5fc5\u8981\u7684\u4fee\u6539\u3002 \u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6216 Git [&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-21222","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21222","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=21222"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21222\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}