{"id":340,"date":"2024-12-27T15:18:53","date_gmt":"2024-12-27T07:18:53","guid":{"rendered":"http:\/\/106.12.148.75\/?p=340"},"modified":"2025-01-24T21:11:26","modified_gmt":"2025-01-24T13:11:26","slug":"%e3%80%90git%e3%80%91git%e6%8f%90%e4%ba%a4%e9%94%99%e4%ba%86%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/jamilblog.top\/?p=340","title":{"rendered":"\u3010Git\u3011git\u63d0\u4ea4\u9519\u4e86\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u5728Git\u4e2d\u5904\u7406\u4e0d\u540c\u9636\u6bb5\u7684\u9519\u8bef<\/h2>\n\n\n\n<p>\u5728\u65e5\u5e38\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u96be\u514d\u4f1a\u5728\u4ee3\u7801\u7ba1\u7406\u5de5\u5177Git\u4e2d\u72af\u9519\u3002\u7406\u89e3\u5982\u4f55\u5728\u4e0d\u540c\u9636\u6bb5\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\uff0c\u8fd8\u80fd\u786e\u4fdd\u4ee3\u7801\u5e93\u7684\u6574\u6d01\u4e0e\u7a33\u5b9a\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5728\u4ee5\u4e0b\u4e09\u79cd\u60c5\u51b5\u4e0b\u5982\u4f55\u5904\u7406\u9519\u8bef\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u9519\u8bef\u5df2\u7ecfcommit\u5e76push\u5230\u8fdc\u7aef<\/h2>\n\n\n\n<p>\u5f53\u9519\u8bef\u7684\u63d0\u4ea4\u5df2\u7ecf\u88ab\u63a8\u9001\u5230\u8fdc\u7aef\u4ed3\u5e93\u65f6\uff0c\u5904\u7406\u8d77\u6765\u76f8\u5bf9\u590d\u6742\uff0c\u56e0\u4e3a\u8fd9\u6d89\u53ca\u5230\u56e2\u961f\u534f\u4f5c\u548c\u4ee3\u7801\u5e93\u7684\u5386\u53f2\u8bb0\u5f55\u3002\u4ee5\u4e0b\u662f\u51e0\u79cd\u5e38\u89c1\u7684\u5904\u7406\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u4f7f\u7528git revert\u64a4\u9500\u9519\u8bef\u63d0\u4ea4<\/h3>\n\n\n\n<p>git revert\u547d\u4ee4\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4\uff0c\u64a4\u9500\u6307\u5b9a\u7684\u9519\u8bef\u63d0\u4ea4\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4f1a\u4fee\u6539\u4ed3\u5e93\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u9002\u5408\u5df2\u7ecf\u63a8\u9001\u5230\u8fdc\u7aef\u4e14\u88ab\u5176\u4ed6\u4eba\u62c9\u53d6\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<p>\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\uff0c\u627e\u5230\u9700\u8981\u64a4\u9500\u7684\u63d0\u4ea4ID\uff08SHA\uff09<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"git log\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">log<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u4f7f\u7528git revert\u64a4\u9500\u6307\u5b9a\u7684\u63d0\u4ea4<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"git revert &lt;commit-id&gt; \" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">revert<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><span style=\"color: #EEFFFF\"> <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u63a8\u9001\u64a4\u9500\u540e\u7684\u63d0\u4ea4\u5230\u8fdc\u7aef<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"git push origin\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">push<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">origin<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u5f3a\u5236\u56de\u9000\uff08\u4e0d\u63a8\u8350\uff0c\u9700\u8c28\u614e\u4f7f\u7528\uff09<\/h3>\n\n\n\n<p>\u5982\u679c\u786e\u5b9e\u9700\u8981\u4fee\u6539\u5386\u53f2\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528git reset\u7ed3\u5408--hard\u53c2\u6570\uff0c\u7136\u540e\u5f3a\u5236\u63a8\u9001\u3002\u4f46\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u91cd\u5199\u5386\u53f2\uff0c\u53ef\u80fd\u5bfc\u81f4\u56e2\u961f\u6210\u5458\u7684\u4ed3\u5e93\u51fa\u73b0\u95ee\u9898\uff0c\u56e0\u6b64\u4e0d\u63a8\u8350\u5728\u56e2\u961f\u534f\u4f5c\u4e2d\u4f7f\u7528\uff0c\u9664\u975e\u7ecf\u8fc7\u5145\u5206\u6c9f\u901a\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<p># \u56de\u9000\u5230\u6307\u5b9a\u7684\u63d0\u4ea4\uff08\u4e0d\u4fdd\u7559\u540e\u7eed\u66f4\u6539\uff09<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"git reset --hard &lt;commit-id&gt;\n# \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7aef\ngit push origin &lt;branch-name&gt; --force\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--hard<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7aef<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">push<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">origin<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">branch-nam<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--force<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786e\u4fdd\u6240\u6709\u56e2\u961f\u6210\u5458\u4e86\u89e3\u6b64\u64cd\u4f5c\uff0c\u4ee5\u907f\u514d\u4ee3\u7801\u51b2\u7a81\u548c\u6570\u636e\u4e22\u5931\u3002<\/li>\n\n\n\n<li>\u5907\u4efd\u5f53\u524d\u5206\u652f\uff0c\u4ee5\u9632\u64cd\u4f5c\u5931\u8bef\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 \u4f7f\u7528git reflog\u6062\u590d<\/h3>\n\n\n\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7git reflog\u627e\u5230\u4e4b\u524d\u7684\u72b6\u6001\u5e76\u6062\u590d\u3002\u4e0d\u8fc7\uff0c\u8fd9\u540c\u6837\u9700\u8981\u8c28\u614e\u64cd\u4f5c\uff0c\u907f\u514d\u5f71\u54cd\u56e2\u961f\u534f\u4f5c\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u67e5\u770breflog\uff0c\u627e\u5230\u9700\u8981\u6062\u590d\u7684\u63d0\u4ea4\ngit reflog\n\n# \u91cd\u7f6e\u5230\u6307\u5b9a\u7684\u63d0\u4ea4\ngit reset --hard <commit-id&gt;\n\n# \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7aef\ngit push origin <branch-name&gt; --force\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u67e5\u770breflog\uff0c\u627e\u5230\u9700\u8981\u6062\u590d\u7684\u63d0\u4ea4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reflog<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u91cd\u7f6e\u5230\u6307\u5b9a\u7684\u63d0\u4ea4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--hard<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5f3a\u5236\u63a8\u9001\u5230\u8fdc\u7aef<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">push<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">origin<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">branch-nam<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--force<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u9519\u8bef\u5df2commit\u4f46\u8fd8\u6ca1push\u5230\u8fdc\u7aef<\/h2>\n\n\n\n<p>\u5f53\u9519\u8bef\u7684\u63d0\u4ea4\u5df2\u7ecf\u5b58\u5728\u4e8e\u672c\u5730\u4ed3\u5e93\uff0c\u4f46\u5c1a\u672a\u63a8\u9001\u5230\u8fdc\u7aef\u65f6\uff0c\u5904\u7406\u76f8\u5bf9\u7b80\u5355\uff0c\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539\u63d0\u4ea4\u5386\u53f2\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u4f7f\u7528git commit --amend\u4fee\u6539\u6700\u65b0\u7684\u63d0\u4ea4<\/h3>\n\n\n\n<p>\u5982\u679c\u9519\u8bef\u51fa\u73b0\u5728\u6700\u65b0\u7684\u4e00\u6b21\u63d0\u4ea4\uff0c\u53ef\u4ee5\u4f7f\u7528--amend\u9009\u9879\u4fee\u6539\u63d0\u4ea4\u5185\u5bb9\u6216\u63d0\u4ea4\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u4fee\u6539\u6587\u4ef6\u5185\u5bb9\u540e\uff0c\u91cd\u65b0\u6dfb\u52a0\u5230\u6682\u5b58\u533a\ngit add <file&gt;\n\n# \u4f7f\u7528--amend\u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\ngit commit --amend\n\n# \u5982\u679c\u53ea\u9700\u8981\u4fee\u6539\u63d0\u4ea4\u4fe1\u606f\ngit commit --amend -m &quot;\u65b0\u7684\u63d0\u4ea4\u4fe1\u606f&quot;\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u4fee\u6539\u6587\u4ef6\u5185\u5bb9\u540e\uff0c\u91cd\u65b0\u6dfb\u52a0\u5230\u6682\u5b58\u533a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">add<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">fil<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u4f7f\u7528--amend\u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">commit<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--amend<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5982\u679c\u53ea\u9700\u8981\u4fee\u6539\u63d0\u4ea4\u4fe1\u606f<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">commit<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--amend<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">-m<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&quot;<\/span><span style=\"color: #C3E88D\">\u65b0\u7684\u63d0\u4ea4\u4fe1\u606f<\/span><span style=\"color: #89DDFF\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 \u4f7f\u7528git reset\u56de\u9000\u5230\u4e4b\u524d\u7684\u72b6\u6001<\/h3>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u64a4\u9500\u591a\u4e2a\u63d0\u4ea4\u6216\u56de\u9000\u5230\u67d0\u4e2a\u7279\u5b9a\u7684\u63d0\u4ea4\uff0c\u53ef\u4ee5\u4f7f\u7528git reset\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u67e5\u770b\u63d0\u4ea4\u5386\u53f2\ngit log\n\n# \u8f6f\u56de\u9000\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u66f4\u6539\ngit reset --soft <commit-id&gt;\n\n# \u6df7\u5408\u56de\u9000\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\u7684\u66f4\u6539\u4f46\u6e05\u7a7a\u6682\u5b58\u533a\ngit reset --mixed <commit-id&gt;\n\n# \u786c\u56de\u9000\uff0c\u6e05\u7a7a\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u66f4\u6539\ngit reset --hard <commit-id&gt;\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u67e5\u770b\u63d0\u4ea4\u5386\u53f2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">log<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u8f6f\u56de\u9000\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u66f4\u6539<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--soft<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u6df7\u5408\u56de\u9000\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\u7684\u66f4\u6539\u4f46\u6e05\u7a7a\u6682\u5b58\u533a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--mixed<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u786c\u56de\u9000\uff0c\u6e05\u7a7a\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7684\u66f4\u6539<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--hard<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">commit-i<\/span><span style=\"color: #EEFFFF\">d<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528--hard\u53c2\u6570\u4f1a\u4e22\u5931\u672a\u4fdd\u5b58\u7684\u66f4\u6539\uff0c\u52a1\u5fc5\u786e\u8ba4\u65e0\u8bef\u540e\u518d\u6267\u884c\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4ec5\u9700\u8981\u4fee\u6539\u90e8\u5206\u63d0\u4ea4\uff0c\u53ef\u4ee5\u7ed3\u5408git rebase -i\u8fdb\u884c\u4ea4\u4e92\u5f0f\u53d8\u57fa\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u4f7f\u7528git rebase -i\u8fdb\u884c\u4ea4\u4e92\u5f0f\u53d8\u57fa<\/h3>\n\n\n\n<p>\u901a\u8fc7\u4ea4\u4e92\u5f0f\u53d8\u57fa\uff0c\u53ef\u4ee5\u4fee\u6539\u3001\u5408\u5e76\u6216\u5220\u9664\u591a\u4e2a\u63d0\u4ea4\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u4ea4\u4e92\u5f0f\u53d8\u57fa\uff0c\u6307\u5b9a\u9700\u8981\u4fee\u6539\u7684\u63d0\u4ea4\u8303\u56f4\ngit rebase -i HEAD~n  # n\u4e3a\u9700\u8981\u56de\u6eaf\u7684\u63d0\u4ea4\u6570\n\n# \u5728\u6253\u5f00\u7684\u7f16\u8f91\u5668\u4e2d\uff0c\u6839\u636e\u9700\u8981\u4fee\u6539\u63d0\u4ea4\u6307\u4ee4\uff08pick, edit, squash\u7b49\uff09\n\n# \u5b8c\u6210\u53d8\u57fa\u540e\uff0c\u63d0\u4ea4\u66f4\u6539\ngit push origin <branch-name&gt;\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u4ea4\u4e92\u5f0f\u53d8\u57fa\uff0c\u6307\u5b9a\u9700\u8981\u4fee\u6539\u7684\u63d0\u4ea4\u8303\u56f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">rebase<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">-i<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">HEAD~n<\/span><span style=\"color: #EEFFFF\">  <\/span><span style=\"color: #546E7A; font-style: italic\"># n\u4e3a\u9700\u8981\u56de\u6eaf\u7684\u63d0\u4ea4\u6570<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5728\u6253\u5f00\u7684\u7f16\u8f91\u5668\u4e2d\uff0c\u6839\u636e\u9700\u8981\u4fee\u6539\u63d0\u4ea4\u6307\u4ee4\uff08pick, edit, squash\u7b49\uff09<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5b8c\u6210\u53d8\u57fa\u540e\uff0c\u63d0\u4ea4\u66f4\u6539<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">push<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">origin<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">branch-nam<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u9519\u8bef\u4ec5add\u4f46\u8fd8\u6ca1commit<\/h2>\n\n\n\n<p>\u5f53\u9519\u8bef\u7684\u66f4\u6539\u5df2\u7ecf\u88ab\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff08staged\uff09\uff0c\u4f46\u5c1a\u672a\u63d0\u4ea4\u65f6\uff0c\u53ef\u4ee5\u8f7b\u677e\u64a4\u9500\u8fd9\u4e9b\u66f4\u6539\u6216\u91cd\u65b0\u8c03\u6574\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u4f7f\u7528git reset\u53d6\u6d88\u6682\u5b58<\/h3>\n\n\n\n<p>\u5982\u679c\u53ea\u60f3\u5c06\u66f4\u6539\u4ece\u6682\u5b58\u533a\u79fb\u9664\uff0c\u4f46\u4fdd\u7559\u5de5\u4f5c\u533a\u7684\u4fee\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528git reset\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u53d6\u6d88\u6682\u5b58\u6307\u5b9a\u6587\u4ef6\ngit reset <file&gt;\n\n# \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6\ngit reset\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u53d6\u6d88\u6682\u5b58\u6307\u5b9a\u6587\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">fil<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u53d6\u6d88\u6682\u5b58\u6240\u6709\u6587\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">reset<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u4f7f\u7528git checkout\u4e22\u5f03\u5de5\u4f5c\u533a\u7684\u66f4\u6539<\/h3>\n\n\n\n<p>\u5982\u679c\u51b3\u5b9a\u653e\u5f03\u5bf9\u6587\u4ef6\u7684\u6240\u6709\u66f4\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528git checkout\u6062\u590d\u6587\u4ef6\u5230\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u72b6\u6001\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u4e22\u5f03\u6307\u5b9a\u6587\u4ef6\u7684\u66f4\u6539\ngit checkout -- <file&gt;\n\n# \u4e22\u5f03\u6240\u6709\u6587\u4ef6\u7684\u66f4\u6539\ngit checkout -- .\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u4e22\u5f03\u6307\u5b9a\u6587\u4ef6\u7684\u66f4\u6539<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">checkout<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #89DDFF\">&lt;<\/span><span style=\"color: #C3E88D\">fil<\/span><span style=\"color: #EEFFFF\">e<\/span><span style=\"color: #89DDFF\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u4e22\u5f03\u6240\u6709\u6587\u4ef6\u7684\u66f4\u6539<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">checkout<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">--<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">.<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6b64\u64cd\u4f5c\u4e0d\u53ef\u9006\uff0c\u8bf7\u786e\u4fdd\u4e0d\u9700\u8981\u4fdd\u7559\u66f4\u6539\u540e\u518d\u6267\u884c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u4f7f\u7528git stash\u6682\u5b58\u5f53\u524d\u66f4\u6539<\/h3>\n\n\n\n<p>\u5982\u679c\u6682\u65f6\u4e0d\u60f3\u5904\u7406\u8fd9\u4e9b\u66f4\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528git stash\u5c06\u5176\u4fdd\u5b58\u8d77\u6765\uff0c\u7a0d\u540e\u518d\u6062\u590d\u3002<\/p>\n\n\n\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#EEFFFF;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#304047;color:#d5ffff\">ShellScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u5c06\u5f53\u524d\u66f4\u6539\u6682\u5b58\ngit stash\n\n# \u67e5\u770b\u6682\u5b58\u5217\u8868\ngit stash list\n\n# \u6062\u590d\u6700\u8fd1\u7684\u6682\u5b58\ngit stash pop\n\n# \u6062\u590d\u6307\u5b9a\u7684\u6682\u5b58\ngit stash apply stash@{n}  # n\u4e3a\u6682\u5b58\u7f16\u53f7\n\" style=\"color:#EEFFFF;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki material-theme\" style=\"background-color: #263238\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u5c06\u5f53\u524d\u66f4\u6539\u6682\u5b58<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">stash<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u67e5\u770b\u6682\u5b58\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">stash<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">list<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u6062\u590d\u6700\u8fd1\u7684\u6682\u5b58<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">stash<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">pop<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #546E7A; font-style: italic\"># \u6062\u590d\u6307\u5b9a\u7684\u6682\u5b58<\/span><\/span>\n<span class=\"line\"><span style=\"color: #FFCB6B\">git<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">stash<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">apply<\/span><span style=\"color: #EEFFFF\"> <\/span><span style=\"color: #C3E88D\">stash@{n}<\/span><span style=\"color: #EEFFFF\">  <\/span><span style=\"color: #546E7A; font-style: italic\"># n\u4e3a\u6682\u5b58\u7f16\u53f7<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003\u8d44\u6599<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/git-scm.com\/book\/zh\/v2\" target=\"_blank\" rel=\"nofollow noopener\">Pro Git Book<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/git-scm.com\/docs\" target=\"_blank\" rel=\"nofollow noopener\">Git\u5b98\u65b9\u6587\u6863<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728Git\u4e2d\u5904\u7406\u4e0d\u540c\u9636\u6bb5\u7684\u9519\u8bef \u5728\u65e5\u5e38\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u96be\u514d\u4f1a\u5728\u4ee3\u7801\u7ba1\u7406\u5de5\u5177Git\u4e2d\u72af\u9519\u3002\u7406\u89e3\u5982\u4f55\u5728\u4e0d\u540c\u9636\u6bb5\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u63d0 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[29,5],"tags":[30],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-git","category-tools","tag-git"],"_links":{"self":[{"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamilblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340"}],"version-history":[{"count":4,"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":488,"href":"https:\/\/jamilblog.top\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions\/488"}],"wp:attachment":[{"href":"https:\/\/jamilblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamilblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamilblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}