{"id":151346,"date":"2019-07-27T08:00:57","date_gmt":"2019-07-27T00:00:57","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=151346"},"modified":"2019-07-21T20:57:20","modified_gmt":"2019-07-21T12:57:20","slug":"git-revert-back","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/git-revert-back.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Git \u4f18\u96c5\u7684\u7248\u672c\u56de\u9000\u5462\uff1f"},"content":{"rendered":"
\n
\u4ecb\u7ecd<\/strong><\/div>\n

\u5728\u7248\u672c\u8fed\u4ee3\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u4f1a\u6709\u8fc7\u9519\u8bef\u63d0\u4ea4\u7684\u65f6\u5019\uff08\u81f3\u5c11\u826f\u8bb8\u6709\u8fc7\u51e0\u6b21\u8fd9\u6837\u7684\u4f53\u9a8c\uff09\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u83dc\u9e1f\u7a0b\u5e8f\u5458\u53ef\u80fd\u5c31\u4f1a\u864e\u9a71\u4e00\u9707\uff0c\u7d27\u5f20\u5f97\u4e0d\u77e5\u6240\u63aa\u3002\u800c\u8d44\u6df1\u7a0b\u5e8f\u5458\u5c31\u4f1a\u5fae\u5fae\u4e00\u7b11\uff0c\u6478\u4e00\u6478\u9503\u4eae\u7684\u8111\u95e8\uff0c\u7136\u540e\u9ed8\u9ed8\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\u3002<\/p>\n

\u5bf9\u4e8e\u7248\u672c\u7684\u56de\u9000\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u7528\u5230\u4e24\u4e2a\u547d\u4ee4\uff1a<\/p>\n

    \n
  1. git reset<\/li>\n
  2. git revert<\/li>\n<\/ol>\n

    \u90a3\u8fd9\u4e24\u4e2a\u547d\u4ee4\u6709\u4f55\u533a\u522b\u5462\uff1f\u5148\u4e0d\u6025\uff0c\u6211\u4eec\u540e\u6587\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n

    git reset<\/strong><\/div>\n

    \u5047\u5982\u6211\u4eec\u7684\u7cfb\u7edf\u73b0\u5728\u6709\u5982\u4e0b\u51e0\u4e2a\u63d0\u4ea4\uff1a<\/p>\n

    \n
    \n
    \"\"<\/a><\/div>\n<\/div>\n
    Git\u5982\u4f55\u4f18\u96c5\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\uff1f<\/div>\n<\/div>\n

    \u5176\u4e2d\uff1aA \u548c B \u662f\u6b63\u5e38\u63d0\u4ea4\uff0c\u800c C \u548c D \u662f\u9519\u8bef\u63d0\u4ea4\u3002\u73b0\u5728\uff0c\u6211\u4eec\u60f3\u628a C \u548c D \u56de\u9000\u6389\u3002\u800c\u6b64\u65f6\uff0cHEAD \u6307\u9488\u6307\u5411 D \u63d0\u4ea4\uff085lk4er\uff09\u3002\u6211\u4eec\u53ea\u9700\u5c06 HEAD \u6307\u9488\u79fb\u52a8\u5230 B \u63d0\u4ea4\uff08a0fvf8\uff09\uff0c\u5c31\u53ef\u4ee5\u8fbe\u5230\u76ee\u7684\u3002<\/p>\n

    \u53ea\u8981\u6709 git \u57fa\u7840\u7684\u670b\u53cb\uff0c\u4e00\u5b9a\u4f1a\u60f3\u5230 git reset \u547d\u4ee4\u3002\u5b8c\u6574\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n

    git reset --hard a0fvf8\r\n<\/code><\/pre>\n

    \u547d\u4ee4\u8fd0\u884c\u4e4b\u540e\uff0cHEAD \u6307\u9488\u5c31\u4f1a\u79fb\u52a8\u5230 B \u63d0\u4ea4\u4e0b\uff0c\u5982\u4e0b\u56fe\u793a\uff1a<\/p>\n

    \n
    \n
    \"\"<\/a><\/div>\n<\/div>\n
    Git\u5982\u4f55\u4f18\u96c5\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\uff1f<\/div>\n<\/div>\n

    \u800c\u8fd9\u4e2a\u65f6\u5019\uff0c\u8fdc\u7a0b\u4ed3\u5e93\u7684 HEAD \u6307\u9488\u4f9d\u7136\u4e0d\u53d8\uff0c\u4ecd\u5728 D \u63d0\u4ea4\u4e0a\u3002\u6240\u4ee5\uff0c\u5982\u679c\u76f4\u63a5\u4f7f\u7528 git push \u547d\u4ee4\u7684\u8bdd\uff0c\u5c06\u65e0\u6cd5\u5c06\u66f4\u6539\u63a8\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002\u6b64\u65f6\uff0c\u53ea\u80fd\u4f7f\u7528 -f \u9009\u9879\u5c06\u63d0\u4ea4\u5f3a\u5236\u63a8\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff1a<\/p>\n

    git push -f\r\n<\/code><\/pre>\n

    \u91c7\u7528\u8fd9\u79cd\u65b9\u5f0f\u56de\u9000\u4ee3\u7801\u7684\u5f0a\u7aef\u663e\u800c\u6613\u89c1\uff0c\u90a3\u5c31\u662f\u4f1a\u4f7f HEAD \u6307\u9488\u5f80\u56de\u79fb\u52a8\uff0c\u4ece\u800c\u4f1a\u5931\u53bb\u4e4b\u540e\u7684\u63d0\u4ea4\u4fe1\u606f\u3002\u5c06\u6765\u5982\u679c\u7a81\u7136\u53d1\u73b0\uff0cC \u548c D \u662f\u591a\u4e48\u7edd\u5999\u7684\u60f3\u6cd5\uff0c\u53ef\u5b83\u4eec\u5df2\u7ecf\u65e9\u5c31\u6d88\u5931\u5728\u5386\u53f2\u7684\u957f\u6cb3\u91cc\u4e86\u3002<\/p>\n

    \u800c\u4e14\uff0c\u6709\u4e9b\u516c\u53f8\uff08\u6bd4\u5982\u826f\u8bb8\u7684\u516c\u53f8\uff09\u660e\u4ee4\u7981\u6b62\u4f7f\u7528 git reset \u547d\u4ee4\u53bb\u56de\u9000\u4ee3\u7801\uff0c\u539f\u56e0\u4e0e\u4e0a\u8ff0\u4e00\u6837\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u9700\u8981\u627e\u5230\u4e00\u4e2a\u547d\u4ee4\uff0c\u65e2\u53ef\u4ee5\u56de\u9000\u4ee3\u7801\uff0c\u53c8\u53ef\u4ee5\u4fdd\u5b58\u9519\u8bef\u7684\u63d0\u4ea4\u3002\u8fd9\u65f6\uff0cgit revert \u547d\u4ee4\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n

    git revert<\/strong><\/div>\n

    git revert\u7684\u4f5c\u7528\u901a\u8fc7\u53cd\u505a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7248\u672c\uff0c\u8fd9\u4e2a\u7248\u672c\u7684\u5185\u5bb9\u4e0e\u6211\u4eec\u8981\u56de\u9000\u5230\u7684\u76ee\u6807\u7248\u672c\u4e00\u6837\uff0c\u4f46\u662fHEAD\u6307\u9488\u662f\u6307\u5411\u8fd9\u4e2a\u65b0\u751f\u6210\u7684\u7248\u672c\uff0c\u800c\u4e0d\u662f\u76ee\u6807\u7248\u672c\u3002<\/p>\n

    \u4f7f\u7528 git revert \u547d\u4ee4\u6765\u5b9e\u73b0\u4e0a\u8ff0\u4f8b\u5b50\u7684\u8bdd\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a\u5148 revert D\uff0c\u518d revert C \uff08\u6709\u591a\u4e2a\u63d0\u4ea4\u9700\u8981\u56de\u9000\u7684\u8bdd\u9700\u8981\u7531\u65b0\u5230\u65e7\u8fdb\u884c revert\uff09\uff1a<\/p>\n

    git revert 5lk4er\r\ngit revert 76sdeb\r\n<\/code><\/pre>\n

    \u8fd9\u91cc\u4f1a\u751f\u6210\u4e24\u4e2a\u65b0\u6709\u63d0\u4ea4\uff1aD' \u548c C'\uff0c\u5982\u4e0b\u56fe\u793a\uff1a<\/p>\n

    \n
    \n
    \"\"<\/a><\/div>\n<\/div>\n
    Git\u5982\u4f55\u4f18\u96c5\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\uff1f<\/div>\n<\/div>\n

    \u8fd9\u91cc\u53ea\u6709\u4e24\u4e2a\u63d0\u4ea4\u9700\u8981 revert\uff0c\u6211\u4eec\u53ef\u4ee5\u4e00\u4e2a\u4e2a\u56de\u9000\u3002\u4f46\u5982\u679c\u6709\u51e0\u5341\u4e2a\u5462\uff1f\u4e00\u4e2a\u4e2a\u56de\u9000\u80af\u5b9a\u6548\u7387\u592a\u4f4e\u800c\u4e14\u5bb9\u6613\u51fa\u9519\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u6279\u91cf\u56de\u9000\uff1a<\/p>\n

    git<\/span> revert<\/span> OLDER_COMMIT<\/span>^..NEWER_COMMIT<\/span>\r\n<\/code><\/pre>\n

    \u8fd9\u65f6\uff0c\u9519\u8bef\u7684\u63d0\u4ea4 C \u548c D \u4f9d\u7136\u4fdd\u7559\uff0c\u5c06\u6765\u8fdb\u884c\u7529\u9505\u7684\u65f6\u5019\u4e5f\u6709\u4f9d\u53ef\u5faa\u3002\u800c\u4e14\uff0c\u8fd9\u6837\u64cd\u4f5c\u7684\u8bdd HEAD \u6307\u9488\u662f\u5f80\u540e\u79fb\u52a8\u7684\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 git push \u547d\u4ee4\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u91cc\u3002\u800c\u8fd9\u79cd\u505a\u6cd5\uff0c\u6b63\u662f\u4f01\u4e1a\u6240\u9f13\u52b1\u7684\u3002<\/p>\n

    \u6211\u4eec\u518d\u4e3e\u4e2a\u66f4\u96be\u4e00\u70b9\u7684\u4f8b\u5b50\u3002<\/p>\n

    \u5047\u5982\u73b0\u5728\u6709\u4e09\u4e2a\u63d0\u4ea4\uff0c\u4f46\u5f88\u4e0d\u5de7\u7684\u662f\uff0c\u90a3\u4e2a\u9519\u8bef\u7684\u63d0\u4ea4\u521a\u597d\u4f4d\u4e8e\u4e2d\u95f4\u3002\u5982\u4e0b\u56fe\u793a\uff1a<\/p>\n

    \n
    \n
    \"\"<\/a><\/div>\n<\/div>\n
    Git\u5982\u4f55\u4f18\u96c5\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\uff1f<\/div>\n<\/div>\n

    \u8fd9\u65f6\uff0c\u76f4\u63a5\u4f7f\u7528 git reset \u547d\u4ee4\u5c06 HEAD \u6307\u9488\u91cd\u7f6e\u5230 A \u63d0\u4ea4\u663e\u7136\u662f\u4e0d\u884c\u7684\uff0c\u56e0\u4e3a C \u63d0\u4ea4\u662f\u6b63\u786e\u7684\uff0c\u9700\u8981\u4fdd\u7559\u7684\u3002\u5148\u628a C \u63d0\u4ea4 \u53ca B \u63d0\u4ea4\u5168\u90e8\u56de\u9000\uff0c\u518d\u4f7f\u7528 cherry-pick \u547d\u4ee4\u5c06 C \u63d0\u4ea4\u91cd\u65b0\u518d\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4 C''\uff0c\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u5c06 B\u63d0\u4ea4\u56de\u9000\u7684\u9700\u6c42\u3002\u5b8c\u6574\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n

    \n
    \n
    \"\"<\/a><\/div>\n<\/div>\n
    Git\u5982\u4f55\u4f18\u96c5\u7684\u8fdb\u884c\u7248\u672c\u56de\u9000\uff1f<\/div>\n<\/div>\n

    \u901a\u8fc7\u4ee5\u4e0a\u5bf9\u6bd4\u53ef\u4ee5\u53d1\u73b0\uff0cgit reset \u4e0e git revert \u6700\u5927\u7684\u5dee\u522b\u5c31\u5728\u4e8e\uff0cgit reset \u4f1a\u5931\u53bb\u540e\u9762\u7684\u63d0\u4ea4\uff0c\u800c git revert \u662f\u901a\u8fc7\u53cd\u505a\u7684\u65b9\u5f0f\u91cd\u65b0\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4\uff0c\u800c\u4fdd\u7559\u539f\u6709\u7684\u63d0\u4ea4\u3002\u5728\u4f01\u4e1a\u91cc\uff0c\u5e94\u5c3d\u91cf\u4f7f\u7528 git revert \u547d\u4ee4\uff0c\u80fd\u4e0d\u7528 git reset \u547d\u4ee4\u5c3d\u91cf\u4e0d\u7528\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

    \u5728\u7248\u672c\u8fed\u4ee3\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u4f1a\u6709\u8fc7\u9519\u8bef\u63d0\u4ea4\u7684\u65f6\u5019\uff08\u81f3\u5c11\u826f\u8bb8\u6709\u8fc7\u51e0\u6b21\u8fd9\u6837\u7684\u4f53\u9a8c\uff09\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u83dc\u9e1f\u7a0b\u5e8f\u5458\u53ef […]<\/p>\n","protected":false},"author":643,"featured_media":151354,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-151346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/151346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=151346"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/151346\/revisions"}],"predecessor-version":[{"id":151379,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/151346\/revisions\/151379"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/151354"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=151346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=151346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=151346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}