{"id":20265,"date":"2024-11-19T12:06:06","date_gmt":"2024-11-19T04:06:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/20265\/"},"modified":"2024-11-19T12:06:06","modified_gmt":"2024-11-19T04:06:06","slug":"git%e8%bf%98%e5%8e%9f%e5%88%b0%e6%8c%87%e5%ae%9a%e7%89%88%e6%9c%ac%e8%bf%98%e8%83%bd%e6%81%a2%e5%a4%8d%e5%90%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/20265\/","title":{"rendered":"git\u8fd8\u539f\u5230\u6307\u5b9a\u7248\u672c\u8fd8\u80fd\u6062\u590d\u5417"},"content":{"rendered":"<p>\u5728\u4f7f\u7528git\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u9700\u8981\u8fd8\u539f\u5230\u67d0\u4e00\u4e2a\u7248\u672c\u7684\u60c5\u51b5\u3002\u4f46\u662f\uff0c\u5982\u679c\u5df2\u7ecf\u4f7f\u7528\u4e86git reset\u6307\u4ee4\u6216\u8005git revert\u6307\u4ee4\u8fdb\u884c\u4e86\u7248\u672c\u56de\u9000\uff0c\u60f3\u8981\u518d\u6b21\u6062\u590d\u5230\u4e4b\u524d\u7684\u7248\u672c\uff0c\u662f\u5426\u8fd8\u6709\u53ef\u80fd\u5b9e\u73b0\u5462\uff1f\u672c\u6587\u5c06\u4e3a\u5927\u5bb6\u8be6\u7ec6\u5206\u6790\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0bgit reset\u548cgit revert\u8fd9\u4e24\u4e2a\u6307\u4ee4\u7684\u4f5c\u7528\u3002<\/p>\n<p>git reset\u6307\u4ee4\uff1a\u5c06\u5f53\u524d\u5206\u652f\u7684HEAD\u91cd\u7f6e\u5230\u6307\u5b9a\u7684commit\uff0c\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u5c06\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u76ee\u5f55\u4e5f\u91cd\u7f6e\u5230\u6307\u5b9acommit\u3002<\/p>\n<p>git revert\u6307\u4ee4\uff1a\u521b\u5efa\u4e00\u6b21\u65b0\u63d0\u4ea4\uff0c\u6765\u64a4\u9500\u4e4b\u524d\u7684\u63d0\u4ea4\uff0c\u53ef\u4ee5\u9009\u62e9\u64a4\u9500\u6307\u5b9a\u7684commit\u6216\u8005\u4e00\u7cfb\u5217\u7684commit\uff0c\u751f\u6210\u65b0\u7684\u63d0\u4ea4\u3002<\/p>\n<p>\u663e\u7136\uff0cgit reset\u6307\u4ee4\u4f1a\u4e22\u5931\u4e4b\u524d\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u5373\u4f7f\u5728\u4e4b\u524d\u4f7f\u7528\u4e86git log\u8fdb\u884c\u5b58\u50a8\u63d0\u4ea4\u5386\u53f2\uff0c\u4e5f\u65e0\u6cd5\u6062\u590d\u5230\u4e4b\u524d\u7684\u7248\u672c\u3002\u800cgit revert\u53ef\u4ee5\u64a4\u9500\u4e4b\u524d\u7684\u63d0\u4ea4\uff0c\u4f46\u662f\u4f1a\u751f\u6210\u4e00\u6b21\u65b0\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u4e4b\u524d\u7684\u63d0\u4ea4\u8bb0\u5f55\u4ecd\u7136\u5b58\u5728\u3002<\/p>\n<p><span>\u70b9\u51fb\u4e0b\u8f7d<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u90a3\u4e48\u5982\u679c\u5df2\u7ecf\u4f7f\u7528\u4e86git reset\u6307\u4ee4\uff0c\u662f\u5426\u8fd8\u6709\u53ef\u80fd\u627e\u56de\u4e4b\u524d\u7684\u7248\u672c\u5462\uff1f\u7b54\u6848\u662f\u6709\u53ef\u80fd\uff0c\u4f46\u662f\u9700\u8981\u6839\u636e\u4e0d\u540c\u60c5\u51b5\u6765\u9009\u62e9\u4e0d\u540c\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u573a\u666f\u4e00\uff1a\u5982\u679c\u5728\u91cd\u7f6e\u540e\uff0c\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u5176\u4ed6\u64cd\u4f5c\uff08\u4f8b\u5982\u5220\u9664\u6587\u4ef6\u3001\u65b0\u5efa\u6587\u4ef6\u7b49\uff09\uff0c\u90a3\u4e48\u53ef\u4ee5\u901a\u8fc7Git\u7684\u201c\u5f15\u7528\u201d\u673a\u5236\u6062\u590d\u3002<\/p>\n<p>1.\u9996\u5148\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684HEAD\u7684\u6307\u5411\uff1a<\/p>\n<pre>git reflog<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2.\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\u7684SHA-1\u503c\uff1a<\/p>\n<pre>git show HEAD@{n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0cn\u4e3a\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684\u7b2cn\u6b21commit\u3002<\/p>\n<p>3.\u91cd\u7f6e\u5230\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\uff1a<\/p>\n<pre>git reset HEAD@{n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>4.\u6b64\u65f6\u4f60\u5df2\u7ecf\u6062\u590d\u5230\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684\u7248\u672c\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u53d6\u56de\u4f60\u9700\u8981\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>git checkout HEAD -- FILENAME<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>FILENAME\u4e3a\u4f60\u9700\u8981\u627e\u56de\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u573a\u666f\u4e8c\uff1a\u5982\u679c\u5728\u91cd\u7f6e\u540e\u505a\u4e86\u5176\u4ed6\u64cd\u4f5c\uff08\u4f8b\u5982\u5220\u9664\u6587\u4ef6\u3001\u65b0\u5efa\u6587\u4ef6\u7b49\uff09\uff0c\u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u201c\u5f15\u7528\u201d\u673a\u5236\u6062\u590d\uff0c\u4f46\u662f\u9700\u8981\u91cd\u65b0checkout\u4e00\u4e0b\u4e4b\u524d\u7684\u63d0\u4ea4\u3002<\/p>\n<p>1.\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\u7684SHA-1\u503c\uff1a<\/p>\n<pre>git show HEAD@{n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2.checkout\u4e4b\u524d\u7684commit\uff1a<\/p>\n<pre>git checkout &lt;commit-sha&gt;&lt;\/commit-sha&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c \u4e3a\u4e4b\u524d\u7684commit\u7684SHA-1\u503c\u3002\u6b64\u65f6\u4f60\u5df2\u7ecf\u6062\u590d\u5230\u4e86\u4e4b\u524d\u7684\u7248\u672c\u3002 <\/p>\n<p>3.\u53d6\u56de\u4f60\u9700\u8981\u7684\u6587\u4ef6\uff1a<\/p>\n<pre>git checkout HEAD -- FILENAME<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5269\u4e0b\u7684\u6b65\u9aa4\u548c\u573a\u666f\u4e00\u4e00\u6837\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u65e0\u8bba\u662f\u573a\u666f\u4e00\u8fd8\u662f\u573a\u666f\u4e8c\uff0c\u90fd\u9700\u8981\u5728git reset\u4e4b\u540e\u5c3d\u5feb\u8fdb\u884c\u8fd8\u539f\uff0c\u5426\u5219\u5982\u679c\u8fdb\u884c\u4e86\u5176\u4ed6\u7684commit\uff0c\u5c31\u65e0\u6cd5\u518d\u56de\u9000\u5230\u4e4b\u524d\u7684\u7248\u672c\u4e86\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528git reset\u4e4b\u524d\uff0c\u5e94\u8be5\u786e\u8ba4\u597d\u64cd\u4f5c\u540e\u518d\u8fdb\u884c\u3002<\/p>\n<p>\u603b\u4e4b\uff0cgit\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u5728\u5904\u7406\u7248\u672c\u95ee\u9898\u65f6\u8fd8\u6709\u5f88\u591a\u5176\u4ed6\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u5206\u652f\u3001\u6807\u7b7e\u7b49\uff0c\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u89e3\u51b3\u65b9\u6848\u3002\u540c\u65f6\uff0c\u5e94\u8be5\u517b\u6210\u597d\u7684Git\u4f7f\u7528\u4e60\u60ef\uff0c\u53ca\u65f6\u5907\u4efd\u548ccommit\uff0c\u4ee5\u514d\u4e0d\u5fc5\u8981\u7684\u635f\u5931\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fgit\u8fd8\u539f\u5230\u6307\u5b9a\u7248\u672c\u8fd8\u80fd\u6062\u590d\u5417\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>\u5728\u4f7f\u7528git\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u9700\u8981\u8fd8\u539f\u5230\u67d0\u4e00\u4e2a\u7248\u672c\u7684\u60c5\u51b5\u3002\u4f46\u662f\uff0c\u5982\u679c\u5df2\u7ecf\u4f7f\u7528\u4e86git reset\u6307\u4ee4\u6216\u8005git revert\u6307\u4ee4\u8fdb\u884c\u4e86\u7248\u672c\u56de\u9000\uff0c\u60f3\u8981\u518d\u6b21\u6062\u590d\u5230\u4e4b\u524d\u7684\u7248\u672c\uff0c\u662f\u5426\u8fd8\u6709\u53ef\u80fd\u5b9e\u73b0\u5462\uff1f\u672c\u6587\u5c06\u4e3a\u5927\u5bb6\u8be6\u7ec6\u5206\u6790\u8fd9\u4e00\u95ee\u9898\u3002 \u9996\u5148\uff0c\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0bgit reset\u548cgit revert\u8fd9\u4e24\u4e2a\u6307\u4ee4\u7684\u4f5c\u7528\u3002 git reset\u6307\u4ee4\uff1a\u5c06\u5f53\u524d\u5206\u652f\u7684HEAD\u91cd\u7f6e\u5230\u6307\u5b9a\u7684commit\uff0c\u53ef\u4ee5\u9009\u62e9\u662f\u5426\u5c06\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u76ee\u5f55\u4e5f\u91cd\u7f6e\u5230\u6307\u5b9acommit\u3002 git revert\u6307\u4ee4\uff1a\u521b\u5efa\u4e00\u6b21\u65b0\u63d0\u4ea4\uff0c\u6765\u64a4\u9500\u4e4b\u524d\u7684\u63d0\u4ea4\uff0c\u53ef\u4ee5\u9009\u62e9\u64a4\u9500\u6307\u5b9a\u7684commit\u6216\u8005\u4e00\u7cfb\u5217\u7684commit\uff0c\u751f\u6210\u65b0\u7684\u63d0\u4ea4\u3002 \u663e\u7136\uff0cgit reset\u6307\u4ee4\u4f1a\u4e22\u5931\u4e4b\u524d\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u5373\u4f7f\u5728\u4e4b\u524d\u4f7f\u7528\u4e86git log\u8fdb\u884c\u5b58\u50a8\u63d0\u4ea4\u5386\u53f2\uff0c\u4e5f\u65e0\u6cd5\u6062\u590d\u5230\u4e4b\u524d\u7684\u7248\u672c\u3002\u800cgit revert\u53ef\u4ee5\u64a4\u9500\u4e4b\u524d\u7684\u63d0\u4ea4\uff0c\u4f46\u662f\u4f1a\u751f\u6210\u4e00\u6b21\u65b0\u7684\u63d0\u4ea4\u8bb0\u5f55\uff0c\u4e4b\u524d\u7684\u63d0\u4ea4\u8bb0\u5f55\u4ecd\u7136\u5b58\u5728\u3002 \u70b9\u51fb\u4e0b\u8f7d\u201c\u201d\uff1b \u90a3\u4e48\u5982\u679c\u5df2\u7ecf\u4f7f\u7528\u4e86git reset\u6307\u4ee4\uff0c\u662f\u5426\u8fd8\u6709\u53ef\u80fd\u627e\u56de\u4e4b\u524d\u7684\u7248\u672c\u5462\uff1f\u7b54\u6848\u662f\u6709\u53ef\u80fd\uff0c\u4f46\u662f\u9700\u8981\u6839\u636e\u4e0d\u540c\u60c5\u51b5\u6765\u9009\u62e9\u4e0d\u540c\u7684\u65b9\u6cd5\u3002 \u573a\u666f\u4e00\uff1a\u5982\u679c\u5728\u91cd\u7f6e\u540e\uff0c\u6ca1\u6709\u8fdb\u884c\u4efb\u4f55\u5176\u4ed6\u64cd\u4f5c\uff08\u4f8b\u5982\u5220\u9664\u6587\u4ef6\u3001\u65b0\u5efa\u6587\u4ef6\u7b49\uff09\uff0c\u90a3\u4e48\u53ef\u4ee5\u901a\u8fc7Git\u7684\u201c\u5f15\u7528\u201d\u673a\u5236\u6062\u590d\u3002 1.\u9996\u5148\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684HEAD\u7684\u6307\u5411\uff1a git reflog \u767b\u5f55\u540e\u590d\u5236 2.\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\u7684SHA-1\u503c\uff1a git show HEAD@{n} \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0cn\u4e3a\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684\u7b2cn\u6b21commit\u3002 3.\u91cd\u7f6e\u5230\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\uff1a git reset HEAD@{n} \u767b\u5f55\u540e\u590d\u5236 4.\u6b64\u65f6\u4f60\u5df2\u7ecf\u6062\u590d\u5230\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684\u7248\u672c\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u53d6\u56de\u4f60\u9700\u8981\u7684\u6587\u4ef6\uff1a git checkout HEAD &#8212; FILENAME \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 FILENAME\u4e3a\u4f60\u9700\u8981\u627e\u56de\u7684\u6587\u4ef6\u3002 \u573a\u666f\u4e8c\uff1a\u5982\u679c\u5728\u91cd\u7f6e\u540e\u505a\u4e86\u5176\u4ed6\u64cd\u4f5c\uff08\u4f8b\u5982\u5220\u9664\u6587\u4ef6\u3001\u65b0\u5efa\u6587\u4ef6\u7b49\uff09\uff0c\u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u201c\u5f15\u7528\u201d\u673a\u5236\u6062\u590d\uff0c\u4f46\u662f\u9700\u8981\u91cd\u65b0checkout\u4e00\u4e0b\u4e4b\u524d\u7684\u63d0\u4ea4\u3002 1.\u67e5\u770b\u4f60\u91cd\u7f6e\u4e4b\u524d\u7684commit\u7684SHA-1\u503c\uff1a git show HEAD@{n} \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 2.checkout\u4e4b\u524d\u7684commit\uff1a git checkout &lt;commit-sha&gt;&lt;\/commit-sha&gt; \u767b\u5f55\u540e\u590d\u5236 [&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-20265","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20265","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=20265"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/20265\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=20265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=20265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=20265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}