{"id":21514,"date":"2024-11-19T15:42:59","date_gmt":"2024-11-19T07:42:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/21514\/"},"modified":"2024-11-19T15:42:59","modified_gmt":"2024-11-19T07:42:59","slug":"git%e6%80%8e%e4%b9%88%e5%9b%9e%e6%bb%9a","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/21514\/","title":{"rendered":"git\u600e\u4e48\u56de\u6eda"},"content":{"rendered":"<blockquote><p>\n  git \u56de\u6eda\u64cd\u4f5c\u5141\u8bb8\u5f00\u53d1\u8005\u6062\u590d\u5230\u4e4b\u524d\u7684\u63d0\u4ea4\u72b6\u6001\u3002\u56de\u6eda\u6b65\u9aa4\u5982\u4e0b\uff1a\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u5e76\u67e5\u627e\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u3002\u64a4\u9500\u6682\u5b58\u66f4\u6539\uff08\u53ef\u9009\uff09\u3002\u8fdb\u884c\u786c\u56de\u6eda\u4ee5\u76f4\u63a5\u6062\u590d\u5230\u6307\u5b9a\u63d0\u4ea4\u3002\u8fdb\u884c\u8f6f\u56de\u6eda\u4ee5\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u66f4\u6539\u3002\u8fdb\u884c\u4ea4\u4e92\u5f0f\u56de\u6eda\u4ee5\u9009\u62e9\u7279\u5b9a\u4fee\u6539\u8fdb\u884c\u56de\u6eda\u3002\u63d0\u4ea4\u56de\u6eda\u4ee5\u4fdd\u5b58\u5df2\u6062\u590d\u7684\u72b6\u6001\u3002\u6ce8\u610f\uff1a\u786c\u56de\u6eda\u4e0d\u53ef\u9006\uff0c\u8f6f\u56de\u6eda\u4e0d\u5e94\u5728\u56e2\u961f\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u4ea4\u4e92\u5f0f\u56de\u6eda\u63d0\u4f9b\u66f4\u591a\u63a7\u5236\u4f46\u66f4\u590d\u6742\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053022574330239.jpg\" class=\"aligncenter\" title=\"git\u600e\u4e48\u56de\u6eda\u63d2\u56fe\" alt=\"git\u600e\u4e48\u56de\u6eda\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Git \u56de\u6eda<\/strong><\/p>\n<p>Git \u4e2d\u7684\u56de\u6eda\u64cd\u4f5c\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u4ee3\u7801\u6062\u590d\u5230\u4e4b\u524d\u7684\u63d0\u4ea4\u72b6\u6001\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u67e5\u627e\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u8bb0\u5f55<\/strong><br \/>\u4f7f\u7528  log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002\u627e\u5230\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u6ce8\u610f\u5176\u63d0\u4ea4\u54c8\u5e0c\u503c\u3002<\/p>\n<p><strong>2. \u64a4\u9500\u6682\u5b58\u66f4\u6539\uff08\u53ef\u9009\uff09<\/strong><br \/>\u5982\u679c\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u5305\u542b\u5c1a\u672a\u63d0\u4ea4\u5230\u6682\u5b58\u533a\u57df\u7684\u66f4\u6539\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>git reset HEAD~1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u786c\u56de\u6eda<\/strong><br \/>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u786c\u56de\u6eda\u3002\u8fd9\u5c06\u76f4\u63a5\u5c06\u4ee3\u7801\u6062\u590d\u5230\u6307\u5b9a\u63d0\u4ea4\uff1a<\/p>\n<pre>git reset --hard &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8f6f\u56de\u6eda<\/strong><br \/>\u8f6f\u56de\u6eda\u4e0d\u4f1a\u91cd\u7f6e\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u5b83\u5c06 HEAD \u6307\u9488\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u63d0\u4ea4\uff0c\u4f46\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u5f53\u524d\u66f4\u6539\u3002<\/p>\n<pre>git reset --soft &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u4ea4\u4e92\u5f0f\u56de\u6eda<\/strong><br \/>\u4ea4\u4e92\u5f0f\u56de\u6eda\u5141\u8bb8\u60a8\u9009\u62e9\u8981\u56de\u6eda\u7684\u7279\u5b9a\u4fee\u6539\u3002<\/p>\n<pre>git reset -i &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u63d0\u4ea4\u56de\u6eda<\/strong><br \/>\u5728\u6267\u884c\u56de\u6eda\u64cd\u4f5c\u540e\uff0c\u60a8\u901a\u5e38\u9700\u8981\u63d0\u4ea4\u66f4\u6539\u4ee5\u4fdd\u5b58\u5df2\u6062\u590d\u7684\u72b6\u6001\uff1a<\/p>\n<pre>git commit -m \"\u56de\u6eda\u5230 &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt;\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786c\u56de\u6eda\u662f\u4e00\u79cd\u7834\u574f\u6027\u7684\u64cd\u4f5c\uff0c\u5b83\u4f1a\u6c38\u4e45\u5220\u9664\u81ea\u6307\u5b9a\u63d0\u4ea4\u540e\u6240\u505a\u7684\u66f4\u6539\u3002<\/li>\n<li>\u8f6f\u56de\u6eda\u5141\u8bb8\u60a8\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u66f4\u6539\uff0c\u4f46\u5b83\u4e0d\u5e94\u5728\u56e2\u961f\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4ea7\u751f\u6df7\u6dc6\u3002<\/li>\n<li>\u4ea4\u4e92\u5f0f\u56de\u6eda\u63d0\u4f9b\u4e86\u5bf9\u56de\u6eda\u8fc7\u7a0b\u7684\u66f4\u591a\u63a7\u5236\uff0c\u4f46\u5b83\u4e5f\u66f4\u590d\u6742\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u56de\u6eda\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>git \u56de\u6eda\u64cd\u4f5c\u5141\u8bb8\u5f00\u53d1\u8005\u6062\u590d\u5230\u4e4b\u524d\u7684\u63d0\u4ea4\u72b6\u6001\u3002\u56de\u6eda\u6b65\u9aa4\u5982\u4e0b\uff1a\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u5e76\u67e5\u627e\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u3002\u64a4\u9500\u6682\u5b58\u66f4\u6539\uff08\u53ef\u9009\uff09\u3002\u8fdb\u884c\u786c\u56de\u6eda\u4ee5\u76f4\u63a5\u6062\u590d\u5230\u6307\u5b9a\u63d0\u4ea4\u3002\u8fdb\u884c\u8f6f\u56de\u6eda\u4ee5\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u66f4\u6539\u3002\u8fdb\u884c\u4ea4\u4e92\u5f0f\u56de\u6eda\u4ee5\u9009\u62e9\u7279\u5b9a\u4fee\u6539\u8fdb\u884c\u56de\u6eda\u3002\u63d0\u4ea4\u56de\u6eda\u4ee5\u4fdd\u5b58\u5df2\u6062\u590d\u7684\u72b6\u6001\u3002\u6ce8\u610f\uff1a\u786c\u56de\u6eda\u4e0d\u53ef\u9006\uff0c\u8f6f\u56de\u6eda\u4e0d\u5e94\u5728\u56e2\u961f\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u4ea4\u4e92\u5f0f\u56de\u6eda\u63d0\u4f9b\u66f4\u591a\u63a7\u5236\u4f46\u66f4\u590d\u6742\u3002 \u5982\u4f55\u4f7f\u7528 Git \u56de\u6eda Git \u4e2d\u7684\u56de\u6eda\u64cd\u4f5c\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u4ee3\u7801\u6062\u590d\u5230\u4e4b\u524d\u7684\u63d0\u4ea4\u72b6\u6001\u3002\u4ee5\u4e0b\u662f\u8be6\u7ec6\u6b65\u9aa4\uff1a 1. \u67e5\u627e\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u8bb0\u5f55\u4f7f\u7528 log \u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002\u627e\u5230\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u6ce8\u610f\u5176\u63d0\u4ea4\u54c8\u5e0c\u503c\u3002 2. \u64a4\u9500\u6682\u5b58\u66f4\u6539\uff08\u53ef\u9009\uff09\u5982\u679c\u8981\u56de\u6eda\u7684\u63d0\u4ea4\u5305\u542b\u5c1a\u672a\u63d0\u4ea4\u5230\u6682\u5b58\u533a\u57df\u7684\u66f4\u6539\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a git reset HEAD~1 \u767b\u5f55\u540e\u590d\u5236 3. \u786c\u56de\u6eda\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u786c\u56de\u6eda\u3002\u8fd9\u5c06\u76f4\u63a5\u5c06\u4ee3\u7801\u6062\u590d\u5230\u6307\u5b9a\u63d0\u4ea4\uff1a git reset &#8211;hard &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt; \u767b\u5f55\u540e\u590d\u5236 4. \u8f6f\u56de\u6eda\u8f6f\u56de\u6eda\u4e0d\u4f1a\u91cd\u7f6e\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u5b83\u5c06 HEAD \u6307\u9488\u79fb\u52a8\u5230\u6307\u5b9a\u7684\u63d0\u4ea4\uff0c\u4f46\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u5f53\u524d\u66f4\u6539\u3002 git reset &#8211;soft &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt; \u767b\u5f55\u540e\u590d\u5236 5. \u4ea4\u4e92\u5f0f\u56de\u6eda\u4ea4\u4e92\u5f0f\u56de\u6eda\u5141\u8bb8\u60a8\u9009\u62e9\u8981\u56de\u6eda\u7684\u7279\u5b9a\u4fee\u6539\u3002 git reset -i &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt; \u767b\u5f55\u540e\u590d\u5236 6. \u63d0\u4ea4\u56de\u6eda\u5728\u6267\u884c\u56de\u6eda\u64cd\u4f5c\u540e\uff0c\u60a8\u901a\u5e38\u9700\u8981\u63d0\u4ea4\u66f4\u6539\u4ee5\u4fdd\u5b58\u5df2\u6062\u590d\u7684\u72b6\u6001\uff1a git commit -m &#8220;\u56de\u6eda\u5230 &lt;\u63d0\u4ea4\u54c8\u5e0c\u503c&gt;&#8221; \u767b\u5f55\u540e\u590d\u5236 \u6ce8\u610f\uff1a \u786c\u56de\u6eda\u662f\u4e00\u79cd\u7834\u574f\u6027\u7684\u64cd\u4f5c\uff0c\u5b83\u4f1a\u6c38\u4e45\u5220\u9664\u81ea\u6307\u5b9a\u63d0\u4ea4\u540e\u6240\u505a\u7684\u66f4\u6539\u3002 \u8f6f\u56de\u6eda\u5141\u8bb8\u60a8\u4fdd\u7559\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u66f4\u6539\uff0c\u4f46\u5b83\u4e0d\u5e94\u5728\u56e2\u961f\u73af\u5883\u4e2d\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4ea7\u751f\u6df7\u6dc6\u3002 \u4ea4\u4e92\u5f0f\u56de\u6eda\u63d0\u4f9b\u4e86\u5bf9\u56de\u6eda\u8fc7\u7a0b\u7684\u66f4\u591a\u63a7\u5236\uff0c\u4f46\u5b83\u4e5f\u66f4\u590d\u6742\u3002 \u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u56de\u6eda\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-21514","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21514","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=21514"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/21514\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=21514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=21514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=21514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}