{"id":1944,"date":"2023-11-02T23:12:31","date_gmt":"2023-11-02T15:12:31","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1944"},"modified":"2023-11-02T23:12:33","modified_gmt":"2023-11-02T15:12:33","slug":"git-bi-bei-ming-lingche-xiaoresetrevertcheckout","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1944","title":{"rendered":"Git\u5fc5\u5907\u547d\u4ee4-\u64a4\u9500-reset&#038;revert&#038;checkout"},"content":{"rendered":"<p>\u5e73\u65f6\u5199\u4ee3\u7801\u7248\u672c\u7ba1\u7406\u5de5\u5177\u4e00\u822c\u662f git \uff0c\u6709\u65f6\u5019\u65e0\u6cd5\u907f\u514d\u9700\u8981\u4e00\u4e9b\u201c\u56de\u9000\u201d\u64cd\u4f5c\uff0cgit \u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\uff1acheckout  \u3001restore\u3001reset \u3001 revert \u7b49\u547d\u4ee4\u3002\u8fd9\u6b21\u6211\u4eec\u53ea\u8bb2 git checkout \/ git reset \/ git revert \u4e09\u4e2a\u3002<br \/>\n\u9996\u5148\u56de\u987e\u4e00\u4e0b git \u7684\u7ec4\u6210\uff1a\u5de5\u4f5c\u533a\u3001\u6682\u5b58\u533a\u3001\u672c\u5730\u4ed3\u5e93\u3001\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/p>\n<h2><a id=\"git-checkout%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Git checkout\uff1a<\/h2>\n<p>\u5b83\u771f\u662f\u4e00\u4e2a\u591a\u9762\u624b\u547d\u4ee4\uff0c\u53ef\u4ee5\u8ba9\u4f60\u5728\u5206\u652f\u4e4b\u95f4\u6765\u56de\u5207\u6362\uff0c\u8fd8\u53ef\u4ee5\u67e5\u770b\u67d0\u4e2a commit \u540c\u65f6\u8fd8\u53ef\u4ee5\u56de\u64a4\u672c\u5730\u6ca1\u6709 commit \u7684\u5185\u5bb9\u3002<\/p>\n<p>\u5207\u6362\u5206\u652f\uff1a<\/p>\n<pre><code class=\"language-plain_text\">git checkout [branch-name]\n<\/code><\/pre>\n<p>\u67e5\u770b\u67d0\u4e2a commit :<\/p>\n<pre><code class=\"language-plain_text\">git checkout [SHA]\n<\/code><\/pre>\n<p>\u4f7f\u7528\u6570\u5b57\u6765\u67e5\u770b\u524d\u9762\u67d0\u4e2a commit :<\/p>\n<pre><code class=\"language-plain_text\">git checkout HEAD~[num-of-commits-back]\n<\/code><\/pre>\n<p>\u6ce8\uff1a<\/p>\n<ol>\n<li>\u5728\u5207\u6362\u5230\u4e0d\u540c\u5206\u652f\u6216 commit \u65f6\uff0c\u9700\u8981\u628a\u5f53\u524d\u5206\u652f\u7684\u5185\u5bb9 commit \u6216\u8005 stash \u6389\uff0c\u4ee5\u514d\u4e22\u5931\u3002<\/li>\n<li>\u5728\u5207\u6362\u5230\u67d0\u4e2a commit \u540e\uff0c\u6700\u597d\u53ea\u7528\u6765\u67e5\u9605\u4ee3\u7801\u800c\u4e0d\u8981\u4fee\u6539\uff0c\u8fd9\u662f\u56e0\u4e3a\u5f53\u4f60\u5207\u6362\u5206\u652f\u7684\u65f6\u5019\u5c06\u4f1a\u4e22\u5931\u4fee\u6539\u7684\u5185\u5bb9\u3002\u82e5\u771f\u60f3\u4fee\u6539\uff0c\u5efa\u8bae\u4ece\u5f53\u524d\u8282\u70b9\u65b0\u5efa\u5206\u652f\u3002<\/li>\n<\/ol>\n<p>\u64a4\u9500\u5de5\u4f5c\u533a\u6240\u6709\u7684\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-plain_text\">git checkout .\n<\/code><\/pre>\n<p>\u64a4\u9500\u67d0\u4e2a\u6307\u5b9a\u6587\u4ef6\u7684\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-plain_text\">git checkout -- [file-name]\n<\/code><\/pre>\n<h2><a id=\"git-revert\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Git revert:<\/h2>\n<p>\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u89c4\u4e14\u5b89\u5168\u7684\u201c\u56de\u9000\u201d\u64cd\u4f5c\u3002Git revert \u662f\u4f7f\u7528\u4e00\u4e2a\u65b0\u7684 commit \u6765\u8986\u76d6\u4e4b\u524d\u7684 commit \u3002\u8fd9\u4e2a\u547d\u4ee4\u5b89\u5168\u4f53\u73b0\u5728\u9996\u5148\u5b83\u4e0d\u66f4\u6539\u4e4b\u524d\u7684\u63d0\u4ea4\u5386\u53f2\uff0c\u518d\u6b21\u5b83\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684 commit \u4fdd\u8bc1\u5b8c\u6574\u4ee5\u53ca\u53ef\u8ffd\u6eaf \u3002\u6bd4\u5982\u5f53\u4f60\u5728\u67e5\u8be2\u4e00\u4e2a bug \u4ea7\u751f\u7684\u95ee\u9898\u65f6\uff0c\u5b9a\u4f4d\u5230\u662f\u4e4b\u524d\u67d0\u6b21 commit \u5bfc\u81f4\u7684\u3002\u6709\u4e24\u79cd\u505a\u6cd5\uff1a1.\u624b\u52a8\u4fee\u6539\u4ee3\u7801\uff0c2.\u4f7f\u7528 revert \u81ea\u52a8\u201c\u64a4\u9500\u201d \u90a3\u6b21 commit \u3002<\/p>\n<p>\u64a4\u9500\u67d0\u4e2a commit :<\/p>\n<pre><code class=\"language-plain_text\">git revert [SHA]\n<\/code><\/pre>\n<p>\u4f7f\u7528\u6570\u5b57\u6765\u64a4\u9500\u524d\u9762\u67d0\u4e2a commit :<\/p>\n<pre><code class=\"language-plain_text\">git revert HEAD~[num-of-commits-back]\n<\/code><\/pre>\n<h2><a id=\"git-reset\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Git reset:<\/h2>\n<p>\u8fd9\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u4e14\u7a0d\u5fae\u6709\u70b9\u590d\u6742\u7684\u547d\u4ee4\u3002\u5176\u4e2d\u6709\u4e09\u4e2a\u53ef\u9009\u53c2\u6570\uff1a<br \/>\n<strong>&#8211;mixed<\/strong><br \/>\n\u8fd9\u662f\u9ed8\u8ba4\u53c2\u6570\uff0c\u5b83\u53ef\u4ee5\u628a HEAD \u6307\u5411\u7279\u5b9a\u7684 commit \u540c\u65f6\u628a commit \u4e4b\u540e\u7684\u63d0\u4ea4\u6539\u4e3a\u6ca1\u6709\u88ab\u7d22\u5f15\u72b6\u6001\u4e5f\u5c31\u662f\u628a\u6587\u4ef6\u653e\u5230\u5de5\u4f5c\u533a\u3002<\/p>\n<p><strong>&#8211;soft<\/strong><br \/>\n\u548c mixed \u5f88\u50cf\u628a HEAD \u6307\u5411\u7279\u5b9a\u7684 commit \uff0c\u4e0d\u540c\u7684\u662f\u4e4b\u540e\u7684\u63d0\u4ea4\u6539\u4e3a\u5df2\u7ecf\u88ab\u7d22\u5f15\u72b6\u6001\u4e5f\u5c31\u662f\u628a\u6587\u4ef6\u653e\u5230\u6682\u5b58\u533a\u3002<\/p>\n<p><strong>&#8211;hard<\/strong><br \/>\n\u8fd9\u4e2a\u53c2\u6570\u8981\u614e\u91cd\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4e22\u5f03\u6389\u7279\u5b9a commit \u540e\u7684\u6240\u6709\u63d0\u4ea4\uff0c\u4e5f\u5c31\u662f\u4e0d\u4f1a\u5728\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u7559\u526f\u672c\u3002<\/p>\n<p>\u6ce8\uff1a<br \/>\n\u56e2\u961f\u5408\u4f5c\u5c3d\u91cf\u907f\u514d\u4f7f\u7528 hard \u6a21\u5f0f\u3002<\/p>\n<p>\u53c2\u8003\uff1a<br \/>\n<a href=\"https:\/\/querix.com\/go\/lycia\/Content\/05_workbench\/01_ls\/04_how_to\/10_repo\/git\/00_intro.htm\" target=\"_blank\" rel=\"noopener\">https:\/\/querix.com\/go\/lycia\/Content\/05_workbench\/01_ls\/04_how_to\/10_repo\/git\/00_intro.htm<\/a><br \/>\n<a href=\"https:\/\/marklodato.github.io\/visual-git-guide\/index-en.html\" target=\"_blank\" rel=\"noopener\">https:\/\/marklodato.github.io\/visual-git-guide\/index-en.html<\/a><br \/>\n<a href=\"https:\/\/dev.to\/milu_franz\/git-explained-the-basics-igc\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/milu_franz\/git-explained-the-basics-igc<\/a><br \/>\n<a href=\"https:\/\/www.pixelstech.net\/article\/1549115148-git-reset-vs-git-revert\" target=\"_blank\" rel=\"noopener\">https:\/\/www.pixelstech.net\/article\/1549115148-git-reset-vs-git-revert<\/a><br \/>\n<a href=\"https:\/\/www.atlassian.com\/git\/tutorials\/undoing-changes\" target=\"_blank\" rel=\"noopener\">https:\/\/www.atlassian.com\/git\/tutorials\/undoing-changes<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/8358035\/whats-the-difference-between-git-revert-checkout-and-reset\" target=\"_blank\" rel=\"noopener\">https:\/\/stackoverflow.com\/questions\/8358035\/whats-the-difference-between-git-revert-checkout-and-reset<\/a><br \/>\n<a href=\"https:\/\/blog.csdn.net\/yxlshk\/article\/details\/79944535\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.csdn.net\/yxlshk\/article\/details\/79944535<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e73\u65f6\u5199\u4ee3\u7801\u7248\u672c\u7ba1\u7406\u5de5\u5177\u4e00\u822c\u662f git \uff0c\u6709\u65f6\u5019\u65e0\u6cd5\u907f\u514d\u9700\u8981\u4e00\u4e9b\u201c\u56de\u9000\u201d\u64cd\u4f5c\uff0cgit \u7ed9\u6211\u4eec\u63d0\u4f9b\u4e86\uff1ac&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,27,3],"tags":[28],"class_list":["post-1944","post","type-post","status-publish","format-standard","hentry","category-all","category-tool","category-tech","tag-git"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1944"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1944\/revisions"}],"predecessor-version":[{"id":1945,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1944\/revisions\/1945"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}