{"id":19324,"date":"2024-11-19T08:24:12","date_gmt":"2024-11-19T00:24:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/19324\/"},"modified":"2024-11-19T08:24:12","modified_gmt":"2024-11-19T00:24:12","slug":"git%e4%b8%ad%e5%a6%82%e4%bd%95%e5%8f%96%e6%b6%88-commit-%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/19324\/","title":{"rendered":"git\u4e2d\u5982\u4f55\u53d6\u6d88 commit \u64cd\u4f5c"},"content":{"rendered":"<p>\u5728\u4f7f\u7528 git \u8fdb\u884c\u7248\u672c\u63a7\u5236\u65f6\uff0ccommit \u64cd\u4f5c\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u6b65\uff0c\u5b83\u8868\u793a\u5c06\u5f53\u524d\u4ee3\u7801\u66f4\u6539\u4fdd\u5b58\u5230\u672c\u5730\u4ed3\u5e93\u4e2d\u3002\u7136\u800c\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u6709\u65f6\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u9700\u8981\u53d6\u6d88 commit \u64cd\u4f5c\u3002\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u53d6\u6d88 commit \u64cd\u4f5c\u3002<\/p>\n<p><strong>\u53d6\u6d88 add \u64cd\u4f5c<\/strong><\/p>\n<p>\u5728 git commit \u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 git add \u547d\u4ee4\u5c06\u6539\u52a8\u6dfb\u52a0\u5230 staging \u533a\u57df\uff0c\u51c6\u5907\u63d0\u4ea4\u3002\u5982\u679c\u6211\u4eec\u5728\u6267\u884c git add \u547d\u4ee4\u540e\uff0c\u53c8\u53d1\u73b0\u4fee\u6539\u9519\u8bef\uff0c\u4e0d\u60f3\u5c06\u6b64\u4fee\u6539\u63d0\u4ea4\u5230 staging \u533a\u57df\uff0c\u53ef\u4ee5\u901a\u8fc7\u6267\u884c git reset HEAD \u547d\u4ee4\u6765\u53d6\u6d88 add \u64cd\u4f5c\u3002\u8fd9\u6761\u547d\u4ee4\u4f1a\u5c06\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u4ece staging \u533a\u57df\u4e2d\u79fb\u9664\uff0c\u4f46\u4fdd\u7559\u5176\u5728\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u4fee\u6539\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u6267\u884c\u4e86\u5982\u4e0b\u547d\u4ee4\u6dfb\u52a0\u4e86\u4e00\u4e2a\u6587\u4ef6\u5230 staging \u533a\u57df\uff1a<\/p>\n<pre>git add index.html<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u73b0\u5728\u6211\u4eec\u4e0d\u60f3\u5c06\u6b64\u6587\u4ef6\u63d0\u4ea4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53d6\u6d88 add \u64cd\u4f5c\uff1a<\/p>\n<pre>git reset HEAD index.html<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u53d6\u6d88 commit \u64cd\u4f5c<\/strong><\/p>\n<p>\u5982\u679c\u6211\u4eec\u5df2\u7ecf\u6267\u884c\u4e86 commit \u64cd\u4f5c\uff0c\u4f46\u540e\u6765\u53d1\u73b0\u63d0\u4ea4\u4fe1\u606f\u6709\u9519\u8bef\u3001\u6216\u8005\u63d0\u4ea4\u7684\u5185\u5bb9\u6709\u8bef\uff0c\u9700\u8981\u91cd\u65b0\u4fee\u6539\u4e4b\u540e\u518d\u6b21\u63d0\u4ea4\uff0c\u8fd9\u65f6\u6211\u4eec\u5c31\u9700\u8981\u53d6\u6d88\u4e0a\u4e00\u6b21 commit \u64cd\u4f5c\u3002<\/p>\n<p>\u5728 git \u4e2d\uff0c\u6267\u884c\u53d6\u6d88 commit \u64cd\u4f5c\u4e00\u822c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528 git revert \u547d\u4ee4\u6216\u4f7f\u7528 git reset \u547d\u4ee4\u3002<\/p>\n<p><strong>\u4f7f\u7528 git revert \u547d\u4ee4<\/strong><\/p>\n<p>git revert \u547d\u4ee4\u7528\u6765\u64a4\u9500\u67d0\u6b21\u63d0\u4ea4\uff0c\u5b83\u4e0d\u4f1a\u6539\u53d8\u63d0\u4ea4\u5386\u53f2\uff0c\u800c\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4\u6765\u64a4\u9500\u4e4b\u524d\u7684\u63d0\u4ea4\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u4e8e\u5df2\u7ecf\u5c06\u4ee3\u7801\u63a8\u9001\u81f3\u516c\u5171\u4ed3\u5e93\u4e2d\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u3002<\/p>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u64a4\u9500\u67d0\u4e2a\u63d0\u4ea4\uff1a<\/p>\n<pre>git revert &lt;commit-id&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff0ccommit-id \u8868\u793a\u9700\u8981\u88ab\u53d6\u6d88\u7684\u90a3\u6b21\u63d0\u4ea4\u7684 ID \u53f7\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u8981\u64a4\u9500\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>git revert HEAD<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u6267\u884c\u6b64\u547d\u4ee4\u540e\uff0cgit \u4f1a\u6253\u5f00\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\uff0c\u8ba9\u4f60\u7f16\u8f91\u63d0\u4ea4\u4fe1\u606f\uff0c\u5e76\u786e\u8ba4\u64a4\u9500\u64cd\u4f5c\u3002<\/p>\n<p>\u5982\u679c\u8981\u64a4\u9500\u591a\u4e2a\u63d0\u4ea4\uff0c\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a commit-id \uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>git revert &lt;commit-id1&gt; &lt;commit-id2&gt; &lt;commit-id3&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4f7f\u7528 git reset \u547d\u4ee4<\/strong><\/p>\n<p>git reset \u547d\u4ee4\u4e5f\u53ef\u4ee5\u7528\u6765\u53d6\u6d88 commit \u64cd\u4f5c\uff0c\u4e0d\u8fc7\u5b83\u4f1a\u6539\u53d8\u63d0\u4ea4\u5386\u53f2\uff0c\u56e0\u6b64\u53ea\u9002\u7528\u4e8e\u672c\u5730\u4ed3\u5e93\u4e2d\u7684\u64cd\u4f5c\uff0c\u4e0d\u80fd\u7528\u4e8e\u5df2\u7ecf\u63a8\u9001\u81f3\u8fdc\u7a0b\u4ed3\u5e93\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u64a4\u9500\u67d0\u4e2a\u63d0\u4ea4\uff1a<\/p>\n<pre>git reset &lt;commit-id&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5176\u4e2d\uff0ccommit-id \u8868\u793a\u9700\u8981\u88ab\u53d6\u6d88\u7684\u90a3\u6b21\u63d0\u4ea4\u7684 ID \u53f7\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u8981\u64a4\u9500\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\uff0c\u53ef\u4ee5\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>\u6267\u884c\u6b64\u547d\u4ee4\u540e\uff0c\u6700\u65b0\u4e00\u6b21\u63d0\u4ea4\u4f1a\u88ab\u79fb\u9664\uff0c\u5e76\u5c06\u5176\u4fee\u6539\u5185\u5bb9\u4fdd\u7559\u5728\u5de5\u4f5c\u76ee\u5f55\u4e2d\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53ea\u662f\u5c06 commit \u64cd\u4f5c\u64a4\u9500\u4e86\uff0c\u5bf9\u5e94\u7684\u4ee3\u7801\u66f4\u6539\u5e76\u672a\u88ab\u5220\u9664\u3002\u5982\u679c\u4f60\u9700\u8981\u5c06\u4ee3\u7801\u56de\u6eda\u5230\u67d0\u4e2a\u5177\u4f53\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528 git checkout \u547d\u4ee4\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u53d6\u6d88 Git \u4e2d\u7684 commit \u64cd\u4f5c\uff0c\u5305\u62ec\u53d6\u6d88 add \u64cd\u4f5c\u3001\u4f7f\u7528 git revert \u548c git reset \u547d\u4ee4\u6765\u64a4\u9500 commit \u64cd\u4f5c\u3002\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u786e\u4fdd\u4ee3\u7801\u7248\u672c\u63a7\u5236\u65e0\u8bef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fgit\u4e2d\u5982\u4f55\u53d6\u6d88 commit \u64cd\u4f5c\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\u7528 git \u8fdb\u884c\u7248\u672c\u63a7\u5236\u65f6\uff0ccommit \u64cd\u4f5c\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u6b65\uff0c\u5b83\u8868\u793a\u5c06\u5f53\u524d\u4ee3\u7801\u66f4\u6539\u4fdd\u5b58\u5230\u672c\u5730\u4ed3\u5e93\u4e2d\u3002\u7136\u800c\uff0c\u5728\u5b9e\u9645\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u6709\u65f6\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\uff0c\u9700\u8981\u53d6\u6d88 commit \u64cd\u4f5c\u3002\u672c\u6587\u5c06\u4f1a\u4ecb\u7ecd\u5982\u4f55\u53d6\u6d88 commit \u64cd\u4f5c\u3002 \u53d6\u6d88 add \u64cd\u4f5c \u5728 git commit \u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 git add \u547d\u4ee4\u5c06\u6539\u52a8\u6dfb\u52a0\u5230 staging \u533a\u57df\uff0c\u51c6\u5907\u63d0\u4ea4\u3002\u5982\u679c\u6211\u4eec\u5728\u6267\u884c git add \u547d\u4ee4\u540e\uff0c\u53c8\u53d1\u73b0\u4fee\u6539\u9519\u8bef\uff0c\u4e0d\u60f3\u5c06\u6b64\u4fee\u6539\u63d0\u4ea4\u5230 staging \u533a\u57df\uff0c\u53ef\u4ee5\u901a\u8fc7\u6267\u884c git reset HEAD \u547d\u4ee4\u6765\u53d6\u6d88 add \u64cd\u4f5c\u3002\u8fd9\u6761\u547d\u4ee4\u4f1a\u5c06\u6307\u5b9a\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u4ece staging \u533a\u57df\u4e2d\u79fb\u9664\uff0c\u4f46\u4fdd\u7559\u5176\u5728\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u4fee\u6539\u3002 \u4f8b\u5982\uff0c\u6211\u4eec\u6267\u884c\u4e86\u5982\u4e0b\u547d\u4ee4\u6dfb\u52a0\u4e86\u4e00\u4e2a\u6587\u4ef6\u5230 staging \u533a\u57df\uff1a git add index.html \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\u6211\u4eec\u4e0d\u60f3\u5c06\u6b64\u6587\u4ef6\u63d0\u4ea4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53d6\u6d88 add \u64cd\u4f5c\uff1a git reset HEAD index.html \u767b\u5f55\u540e\u590d\u5236 \u53d6\u6d88 commit \u64cd\u4f5c \u5982\u679c\u6211\u4eec\u5df2\u7ecf\u6267\u884c\u4e86 commit \u64cd\u4f5c\uff0c\u4f46\u540e\u6765\u53d1\u73b0\u63d0\u4ea4\u4fe1\u606f\u6709\u9519\u8bef\u3001\u6216\u8005\u63d0\u4ea4\u7684\u5185\u5bb9\u6709\u8bef\uff0c\u9700\u8981\u91cd\u65b0\u4fee\u6539\u4e4b\u540e\u518d\u6b21\u63d0\u4ea4\uff0c\u8fd9\u65f6\u6211\u4eec\u5c31\u9700\u8981\u53d6\u6d88\u4e0a\u4e00\u6b21 commit [&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-19324","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19324","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=19324"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19324\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=19324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=19324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=19324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}