{"id":2303,"date":"2015-07-05T23:14:29","date_gmt":"2015-07-05T15:14:29","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2303"},"modified":"2015-07-05T23:14:29","modified_gmt":"2015-07-05T15:14:29","slug":"collect%e5%a6%82%e4%bd%95%e5%9c%a8git%e9%87%8c%e6%92%a4%e9%94%80%e5%87%a0%e4%b9%8e%e4%bb%bb%e4%bd%95%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2303.html","title":{"rendered":"[collect]\u5982\u4f55\u5728Git\u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c"},"content":{"rendered":"<h6>\u539f\u6587\u5730\u5740\uff1a<\/h6>\n<p><a href=\"https:\/\/github.com\/blog\/2019-how-to-undo-almost-anything-with-git\" target=\"_blank\">https:\/\/github.com\/blog\/2019-how-to-undo-almost-anything-with-git<\/a><\/p>\n<h6>\u8bd1\u6587\u5730\u5740\uff1a<\/h6>\n<p><a href=\"http:\/\/blog.jobbole.com\/87700\/\" target=\"_blank\">http:\/\/blog.jobbole.com\/87700\/<\/a><\/p>\n<p>==<\/p>\n<p><span data-rel=\"content\">\u4efb\u4f55\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u7684\u4e00\u4e2a\u6700\u6709\u7684\u7528\u7279\u6027\u5c31\u662f\u201c\u64a4\u9500 (undo)\u201d\u4f60\u7684\u9519\u8bef\u64cd\u4f5c\u7684\u80fd\u529b\u3002\u5728 Git \u91cc\uff0c\u201c\u64a4\u9500\u201d \u8574\u542b\u4e86\u4e0d\u5c11\u7565\u6709\u5dee\u522b\u7684\u529f\u80fd\u3002<\/span><\/p>\n<p>\u5f53\u4f60\u8fdb\u884c\u4e00\u6b21\u65b0\u7684\u63d0\u4ea4\u7684\u65f6\u5019\uff0cGit \u4f1a\u4fdd\u5b58\u4f60\u4ee3\u7801\u5e93\u5728\u90a3\u4e2a\u7279\u5b9a\u65f6\u95f4\u70b9\u7684\u5feb\u7167\uff1b\u4e4b\u540e\uff0c\u4f60\u53ef\u4ee5\u5229\u7528 Git \u8fd4\u56de\u5230\u4f60\u7684\u9879\u76ee\u7684\u4e00\u4e2a\u65e9\u671f\u7248\u672c\u3002<\/p>\n<p>\u5728\u672c\u7bc7\u535a\u6587\u91cc\uff0c\u6211\u4f1a\u8bb2\u89e3\u67d0\u4e9b\u4f60\u9700\u8981\u201c\u64a4\u9500\u201d\u5df2\u505a\u51fa\u7684\u4fee\u6539\u7684\u5e38\u89c1\u573a\u666f\uff0c\u4ee5\u53ca\u5229\u7528 Git \u8fdb\u884c\u8fd9\u4e9b\u64cd\u4f5c\u7684\u6700\u4f73\u65b9\u6cd5\u3002<\/p>\n<h2>\u64a4\u9500\u4e00\u4e2a\u201c\u5df2\u516c\u5f00\u201d\u7684\u6539\u53d8<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5df2\u7ecf\u6267\u884c\u4e86 <code>git push<\/code>, \u628a\u4f60\u7684\u4fee\u6539\u53d1\u9001\u5230\u4e86GitHub\uff0c\u73b0\u5728\u4f60\u610f\u8bc6\u5230\u8fd9\u4e9b commit \u7684\u5176\u4e2d\u4e00\u4e2a\u662f\u6709\u95ee\u9898\u7684\uff0c\u4f60\u9700\u8981\u64a4\u9500\u90a3\u4e00\u4e2a commit.<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong>\u00a0<code>git revert &lt;SHA&gt;<\/code><\/p>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<span style=\"color: #ff0000;\"><strong><code>git revert <\/code>\u4f1a\u4ea7\u751f\u4e00\u4e2a\u65b0\u7684 commit<\/strong><\/span>\uff0c\u5b83\u548c\u6307\u5b9a SHA \u5bf9\u5e94\u7684 commit \u662f\u76f8\u53cd\u7684\uff08\u6216\u8005\u8bf4\u662f\u53cd\u8f6c\u7684\uff09\u3002\u5982\u679c\u539f\u5148\u7684 commit \u662f\u201c\u7269\u8d28\u201d\uff0c\u65b0\u7684 commit \u5c31\u662f\u201c\u53cd\u7269\u8d28\u201d \u2014 \u4efb\u4f55\u4ece\u539f\u5148\u7684 commit \u91cc\u5220\u9664\u7684\u5185\u5bb9\u4f1a\u5728\u65b0\u7684 commit \u91cc\u88ab\u52a0\u56de\u53bb\uff0c\u4efb\u4f55\u5728\u539f\u5148\u7684 commit \u91cc\u52a0\u5165\u7684\u5185\u5bb9\u4f1a\u5728\u65b0\u7684 commit \u91cc\u88ab\u5220\u9664\u3002<\/p>\n<p>\u8fd9\u662f Git \u6700\u5b89\u5168\u3001\u6700\u57fa\u672c\u7684\u64a4\u9500\u573a\u666f\uff0c\u56e0\u4e3a\u5b83\u5e76\u4e0d\u4f1a<span style=\"color: #0000ff;\"><strong>\u6539\u53d8<\/strong><\/span>\u5386\u53f2 \u2014 \u6240\u4ee5\u4f60\u73b0\u5728\u53ef\u4ee5 \u00a0<code>git push\u00a0<\/code>\u65b0\u7684\u201c\u53cd\u8f6c\u201d commit \u6765\u62b5\u6d88\u4f60\u9519\u8bef\u63d0\u4ea4\u7684 commit\u3002<\/p>\n<h2>\u4fee\u6b63\u6700\u540e\u4e00\u4e2a commit \u6d88\u606f<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5728\u6700\u540e\u4e00\u6761 commit \u6d88\u606f\u91cc\u6709\u4e2a\u7b14\u8bef\uff0c\u5df2\u7ecf\u6267\u884c\u4e86\u00a0<code>git commit -m \"Fxies bug #42\"\uff0c\u4f46\u5728<\/code>\u00a0<code>git push<\/code>\u00a0\u4e4b\u524d\u4f60\u610f\u8bc6\u5230\u6d88\u606f\u5e94\u8be5\u662f \u201cFixes bug #42\u2033\u3002<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git commit --amend\n\u6216\ngit commit --amend -m \"Fixes bug #42\"<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<code>git commit --amend<\/code>\u00a0\u4f1a<span style=\"color: #ff0000;\"><strong>\u7528\u4e00\u4e2a\u65b0\u7684 commit \u66f4\u65b0\u5e76\u66ff\u6362\u6700\u8fd1\u7684 commit \uff0c\u8fd9\u4e2a\u65b0\u7684 commit \u4f1a\u628a\u4efb\u4f55\u4fee\u6539\u5185\u5bb9\u548c\u4e0a\u4e00\u4e2a commit \u7684\u5185\u5bb9\u7ed3\u5408\u8d77\u6765<\/strong><\/span>\u3002\u5982\u679c\u5f53\u524d\u6ca1\u6709\u63d0\u51fa\u4efb\u4f55\u4fee\u6539\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u5c31\u53ea\u4f1a\u628a\u4e0a\u6b21\u7684 commit \u6d88\u606f\u91cd\u5199\u4e00\u904d\u3002<\/p>\n<h2>\u64a4\u9500\u201c\u672c\u5730\u7684\u201d\u4fee\u6539<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4e00\u53ea\u732b\u4ece\u952e\u76d8\u4e0a\u8d70\u8fc7\uff0c\u65e0\u610f\u4e2d\u4fdd\u5b58\u4e86\u4fee\u6539\uff0c\u7136\u540e\u7834\u574f\u4e86\u7f16\u8f91\u5668\u3002\u4e0d\u8fc7\uff0c\u4f60\u8fd8\u6ca1\u6709 commit \u8fd9\u4e9b\u4fee\u6539\u3002\u4f60\u60f3\u8981\u6062\u590d\u88ab\u4fee\u6539\u6587\u4ef6\u91cc\u7684\u6240\u6709\u5185\u5bb9 \u2014 \u5c31\u50cf\u4e0a\u6b21 commit \u7684\u65f6\u5019\u4e00\u6a21\u4e00\u6837\u3002<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git checkout -- &lt;bad filename&gt;<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<span style=\"color: #ff0000;\"><strong><code>git checkout <\/code>\u4f1a\u628a\u5de5\u4f5c\u76ee\u5f55\u91cc\u7684\u6587\u4ef6\u4fee\u6539\u5230 Git \u4e4b\u524d\u8bb0\u5f55\u7684\u67d0\u4e2a\u72b6\u6001<\/strong><\/span>\u3002\u4f60\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u4f60\u60f3\u8fd4\u56de\u7684\u5206\u652f\u540d\u6216\u7279\u5b9a SHA \uff0c\u6216\u8005\u5728\u7f3a\u7701\u60c5\u51b5\u4e0b\uff0cGit \u4f1a\u8ba4\u4e3a\u4f60\u5e0c\u671b checkout \u7684\u662f <code>HEAD<\/code>\uff0c\u5f53\u524d checkout \u5206\u652f\u7684\u6700\u540e\u4e00\u6b21 commit\u3002<\/p>\n<p>\u8bb0\u4f4f\uff1a\u4f60\u7528\u8fd9\u79cd\u65b9\u6cd5\u201c\u64a4\u9500\u201d\u7684\u4efb\u4f55\u4fee\u6539<strong>\u771f\u7684<\/strong>\u4f1a\u5b8c\u5168\u6d88\u5931\u3002\u56e0\u4e3a\u5b83\u4eec\u4ece\u6765\u6ca1\u6709\u88ab\u63d0\u4ea4\u8fc7\uff0c\u6240\u4ee5\u4e4b\u540e Git \u4e5f\u65e0\u6cd5\u5e2e\u52a9\u6211\u4eec\u6062\u590d\u5b83\u4eec\u3002\u4f60\u8981\u786e\u4fdd\u81ea\u5df1\u4e86\u89e3\u4f60\u5728\u8fd9\u4e2a\u64cd\u4f5c\u91cc\u6254\u6389\u7684\u4e1c\u897f\u662f\u4ec0\u4e48\uff01\uff08\u4e5f\u8bb8\u53ef\u4ee5\u5148\u5229\u7528\u00a0<code>git diff<\/code> \u786e\u8ba4\u4e00\u4e0b\uff09<\/p>\n<h2>\u91cd\u7f6e\u201c\u672c\u5730\u7684\u201d\u4fee\u6539<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5728\u672c\u5730\u63d0\u4ea4\u4e86\u4e00\u4e9b\u4e1c\u897f\uff08\u8fd8\u6ca1\u6709 push\uff09\uff0c\u4f46\u662f\u6240\u6709\u8fd9\u4e9b\u4e1c\u897f\u90fd\u5f88\u7cdf\u7cd5\uff0c\u4f60\u5e0c\u671b\u64a4\u9500\u524d\u9762\u7684\u4e09\u6b21\u63d0\u4ea4 \u2014 \u5c31\u50cf\u5b83\u4eec\u4ece\u6765\u6ca1\u6709\u53d1\u751f\u8fc7\u4e00\u6837\u3002<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git reset &lt;last good SHA&gt;\n\u6216\ngit reset --hard &lt;last good SHA&gt;<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<strong><span style=\"color: #ff0000;\"><code>git reset <\/code>\u4f1a\u628a\u4f60\u7684\u4ee3\u7801\u5e93\u5386\u53f2\u8fd4\u56de\u5230\u6307\u5b9a\u7684 SHA \u72b6\u6001<\/span><\/strong>\u3002 \u8fd9\u6837\u5c31\u50cf\u662f\u8fd9\u4e9b\u63d0\u4ea4\u4ece\u6765\u6ca1\u6709\u53d1\u751f\u8fc7\u3002\u7f3a\u7701\u60c5\u51b5\u4e0b\uff0c <code>git reset <\/code>\u4f1a\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u3002\u8fd9\u6837\uff0c\u63d0\u4ea4\u662f\u6ca1\u6709\u4e86\uff0c\u4f46\u662f\u4fee\u6539\u5185\u5bb9\u8fd8\u5728\u78c1\u76d8\u4e0a\u3002\u8fd9\u662f\u4e00\u79cd\u5b89\u5168\u7684\u9009\u62e9\uff0c\u4f46\u901a\u5e38\u6211\u4eec\u4f1a\u5e0c\u671b\u4e00\u6b65\u5c31\u201c\u64a4\u9500\u201d\u63d0\u4ea4\u4ee5\u53ca\u4fee\u6539\u5185\u5bb9 \u2014 \u8fd9\u5c31\u662f <code>--hard <\/code>\u9009\u9879\u7684\u529f\u80fd\u3002<\/p>\n<h2>\u5728\u64a4\u9500\u201c\u672c\u5730\u4fee\u6539\u201d\u4e4b\u540e\u518d\u6062\u590d<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u63d0\u4ea4\u4e86\u51e0\u4e2a commit\uff0c\u7136\u540e\u7528\u00a0<code>git reset --hard<\/code>\u00a0\u64a4\u9500\u4e86\u8fd9\u4e9b\u4fee\u6539\uff08\u89c1\u4e0a\u4e00\u6bb5\uff09\uff0c\u63a5\u7740\u4f60\u53c8\u610f\u8bc6\u5230\uff1a\u4f60\u5e0c\u671b\u8fd8\u539f\u8fd9\u4e9b\u4fee\u6539\uff01<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git reflog\u00a0\u548c\u00a0git reset\u00a0\u6216\u00a0git checkout<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<code>git reflog <\/code>\u5bf9\u4e8e\u6062\u590d\u9879\u76ee\u5386\u53f2\u662f\u4e00\u4e2a\u8d85\u68d2\u7684\u8d44\u6e90\u3002\u4f60\u53ef\u4ee5\u6062\u590d<span style=\"color: #ff0000;\"><strong>\u51e0\u4e4e<\/strong><\/span>\u4efb\u4f55\u4e1c\u897f \u2014 \u4efb\u4f55\u4f60 commit \u8fc7\u7684\u4e1c\u897f \u2014 \u53ea\u8981\u901a\u8fc7 reflog\u3002<\/p>\n<p>\u4f60\u53ef\u80fd\u5df2\u7ecf\u719f\u6089\u4e86\u00a0<code>git log<\/code>\u00a0\u547d\u4ee4\uff0c\u5b83\u4f1a\u663e\u793a commit \u7684\u5217\u8868\u3002\u00a0<code>git reflog<\/code>\u00a0\u4e5f\u662f\u7c7b\u4f3c\u7684\uff0c\u4e0d\u8fc7\u5b83\u663e\u793a\u7684\u662f\u4e00\u4e2a\u00a0<code>HEAD<\/code>\u00a0\u53d1\u751f\u6539\u53d8\u7684\u65f6\u95f4\u5217\u8868.<\/p>\n<p><strong>\u4e00\u4e9b\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/p>\n<ul>\n<li><strong><span style=\"color: #ff0000;\"><code>\u5b83\u6d89\u53ca\u7684\u53ea\u662f HEAD <\/code>\u7684\u6539\u53d8<\/span><\/strong>\u3002\u5728\u4f60\u5207\u6362\u5206\u652f\u3001\u7528 <code>git commit <\/code>\u8fdb\u884c\u63d0\u4ea4\u3001\u4ee5\u53ca\u7528 <code>git reset <\/code>\u64a4\u9500 commit \u65f6\uff0c<code>HEAD <\/code>\u4f1a\u6539\u53d8\uff0c\u4f46\u5f53\u4f60\u7528 <code>git checkout -- &lt;bad filename&gt; <\/code>\u64a4\u9500\u65f6\uff08\u6b63\u5982\u6211\u4eec\u5728\u524d\u9762\u8bb2\u5230\u7684\u60c5\u51b5\uff09\uff0cHEAD \u5e76\u4e0d\u4f1a\u6539\u53d8 \u2014 \u5982\u524d\u6240\u8ff0\uff0c\u8fd9\u4e9b\u4fee\u6539\u4ece\u6765\u6ca1\u6709\u88ab\u63d0\u4ea4\u8fc7\uff0c\u56e0\u6b64 reflog \u4e5f\u65e0\u6cd5\u5e2e\u52a9\u6211\u4eec\u6062\u590d\u5b83\u4eec\u3002<\/li>\n<li><span style=\"color: #ff0000;\"><strong><code>git reflog <\/code>\u4e0d\u4f1a\u6c38\u8fdc\u4fdd\u6301<\/strong><\/span>\u3002Git \u4f1a\u5b9a\u671f\u6e05\u7406\u90a3\u4e9b \u201c\u7528\u4e0d\u5230\u7684\u201d \u5bf9\u8c61\u3002\u4e0d\u8981\u6307\u671b\u51e0\u4e2a\u6708\u524d\u7684\u63d0\u4ea4\u8fd8\u4e00\u76f4\u8eba\u5728\u90a3\u91cc\u3002<\/li>\n<li><strong>\u4f60\u7684 <code>reflog <\/code>\u5c31\u662f\u4f60\u7684\uff0c<span style=\"color: #ff0000;\">\u53ea\u662f\u4f60\u7684<\/span><\/strong>\u3002\u4f60\u4e0d\u80fd\u7528 <code>git reflog <\/code>\u6765\u6062\u590d\u53e6\u4e00\u4e2a\u5f00\u53d1\u8005\u6ca1\u6709 push \u8fc7\u7684 commit\u3002<\/li>\n<\/ul>\n<p><a class=\"cboxElement\" title=\"\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c\" href=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953866\/f6b9f054-d891-11e4-8c53-838eff9f40ae.png\" target=\"_blank\" rel=\"lightbox[87700]\"><img decoding=\"async\" src=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953866\/f6b9f054-d891-11e4-8c53-838eff9f40ae.png\" alt=\"reflog\" \/><\/a><\/p>\n<p>\u90a3\u4e48\u2026\u4f60\u600e\u4e48\u5229\u7528 reflog \u6765\u201c\u6062\u590d\u201d\u4e4b\u524d\u201c\u64a4\u9500\u201d\u7684 commit \u5462\uff1f\u5b83\u53d6\u51b3\u4e8e\u4f60\u60f3\u505a\u5230\u7684\u5230\u5e95\u662f\u4ec0\u4e48\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u5e0c\u671b\u51c6\u786e\u5730\u6062\u590d\u9879\u76ee\u7684\u5386\u53f2\u5230\u67d0\u4e2a\u65f6\u95f4\u70b9\uff0c\u7528\u00a0<code>git reset --hard &lt;SHA&gt;<\/code><\/li>\n<li>\u5982\u679c\u4f60\u5e0c\u671b\u91cd\u5efa\u5de5\u4f5c\u76ee\u5f55\u91cc\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\uff0c\u8ba9\u5b83\u4eec\u6062\u590d\u5230\u67d0\u4e2a\u65f6\u95f4\u70b9\u7684\u72b6\u6001\uff0c\u7528\u00a0<code>git checkout &lt;SHA&gt; -- &lt;filename&gt;<\/code><\/li>\n<li>\u5982\u679c\u4f60\u5e0c\u671b\u628a\u8fd9\u4e9b commit \u91cc\u7684\u67d0\u4e00\u4e2a\u91cd\u65b0\u63d0\u4ea4\u5230\u4f60\u7684\u4ee3\u7801\u5e93\u91cc\uff0c\u7528\u00a0<code>git cherry-pick &lt;SHA&gt;<\/code><\/li>\n<\/ul>\n<h2>\u5229\u7528\u5206\u652f\u7684\u53e6\u4e00\u79cd\u505a\u6cd5<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u8fdb\u884c\u4e86\u4e00\u4e9b\u63d0\u4ea4\uff0c\u7136\u540e\u610f\u8bc6\u5230\u4f60\u5f00\u59cb check out \u7684\u662f\u00a0<code>master \u5206\u652f\u3002\u4f60\u5e0c\u671b\u8fd9\u4e9b\u63d0\u4ea4\u8fdb\u5230\u53e6\u4e00\u4e2a\u7279\u6027\uff08feature\uff09\u5206\u652f\u91cc\u3002<\/code><\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git branch feature, git reset --hard origin\/master, and git checkout feature<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0\u4f60\u53ef\u80fd\u4e60\u60ef\u4e86\u7528\u00a0<code>git checkout -b &lt;name&gt; \u521b\u5efa\u65b0\u7684\u5206\u652f\u00a0<\/code>\u2014 \u8fd9\u662f\u521b\u5efa\u65b0\u5206\u652f\u5e76\u9a6c\u4e0a check out \u7684\u6d41\u884c\u6377\u5f84 \u2014 \u4f46\u662f\u4f60\u4e0d\u5e0c\u671b\u9a6c\u4e0a\u5207\u6362\u5206\u652f\u3002\u8fd9\u91cc\uff0c\u00a0<code>git branch feature<\/code>\u00a0\u521b\u5efa\u4e00\u4e2a\u53eb\u505a\u00a0<code>feature<\/code>\u00a0\u7684\u65b0\u5206\u652f\u5e76\u6307\u5411\u4f60\u6700\u8fd1\u7684 commit\uff0c\u4f46\u8fd8\u662f\u8ba9\u4f60 check out \u5728\u00a0<code>master \u5206\u652f\u4e0a\u3002<\/code><\/p>\n<p>\u4e0b\u4e00\u6b65\uff0c\u5728\u63d0\u4ea4\u4efb\u4f55\u65b0\u7684 commit \u4e4b\u524d\uff0c\u7528\u00a0<code>git reset --hard<\/code>\u00a0\u628a\u00a0<code>master<\/code>\u00a0\u5206\u652f\u5012\u56de\u00a0<code>origin\/master \u3002\u4e0d\u8fc7\u522b\u62c5\u5fc3\uff0c\u90a3\u4e9b commit \u8fd8\u5728<\/code>\u00a0<code>feature \u5206\u652f\u91cc\u3002<\/code><\/p>\n<p>\u6700\u540e\uff0c\u7528\u00a0<code>git checkout<\/code>\u00a0\u5207\u6362\u5230\u65b0\u7684\u00a0<code>feature<\/code>\u00a0\u5206\u652f\uff0c\u5e76\u4e14\u8ba9\u4f60\u6700\u8fd1\u6240\u6709\u7684\u5de5\u4f5c\u6210\u679c\u90fd\u5b8c\u597d\u65e0\u635f\u3002<\/p>\n<h2>\u53ca\u65f6\u5206\u652f\uff0c\u7701\u53bb\u7e41\u7410<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5728\u00a0master\u00a0\u5206\u652f\u7684\u57fa\u7840\u4e0a\u521b\u5efa\u4e86\u00a0<code>feature<\/code>\u00a0\u5206\u652f\uff0c\u4f46\u00a0<code>master<\/code>\u00a0\u5206\u652f\u5df2\u7ecf\u6ede\u540e\u4e8e\u00a0<code>origin\/master \u5f88\u591a\u3002\u73b0\u5728<\/code>\u00a0<code>master<\/code>\u00a0\u5206\u652f\u5df2\u7ecf\u548c\u00a0<code>origin\/master \u540c\u6b65\uff0c\u4f60\u5e0c\u671b<\/code>\u5728\u00a0<code>feature<\/code>\u00a0\u4e0a\u7684\u63d0\u4ea4\u662f\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u800c\u4e0d\u662f\u4e5f\u4ece\u6ede\u540e\u5f88\u591a\u7684\u5730\u65b9\u5f00\u59cb\u3002<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git checkout feature\u00a0\u548c\u00a0git rebase master<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0\u8981\u8fbe\u5230\u8fd9\u4e2a\u6548\u679c\uff0c\u4f60\u672c\u6765\u53ef\u4ee5\u901a\u8fc7\u00a0<code>git reset<\/code>\u00a0(\u4e0d\u52a0\u00a0<code>--hard<\/code>, \u8fd9\u6837\u53ef\u4ee5\u5728\u78c1\u76d8\u4e0a\u4fdd\u7559\u4fee\u6539) \u548c\u00a0<code>git checkout -b &lt;new branch name&gt;<\/code>\u00a0\u7136\u540e\u518d\u91cd\u65b0\u63d0\u4ea4\u4fee\u6539\uff0c\u4e0d\u8fc7\u8fd9\u6837\u505a\u7684\u8bdd\uff0c\u4f60\u5c31\u4f1a\u5931\u53bb\u63d0\u4ea4\u5386\u53f2\u3002\u6211\u4eec\u6709\u66f4\u597d\u7684\u529e\u6cd5\u3002<\/p>\n<p><code>git rebase master<\/code>\u00a0\u4f1a\u505a\u5982\u4e0b\u7684\u4e8b\u60c5\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\u5b83\u4f1a\u627e\u5230\u4f60\u5f53\u524d check out \u7684\u5206\u652f\u548c\u00a0<code>master \u5206\u652f\u7684\u5171\u540c\u7956\u5148\u3002<\/code><\/li>\n<li>\u7136\u540e\u5b83 reset \u5f53\u524d \u00a0check out \u7684\u5206\u652f\u5230\u90a3\u4e2a\u5171\u540c\u7956\u5148\uff0c\u5728\u4e00\u4e2a\u4e34\u65f6\u4fdd\u5b58\u533a\u5b58\u653e\u6240\u6709\u4e4b\u524d\u7684\u63d0\u4ea4\u3002<\/li>\n<li>\u7136\u540e\u5b83\u628a\u5f53\u524d check out \u7684\u5206\u652f\u63d0\u5230\u00a0<code>master<\/code>\u00a0\u7684\u672b\u5c3e\u90e8\u5206\uff0c\u5e76\u4ece\u4e34\u65f6\u4fdd\u5b58\u533a\u91cd\u65b0\u628a\u5b58\u653e\u7684 commit \u63d0\u4ea4\u5230\u00a0<code>master<\/code>\u00a0\u5206\u652f\u7684\u6700\u540e\u4e00\u4e2a commit \u4e4b\u540e\u3002<\/li>\n<\/ul>\n<h2>\u5927\u91cf\u7684\u64a4\u9500\/\u6062\u590d<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5411\u67d0\u4e2a\u65b9\u5411\u5f00\u59cb\u5b9e\u73b0\u4e00\u4e2a\u7279\u6027\uff0c\u4f46\u662f\u534a\u8def\u4f60\u610f\u8bc6\u5230\u53e6\u4e00\u4e2a\u65b9\u6848\u66f4\u597d\u3002\u4f60\u5df2\u7ecf\u8fdb\u884c\u4e86\u5341\u51e0\u6b21\u63d0\u4ea4\uff0c\u4f46\u4f60\u73b0\u5728\u53ea\u9700\u8981\u5176\u4e2d\u7684\u4e00\u90e8\u5206\u3002\u4f60\u5e0c\u671b\u5176\u4ed6\u4e0d\u9700\u8981\u7684\u63d0\u4ea4\u7edf\u7edf\u6d88\u5931\u3002<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git rebase -i &lt;earlier SHA&gt;<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<code>-i<\/code>\u00a0\u53c2\u6570\u8ba9\u00a0<code>rebase<\/code>\u00a0\u8fdb\u5165\u201c\u4ea4\u4e92\u6a21\u5f0f\u201d\u3002\u5b83\u5f00\u59cb\u7c7b\u4f3c\u4e8e\u524d\u9762\u8ba8\u8bba\u7684 rebase\uff0c\u4f46\u5728\u91cd\u65b0\u8fdb\u884c\u4efb\u4f55\u63d0\u4ea4\u4e4b\u524d\uff0c\u5b83\u4f1a\u6682\u505c\u4e0b\u6765\u5e76\u5141\u8bb8\u4f60\u8be6\u7ec6\u5730\u4fee\u6539\u6bcf\u4e2a\u63d0\u4ea4\u3002<\/p>\n<p><code>rebase -i<\/code>\u00a0\u4f1a\u6253\u5f00\u4f60\u7684\u7f3a\u7701\u6587\u672c\u7f16\u8f91\u5668\uff0c\u91cc\u9762\u5217\u51fa\u5019\u9009\u7684\u63d0\u4ea4\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a class=\"cboxElement\" title=\"\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c\" href=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953863\/f6b1ab88-d891-11e4-97c1-e0630ac74e74.png\" target=\"_blank\" rel=\"lightbox[87700]\"><img decoding=\"async\" src=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953863\/f6b1ab88-d891-11e4-97c1-e0630ac74e74.png\" alt=\"rebase-interactive1\" \/><\/a><\/p>\n<p>\u524d\u9762\u4e24\u5217\u662f\u952e\uff1a\u7b2c\u4e00\u4e2a\u662f\u9009\u5b9a\u7684\u547d\u4ee4\uff0c\u5bf9\u5e94\u7b2c\u4e8c\u5217\u91cc\u7684 SHA \u786e\u5b9a\u7684 commit\u3002\u7f3a\u7701\u60c5\u51b5\u4e0b\uff0c\u00a0<code>rebase -i<\/code>\u00a0 \u5047\u5b9a\u6bcf\u4e2a commit \u90fd\u8981\u901a\u8fc7 \u00a0<code>pick<\/code>\u00a0\u547d\u4ee4\u88ab\u8fd0\u7528\u3002<\/p>\n<p>\u8981\u4e22\u5f03\u4e00\u4e2a commit\uff0c\u53ea\u8981\u5728\u7f16\u8f91\u5668\u91cc\u5220\u9664\u90a3\u4e00\u884c\u5c31\u884c\u4e86\u3002\u5982\u679c\u4f60\u4e0d\u518d\u9700\u8981\u9879\u76ee\u91cc\u7684\u90a3\u51e0\u4e2a\u9519\u8bef\u7684\u63d0\u4ea4\uff0c\u4f60\u53ef\u4ee5\u5220\u9664\u4e0a\u4f8b\u4e2d\u76841\u30013\u30014\u884c\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u4fdd\u7559 commit \u7684\u5185\u5bb9\uff0c\u800c\u662f\u5bf9 commit \u6d88\u606f\u8fdb\u884c\u7f16\u8f91\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0<code>reword<\/code>\u00a0\u547d\u4ee4\u3002 \u628a\u7b2c\u4e00\u5217\u91cc\u7684\u00a0<code>pick<\/code>\u00a0\u66ff\u6362\u4e3a\u00a0<code>reword<\/code>\u00a0(\u6216\u8005\u76f4\u63a5\u7528\u00a0<code>r<\/code>)\u3002\u6709\u4eba\u4f1a\u89c9\u5f97\u5728\u8fd9\u91cc\u76f4\u63a5\u91cd\u5199 commit \u6d88\u606f\u5c31\u884c\u4e86\uff0c\u4f46\u662f\u8fd9\u6837\u4e0d\u7ba1\u7528 \u2014<code>rebase -i<\/code>\u00a0\u4f1a\u5ffd\u7565 SHA \u5217\u524d\u9762\u7684\u4efb\u4f55\u4e1c\u897f\u3002\u5b83\u540e\u9762\u7684\u6587\u672c\u53ea\u662f\u7528\u6765\u5e2e\u52a9\u6211\u4eec\u8bb0\u4f4f\u00a0<code>0835fe2<\/code>\u00a0\u662f\u5e72\u5565\u7684\u3002\u5f53\u4f60\u5b8c\u6210\u00a0<code>rebase -i<\/code>\u00a0\u7684\u64cd\u4f5c\u4e4b\u540e\uff0c\u4f60\u4f1a\u88ab\u63d0\u793a\u8f93\u5165\u9700\u8981\u7f16\u5199\u7684\u4efb\u4f55 commit \u6d88\u606f\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u628a\u4e24\u4e2a commit \u5408\u5e76\u5230\u4e00\u8d77\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0<code>squash<\/code>\u00a0\u6216\u00a0<code>fixup<\/code>\u00a0\u547d\u4ee4\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a class=\"cboxElement\" title=\"\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c\" href=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953865\/f6b605ca-d891-11e4-98cf-d567ca9f4edc.png\" target=\"_blank\" rel=\"lightbox[87700]\"><img decoding=\"async\" src=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953865\/f6b605ca-d891-11e4-98cf-d567ca9f4edc.png\" alt=\"rebase-interactive2\" \/><\/a><\/p>\n<p><code>squash<\/code>\u00a0\u548c\u00a0<code>fixup<\/code>\u00a0\u4f1a\u201c\u5411\u4e0a\u201d\u5408\u5e76 \u2014 \u5e26\u6709\u8fd9\u4e24\u4e2a\u547d\u4ee4\u7684 commit \u4f1a\u88ab\u5408\u5e76\u5230\u5b83\u7684\u524d\u4e00\u4e2a commit \u91cc\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\uff0c\u00a0<code>0835fe2<\/code>\u00a0\u548c\u00a0<code>6943e85<\/code>\u00a0\u4f1a\u88ab\u5408\u5e76\u6210\u4e00\u4e2a commit\uff0c\u00a0<code>38f5e4e<\/code>\u00a0\u548c\u00a0<code>af67f82<\/code>\u00a0\u4f1a\u88ab\u5408\u5e76\u6210\u53e6\u4e00\u4e2a\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9009\u62e9\u4e86\u00a0<code>squash\uff0c<\/code>\u00a0Git \u4f1a\u63d0\u793a\u6211\u4eec\u7ed9\u65b0\u5408\u5e76\u7684 commit \u4e00\u4e2a\u65b0\u7684 commit \u6d88\u606f\uff1b\u00a0<code>fixup<\/code>\u00a0\u5219\u4f1a\u628a\u5408\u5e76\u6e05\u5355\u91cc\u7b2c\u4e00\u4e2a commit \u7684\u6d88\u606f\u76f4\u63a5\u7ed9\u65b0\u5408\u5e76\u7684 commit \u3002 \u8fd9\u91cc\uff0c\u4f60\u77e5\u9053\u00a0<code>af67f82<\/code>\u00a0\u662f\u4e00\u4e2a\u201c\u5b8c\u4e86\u5b8c\u4e86\u2026.\u201d \u7684 commit\uff0c\u6240\u4ee5\u4f60\u4f1a\u7559\u7740\u00a0<code>38f5e4e<\/code>\u00a0as\u7684 commit \u6d88\u606f\uff0c\u4f46\u4f60\u4f1a\u7ed9\u5408\u5e76\u4e86\u00a0<code>0835fe2<\/code>\u00a0\u548c\u00a0<code>6943e85<\/code>\u00a0\u7684\u65b0 commit \u7f16\u5199\u4e00\u4e2a\u65b0\u7684\u6d88\u606f\u3002<\/p>\n<p>\u5728\u4f60\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u7684\u65f6\u5019\uff0cGit \u4f1a\u6309\u4ece\u9876\u90e8\u5230\u5e95\u90e8\u7684\u987a\u5e8f\u8fd0\u7528\u4f60\u7684 commit\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u4fdd\u5b58\u524d\u4fee\u6539 commit \u987a\u5e8f\u6765\u6539\u53d8\u8fd0\u7528\u7684\u987a\u5e8f\u3002\u5982\u679c\u4f60\u613f\u610f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u5b89\u6392\u628a\u00a0<code>af67f82<\/code>\u00a0\u548c\u00a0<code>0835fe2<\/code>\u00a0\u5408\u5e76\u5230\u4e00\u8d77\uff1a<\/p>\n<p><a class=\"cboxElement\" title=\"\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c\" href=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953864\/f6b4a9d2-d891-11e4-9ac9-10039c031d06.png\" target=\"_blank\" rel=\"lightbox[87700]\"><img decoding=\"async\" src=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953864\/f6b4a9d2-d891-11e4-9ac9-10039c031d06.png\" alt=\"rebase-interactive3\" \/><\/a><\/p>\n<h2>\u4fee\u590d\u66f4\u65e9\u671f\u7684 commit<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5728\u4e00\u4e2a\u66f4\u65e9\u671f\u7684 commit \u91cc\u5fd8\u8bb0\u4e86\u52a0\u5165\u4e00\u4e2a\u6587\u4ef6\uff0c\u5982\u679c\u66f4\u65e9\u7684 commit \u80fd\u5305\u542b\u8fd9\u4e2a\u5fd8\u8bb0\u7684\u6587\u4ef6\u5c31\u592a\u68d2\u4e86\u3002\u4f60\u8fd8\u6ca1\u6709 push\uff0c\u4f46\u8fd9\u4e2a commit \u4e0d\u662f\u6700\u8fd1\u7684\uff0c\u6240\u4ee5\u4f60\u6ca1\u6cd5\u7528\u00a0<code>commit --amend<\/code>.<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">git commit --squash &lt;SHA of the earlier commit&gt;\n\u548c\ngit rebase --autosquash -i &lt;even earlier SHA&gt;<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0<code>git commit --squash<\/code>\u00a0\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 commit \uff0c\u5b83\u5e26\u6709\u4e00\u4e2a commit \u6d88\u606f\uff0c\u7c7b\u4f3c\u4e8e\u00a0<code>squash! Earlier commit<\/code>\u3002 (\u4f60\u4e5f\u53ef\u4ee5\u624b\u5de5\u521b\u5efa\u4e00\u4e2a\u5e26\u6709\u7c7b\u4f3c commit \u6d88\u606f\u7684 commit\uff0c\u4f46\u662f\u00a0<code>commit --squash<\/code>\u00a0\u53ef\u4ee5\u5e2e\u4f60\u7701\u4e0b\u8f93\u5165\u7684\u5de5\u4f5c\u3002)<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u60f3\u88ab\u63d0\u793a\u4e3a\u65b0\u5408\u5e76\u7684 commit \u8f93\u5165\u4e00\u6761\u65b0\u7684 commit \u6d88\u606f\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5229\u7528\u00a0<code>git commit --fixup<\/code>\u00a0\u3002\u5728\u8fd9\u4e2a\u60c5\u51b5\u4e0b\uff0c\u4f60\u5f88\u53ef\u80fd\u4f1a\u7528<code>commit --fixup<\/code>\u00a0\uff0c\u56e0\u4e3a\u4f60\u53ea\u662f\u5e0c\u671b\u5728\u00a0<code>rebase<\/code>\u00a0\u7684\u65f6\u5019\u4f7f\u7528\u65e9\u671f commit \u7684 commit \u6d88\u606f\u3002<\/p>\n<p><code>rebase --autosquash -i<\/code>\u00a0 \u4f1a\u6fc0\u6d3b\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684\u00a0<code>rebase<\/code>\u00a0\u7f16\u8f91\u5668\uff0c\u4f46\u662f\u7f16\u8f91\u5668\u6253\u5f00\u7684\u65f6\u5019\uff0c\u5728 commit \u6e05\u5355\u91cc\u4efb\u4f55\u00a0<code>squash!<\/code>\u00a0\u548c\u00a0<code>fixup!<\/code>\u00a0\u7684 commit \u90fd\u5df2\u7ecf\u914d\u5bf9\u5230\u76ee\u6807 commit \u4e0a\u4e86\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a class=\"cboxElement\" title=\"\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500(\u51e0\u4e4e)\u4efb\u4f55\u64cd\u4f5c\" href=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953862\/f6a7a1d8-d891-11e4-8784-c32262ff54da.png\" target=\"_blank\" rel=\"lightbox[87700]\"><img decoding=\"async\" src=\"https:\/\/cloud.githubusercontent.com\/assets\/2077\/6953862\/f6a7a1d8-d891-11e4-8784-c32262ff54da.png\" alt=\"rebase-autosquash\" \/><\/a><\/p>\n<p>\u5728\u4f7f\u7528\u00a0<code>--squash<\/code>\u00a0\u548c\u00a0<code>--fixup<\/code>\u00a0\u7684\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u4e0d\u8bb0\u5f97\u60f3\u8981\u4fee\u6b63\u7684 commit \u7684 SHA \u4e86\u2014 \u53ea\u8bb0\u5f97\u5b83\u662f\u524d\u9762\u7b2c 1 \u4e2a\u6216\u7b2c 5 \u4e2a commit\u3002\u4f60\u4f1a\u53d1\u73b0 Git \u7684\u00a0<code>^<\/code>\u00a0\u548c\u00a0<code>~ \u64cd\u4f5c\u7b26\u7279\u522b\u597d\u7528\u3002<\/code><code>HEAD^<\/code>\u00a0\u662f\u00a0<code>HEAD\u00a0<\/code>\u7684\u524d\u4e00\u4e2a commit\u3002\u00a0<code>HEAD~4<\/code>\u00a0\u662f\u00a0<code>HEAD<\/code>\u00a0\u5f80\u524d\u7b2c 4 \u4e2a \u2013 \u6216\u8005\u4e00\u8d77\u7b97\uff0c\u5012\u6570\u7b2c 5 \u4e2a commit\u3002<\/p>\n<h2>\u505c\u6b62\u8ffd\u8e2a\u4e00\u4e2a\u6587\u4ef6<\/h2>\n<p><strong>\u573a\u666f:<\/strong>\u00a0\u4f60\u5076\u7136\u628a\u00a0<code>application.log<\/code>\u00a0\u52a0\u5230\u4ee3\u7801\u5e93\u91cc\u4e86\uff0c\u73b0\u5728\u6bcf\u6b21\u4f60\u8fd0\u884c\u5e94\u7528\uff0cGit \u90fd\u4f1a\u62a5\u544a\u5728\u00a0<code>application.log<\/code>\u00a0\u91cc\u6709\u672a\u63d0\u4ea4\u7684\u4fee\u6539\u3002\u4f60\u628a\u00a0<code>*.log<\/code>in \u653e\u5230\u4e86\u00a0<code>.gitignore<\/code>\u00a0\u6587\u4ef6\u91cc\uff0c\u53ef\u6587\u4ef6\u8fd8\u662f\u5728\u4ee3\u7801\u5e93\u91cc \u2014 \u4f60\u600e\u4e48\u624d\u80fd\u544a\u8bc9 Git \u201c\u64a4\u9500\u201d \u5bf9\u8fd9\u4e2a\u6587\u4ef6\u7684\u8ffd\u8e2a\u5462\uff1f<\/p>\n<p><strong>\u65b9\u6cd5:<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">git rm --cached application.log<\/pre>\n<p><strong>\u539f\u7406:<\/strong>\u00a0\u867d\u7136 <code>.gitignore <\/code>\u4f1a\u963b\u6b62 Git \u8ffd\u8e2a\u6587\u4ef6\u7684\u4fee\u6539\uff0c\u751a\u81f3\u4e0d\u5173\u6ce8\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u4f46\u8fd9\u53ea\u662f\u9488\u5bf9\u90a3\u4e9b\u4ee5\u524d\u4ece\u6765\u6ca1\u6709\u8ffd\u8e2a\u8fc7\u7684\u6587\u4ef6\u3002\u4e00\u65e6\u6709\u4e2a\u6587\u4ef6\u88ab\u52a0\u5165\u5e76\u63d0\u4ea4\u4e86\uff0cGit \u5c31\u4f1a\u6301\u7eed\u5173\u6ce8\u8be5\u6587\u4ef6\u7684\u6539\u53d8\u3002\u7c7b\u4f3c\u5730\uff0c\u5982\u679c\u4f60\u5229\u7528 <code>git add -f <\/code>\u6765\u5f3a\u5236\u6216\u8986\u76d6\u4e86 <code>.gitignore<\/code>\uff0c Git \u8fd8\u4f1a\u6301\u7eed\u8ffd\u8e2a\u6539\u53d8\u7684\u60c5\u51b5\u3002\u4e4b\u540e\u4f60\u5c31\u4e0d\u5fc5\u7528\u00a0<code>-f <\/code>\u6765\u6dfb\u52a0\u8fd9\u4e2a\u6587\u4ef6\u4e86\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5e0c\u671b\u4ece Git \u7684\u8ffd\u8e2a\u5bf9\u8c61\u4e2d\u5220\u9664\u90a3\u4e2a\u672c\u5e94\u5ffd\u7565\u7684\u6587\u4ef6\uff0c<code>git rm --cached <\/code>\u4f1a\u4ece\u8ffd\u8e2a\u5bf9\u8c61\u4e2d\u5220\u9664\u5b83\uff0c\u4f46\u8ba9\u6587\u4ef6\u5728\u78c1\u76d8\u4e0a\u4fdd\u6301\u539f\u5c01\u4e0d\u52a8\u3002\u56e0\u4e3a\u73b0\u5728\u5b83\u5df2\u7ecf\u88ab\u5ffd\u7565\u4e86\uff0c\u4f60\u5728 \u00a0<code>git status<\/code>\u00a0\u91cc\u5c31\u4e0d\u4f1a\u518d\u770b\u89c1\u8fd9\u4e2a\u6587\u4ef6\uff0c\u4e5f\u4e0d\u4f1a\u518d\u5076\u7136\u63d0\u4ea4\u8be5\u6587\u4ef6\u7684\u4fee\u6539\u4e86\u3002<\/p>\n<hr \/>\n<p>\u8fd9\u5c31\u662f\u5982\u4f55\u5728 Git \u91cc\u64a4\u9500\u4efb\u4f55\u64cd\u4f5c\u7684\u65b9\u6cd5\u3002\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u672c\u6587\u4e2d\u7528\u5230\u7684 Git \u547d\u4ee4\uff0c\u8bf7\u67e5\u770b\u4e0b\u9762\u7684\u6709\u5173\u6587\u6863\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-checkout\">checkout<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-commit\">commit<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-rebase\">rebase<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-reflog\">reflog<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-reset\">reset<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-revert\">revert<\/a><\/li>\n<li><a href=\"http:\/\/git-scm.com\/docs\/git-rm\">rm<\/a><\/li>\n<\/ul>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1a https:\/\/github.com\/blog\/2019-how-to-undo-almost-a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,7,12],"tags":[468,365,473],"class_list":["post-2303","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-programing","category-tools","tag-git","tag-github","tag-jobbole"],"views":10594,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2303"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2303\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}