{"id":21515,"date":"2024-11-19T14:58:03","date_gmt":"2024-11-19T06:58:03","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21515\/"},"modified":"2024-11-19T14:58:03","modified_gmt":"2024-11-19T06:58:03","slug":"git%e6%80%8e%e4%b9%88%e5%88%a0%e9%99%a4%e5%b7%b2%e7%bb%8f%e6%8f%90%e4%ba%a4%e7%9a%84%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21515\/","title":{"rendered":"git\u600e\u4e48\u5220\u9664\u5df2\u7ecf\u63d0\u4ea4\u7684\u6587\u4ef6"},"content":{"rendered":"<blockquote><p>\n  \u6709\u4e09\u79cd\u65b9\u6cd5\u4ece\u5386\u53f2\u8bb0\u5f55\u5220\u9664\u6587\u4ef6\uff1a1) \u4f7f\u7528 git filter-branch \u91cd\u5199\u5386\u53f2\uff0c\u79fb\u9664\u6307\u5b9a\u6587\u4ef6\uff1b2) \u4f7f\u7528 git rebase \u5220\u9664\u6307\u5b9a\u63d0\u4ea4\u4e2d\u7684\u6587\u4ef6\uff1b3) \u4f7f\u7528 git revert \u8fd8\u539f\u5bf9\u6587\u4ef6\u7684\u66f4\u6539\u5e76\u5220\u9664\u5b83\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u56e0\u6b64\u4f7f\u7528\u524d\u5e94\u5907\u4efd\u4ee3\u7801\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053023003150434.jpg\" class=\"aligncenter\" title=\"git\u600e\u4e48\u5220\u9664\u5df2\u7ecf\u63d0\u4ea4\u7684\u6587\u4ef6\u63d2\u56fe\" alt=\"git\u600e\u4e48\u5220\u9664\u5df2\u7ecf\u63d0\u4ea4\u7684\u6587\u4ef6\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4ece\u5df2\u63d0\u4ea4\u7684\u5386\u53f2\u8bb0\u5f55\u4e2d\u5220\u9664\u6587\u4ef6<\/strong><\/p>\n<p><strong>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528  filter-branch<\/strong><\/p>\n<p>git filter-branch \u547d\u4ee4\u53ef\u7528\u4e8e\u91cd\u5199\u5386\u53f2\u8bb0\u5f55\uff0c\u4ece\u4e2d\u5220\u9664\u6307\u5b9a\u6587\u4ef6\u3002<\/p>\n<pre>git filter-branch --index-filter 'git rm --cached --ignore-unmatch &lt;path\/to\/file&gt;' HEAD<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528 git rebase<\/strong><\/p>\n<p>git rebase \u547d\u4ee4\u5141\u8bb8\u4fee\u6539\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5220\u9664\u6587\u4ef6\uff0c\u800c\u65e0\u9700\u91cd\u5199\u6574\u4e2a\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n<pre>git rebase -i HEAD<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u9009\u62e9\u8981\u4ece\u4e2d\u5220\u9664\u6587\u4ef6\u7684\u63d0\u4ea4\uff0c\u7136\u540e\u8f93\u5165 d \u4ee5\u5220\u9664\u5b83\u3002<\/p>\n<p><strong>\u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528 git revert<\/strong><\/p>\n<p>git revert \u547d\u4ee4\u53ef\u7528\u4e8e\u8fd8\u539f\u5bf9\u6587\u4ef6\u7684\u66f4\u6539\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5220\u9664\u6587\u4ef6\uff0c\u800c\u65e0\u9700\u4fee\u6539\u5386\u53f2\u8bb0\u5f55\u3002<\/p>\n<pre>git revert &lt;commit-hash&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u4ee5\u4e0a\u6240\u6709\u65b9\u6cd5\u90fd\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u5b83\u4eec\u4e4b\u524d\u5907\u4efd\u60a8\u7684\u4ee3\u7801\u3002<\/li>\n<li>\u5982\u679c\u60a8\u5728\u4ed3\u5e93\u4e2d\u6709\u591a\u4e2a\u5206\u652f\uff0c\u5219\u9700\u8981\u4f7f\u7528 -f \u6807\u5fd7\u6765\u5f3a\u5236\u63a8\u9001\u5230\u6bcf\u4e2a\u5206\u652f\u3002<\/li>\n<li>\u5220\u9664\u5df2\u63d0\u4ea4\u7684\u6587\u4ef6\u540e\uff0c\u5982\u679c\u60a8\u4e0d\u60f3\u63d0\u4ea4\u66f4\u6539\uff0c\u8bf7\u4f7f\u7528 git reset HEAD &#8211;hard \u6765\u8fd8\u539f\u5de5\u4f5c\u6811\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5220\u9664\u5df2\u7ecf\u63d0\u4ea4\u7684\u6587\u4ef6\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>\u6709\u4e09\u79cd\u65b9\u6cd5\u4ece\u5386\u53f2\u8bb0\u5f55\u5220\u9664\u6587\u4ef6\uff1a1) \u4f7f\u7528 git filter-branch \u91cd\u5199\u5386\u53f2\uff0c\u79fb\u9664\u6307\u5b9a\u6587\u4ef6\uff1b2) \u4f7f\u7528 git rebase \u5220\u9664\u6307\u5b9a\u63d0\u4ea4\u4e2d\u7684\u6587\u4ef6\uff1b3) \u4f7f\u7528 git revert \u8fd8\u539f\u5bf9\u6587\u4ef6\u7684\u66f4\u6539\u5e76\u5220\u9664\u5b83\u3002\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u56e0\u6b64\u4f7f\u7528\u524d\u5e94\u5907\u4efd\u4ee3\u7801\u3002 \u5982\u4f55\u4ece\u5df2\u63d0\u4ea4\u7684\u5386\u53f2\u8bb0\u5f55\u4e2d\u5220\u9664\u6587\u4ef6 \u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528 filter-branch git filter-branch \u547d\u4ee4\u53ef\u7528\u4e8e\u91cd\u5199\u5386\u53f2\u8bb0\u5f55\uff0c\u4ece\u4e2d\u5220\u9664\u6307\u5b9a\u6587\u4ef6\u3002 git filter-branch &#8211;index-filter &#8216;git rm &#8211;cached &#8211;ignore-unmatch &lt;path\/to\/file&gt;&#8217; HEAD \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528 git rebase git rebase \u547d\u4ee4\u5141\u8bb8\u4fee\u6539\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5220\u9664\u6587\u4ef6\uff0c\u800c\u65e0\u9700\u91cd\u5199\u6574\u4e2a\u5386\u53f2\u8bb0\u5f55\u3002 git rebase -i HEAD \u767b\u5f55\u540e\u590d\u5236 \u9009\u62e9\u8981\u4ece\u4e2d\u5220\u9664\u6587\u4ef6\u7684\u63d0\u4ea4\uff0c\u7136\u540e\u8f93\u5165 d \u4ee5\u5220\u9664\u5b83\u3002 \u65b9\u6cd5\u4e09\uff1a\u4f7f\u7528 git revert git revert \u547d\u4ee4\u53ef\u7528\u4e8e\u8fd8\u539f\u5bf9\u6587\u4ef6\u7684\u66f4\u6539\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5220\u9664\u6587\u4ef6\uff0c\u800c\u65e0\u9700\u4fee\u6539\u5386\u53f2\u8bb0\u5f55\u3002 git revert &lt;commit-hash&gt; \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\uff1a \u4ee5\u4e0a\u6240\u6709\u65b9\u6cd5\u90fd\u662f\u4e0d\u53ef\u9006\u7684\uff0c\u56e0\u6b64\u5728\u4f7f\u7528\u5b83\u4eec\u4e4b\u524d\u5907\u4efd\u60a8\u7684\u4ee3\u7801\u3002 [&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-21515","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21515","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=21515"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21515\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}