{"id":54946,"date":"2023-09-22T19:38:59","date_gmt":"2023-09-22T11:38:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=54946"},"modified":"2023-09-23T20:04:11","modified_gmt":"2023-09-23T12:04:11","slug":"git-reset%e5%90%8e%e5%a6%82%e4%bd%95%e6%89%be%e5%9b%9e%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/54946.html","title":{"rendered":"git reset\u540e\u5982\u4f55\u627e\u56de\u4ee3\u7801"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u5728\u4f7f\u7528git reset\u540e\u6062\u590d\u4e22\u5931\u4ee3\u7801\u7684\u6b65\u9aa4\uff1a\u4e00\u3001\u7406\u89e3git reset\u7684\u4f5c\u7528\uff1b\u4e8c\u3001\u4f7f\u7528reflog\u67e5\u627e\u4e22\u5931\u63d0\u4ea4\uff1b\u4e09\u3001\u5229\u7528checkout\u547d\u4ee4\u6062\u590d\u4ee3\u7801\uff1b\u56db\u3001\u786e\u4fdd\u4ee3\u7801\u5b89\u5168\u3002\u200b\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u56e0\u8bef\u64cd\u4f5c\u6216\u5176\u4ed6\u539f\u56e0\u4f7f\u7528\u4e86git reset\u547d\u4ee4\uff0c\u4ece\u800c\u5bfc\u81f4\u4ee3\u7801\u4e22\u5931\uff0c\u6062\u590d\u4e22\u5931\u4ee3\u7801\u7684\u5173\u952e\u5728\u4e8e\u5bf9git\u5185\u90e8\u673a\u5236\u7684\u7406\u89e3\u4ee5\u53ca\u6b63\u786e\u7684\u64cd\u4f5c\u6b65\u9aa4\u3002<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"680\" height=\"421\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/09\/680-90.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-54948\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u7406\u89e3git reset\u7684\u4f5c\u7528 <\/h2>\n\n\n\n<p>git reset\u662fGit\u4e2d\u7684\u4e00\u4e2a\u547d\u4ee4\uff0c\u7528\u4e8e\u5c06\u5f53\u524dHEAD\u91cd\u7f6e\u5230\u6307\u5b9a\u72b6\u6001\u3002\u6709\u4e09\u79cd\u6a21\u5f0f\uff1asoft\u3001mixed\u548chard\uff0c\u5176\u4e2dhard\u6a21\u5f0f\u4f1a\u91cd\u7f6e\u5de5\u4f5c\u76ee\u5f55\u5230\u67d0\u4e00\u63d0\u4ea4\uff0c\u4ece\u800c\u53ef\u80fd\u5bfc\u81f4\u4ee3\u7801\u7684\u4e22\u5931\u3002\u5f53\u5f00\u53d1\u8005\u53d1\u73b0\u8bef\u64cd\u4f5c\u540e\uff0c\u4e0d\u8981\u614c\uff0c\u56e0\u4e3agit\u5728\u5185\u90e8\u4fdd\u5b58\u4e86\u4e00\u4e2a\u5f15\u7528\u65e5\u5fd7\uff0c\u5e2e\u52a9\u6211\u4eec\u627e\u56de\u4e22\u5931\u7684\u63d0\u4ea4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u4f7f\u7528reflog\u67e5\u627e\u4e22\u5931\u63d0\u4ea4 <\/h2>\n\n\n\n<p>git reflog\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u547d\u4ee4\uff0c\u5b83\u4f1a\u5c55\u793a\u5f53\u524d\u4ed3\u5e93\u7684\u5f15\u7528\u65e5\u5fd7\u3002\u6bcf\u5f53HEAD\u3001\u5206\u652f\u6216\u5176\u4ed6\u5f15\u7528\u53d1\u751f\u53d8\u5316\u65f6\uff0cGit\u90fd\u4f1a\u5728\u5f15\u7528\u65e5\u5fd7\u4e2d\u8bb0\u5f55\u3002\u8f93\u5165<code>git reflog<\/code>\u547d\u4ee4\uff0c\u4f60\u4f1a\u770b\u5230\u4e00\u4e2a\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6240\u6709\u7684\u63d0\u4ea4\u54c8\u5e0c\u548c\u5bf9\u5e94\u7684\u64cd\u4f5c\u3002\u627e\u5230\u4f60\u4e22\u5931\u4ee3\u7801\u4e4b\u524d\u7684\u90a3\u6b21\u63d0\u4ea4\uff0c\u8bb0\u4e0b\u5176\u54c8\u5e0c\u503c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5229\u7528checkout\u547d\u4ee4\u6062\u590d\u4ee3\u7801 <\/h2>\n\n\n\n<p>\u62e5\u6709\u4e86\u6b63\u786e\u7684\u63d0\u4ea4\u54c8\u5e0c\u503c\u540e\uff0c\u4f7f\u7528<code>git checkout<\/code>\u547d\u4ee4\u5c06\u4ee3\u7801\u6062\u590d\u5230\u8be5\u72b6\u6001\u3002\u4f8b\u5982\uff0c\u5982\u679c\u54c8\u5e0c\u503c\u662fabcdef1234\uff0c\u90a3\u4e48\u53ea\u9700\u8f93\u5165<code>git checkout abcdef1234<\/code>\u5373\u53ef\u3002\u6b64\u65f6\uff0c\u4f60\u4f1a\u5904\u4e8e\u4e00\u4e2a&#8221;detached HEAD&#8221;\u72b6\u6001\u3002\u4e3a\u4e86\u907f\u514d\u5728\u6b64\u57fa\u7840\u4e0a\u7ee7\u7eed\u5de5\u4f5c\uff0c\u6700\u597d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff1a<code>git checkout -b recover-branch<\/code>\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u5728\u8fd9\u4e2a\u65b0\u5206\u652f\u4e0a\u7ee7\u7eed\u4f60\u7684\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u786e\u4fdd\u4ee3\u7801\u5b89\u5168 <\/h2>\n\n\n\n<p>\u5728\u6062\u590d\u4ee3\u7801\u540e\uff0c\u4e3a\u4e86\u9632\u6b62\u672a\u6765\u518d\u6b21\u53d1\u751f\u7c7b\u4f3c\u60c5\u51b5\uff0c\u5efa\u8bae\u91c7\u7528\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u6cd5\u4fdd\u62a4\u4ee3\u7801\uff1a a. \u5b9a\u671f\u5907\u4efd\u4ed3\u5e93\uff1a\u867d\u7136Git\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\uff0c\u4f46\u6709\u65f6\u8fdb\u884c\u672c\u5730\u6216\u5916\u90e8\u5907\u4efd\u4e5f\u662f\u4e00\u4e2a\u597d\u4e60\u60ef\u3002 b. \u907f\u514d\u76f4\u63a5\u5728\u4e3b\u5206\u652f\u4e0a\u5f00\u53d1\uff1a\u5c3d\u91cf\u4e3a\u6bcf\u4e2a\u529f\u80fd\u6216\u4fee\u590d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\u3002 c. \u5b9a\u671f\u4e0e\u56e2\u961f\u6210\u5458\u540c\u6b65\uff0c\u786e\u4fdd\u6bcf\u4e2a\u4eba\u90fd\u4e86\u89e3\u548c\u9075\u5faa\u56e2\u961f\u7684Git\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n\n\n\n<p>\u603b\u7ed3\uff1a\u5728\u4f7f\u7528git reset\u5bfc\u81f4\u4ee3\u7801\u4e22\u5931\u540e\uff0c\u4e0d\u5fc5\u592a\u8fc7\u62c5\u5fc3\u3002\u53ea\u8981\u6309\u7167\u6b63\u786e\u7684\u6b65\u9aa4\u64cd\u4f5c\uff0c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u90fd\u53ef\u4ee5\u6210\u529f\u6062\u590d\u3002\u91cd\u8981\u7684\u662f\u7406\u89e3Git\u7684\u5185\u90e8\u673a\u5236\uff0c\u5e76\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\u91c7\u53d6\u9884\u9632\u63aa\u65bd\uff0c\u786e\u4fdd\u4ee3\u7801\u5b89\u5168\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\" \/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u7b54\uff1a<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-layout-1 wp-block-group-is-layout-flex\">\n<p><strong>Q1: \u4e3a\u4ec0\u4e48\u5728\u6267\u884c<code>git reset<\/code>\u540e\u6211\u7684\u4ee3\u7801\u4f1a\u4e22\u5931\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u7b54<\/strong>: \u5f53\u4f60\u6267\u884c<code>git reset<\/code>\u547d\u4ee4\u65f6\uff0c\u4f60\u5b9e\u9645\u4e0a\u662f\u5728\u79fb\u52a8<code>HEAD<\/code>\u548c\u5f53\u524d\u5206\u652f\u7684\u6307\u9488\u5230\u4e00\u4e2a\u6307\u5b9a\u7684\u63d0\u4ea4\u3002\u6839\u636e\u4f60\u4f7f\u7528\u7684<code>reset<\/code>\u7c7b\u578b\uff08<code>--soft<\/code>\u3001<code>--mixed<\/code>\u3001<code>--hard<\/code>\uff09\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u7684\u4ee3\u7801\u53d1\u751f\u53d8\u5316\u3002\u5176\u4e2d\uff0c<code>--hard<\/code>\u9009\u9879\u4f1a\u91cd\u7f6e\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4f60\u7684\u5de5\u4f5c\u533a\u4ee3\u7801\u88ab\u4e4b\u524d\u7684\u63d0\u4ea4\u66ff\u4ee3\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-layout-2 wp-block-group-is-layout-flex\">\n<p><strong>Q2: \u6211\u4f7f\u7528\u4e86<code>git reset --hard<\/code>\u5e76\u4e22\u5931\u4e86\u4e00\u4e9b\u4ee3\u7801\uff0c\u6709\u529e\u6cd5\u627e\u56de\u5b83\u5417\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u7b54<\/strong>: \u662f\u7684\uff0c\u5373\u4f7f\u6267\u884c\u4e86<code>git reset --hard<\/code>\uff0c\u4f60\u8fd8\u662f\u6709\u673a\u4f1a\u627e\u56de\u4ee3\u7801\u3002Git\u6709\u4e00\u4e2a\u79f0\u4e3a<code>reflog<\/code>\u7684\u529f\u80fd\uff0c\u5b83\u8bb0\u5f55\u4e86\u6240\u6709\u5206\u652f\u548c<code>HEAD<\/code>\u7684\u79fb\u52a8\u5386\u53f2\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>git reflog<\/code>\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\uff0c\u7136\u540e\u627e\u5230\u4f60\u60f3\u8981\u6062\u590d\u7684\u63d0\u4ea4\u7684\u54c8\u5e0c\u503c\u3002\u4e00\u65e6\u627e\u5230\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>git checkout<\/code>\u6216<code>git reset<\/code>\u5230\u90a3\u4e2a\u63d0\u4ea4\uff0c\u4ece\u800c\u6062\u590d\u4f60\u7684\u4ee3\u7801\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-layout-3 wp-block-group-is-layout-flex\">\n<p><strong>Q3: <code>git reflog<\/code>\u548c<code>git log<\/code>\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u7b54<\/strong>: <code>git log<\/code>\u663e\u793a\u7684\u662f\u63d0\u4ea4\u5386\u53f2\uff0c\u5373\u4f60\u7684\u5206\u652f\u7684\u63d0\u4ea4\u8bb0\u5f55\u3002\u800c<code>git reflog<\/code>\u663e\u793a\u7684\u662f\u5f15\u7528\u65e5\u5fd7\uff0c\u5b83\u8ddf\u8e2a\u4e86<code>HEAD<\/code>\u548c\u5206\u652f\u5f15\u7528\u5728\u8fc7\u53bb\u4e00\u6bb5\u65f6\u95f4\u5185\u5982\u4f55\u79fb\u52a8\u7684\u3002\u8fd9\u610f\u5473\u7740\u5373\u4f7f\u4f60\u6267\u884c\u4e86\u67d0\u4e9b\u5c06\u63d0\u4ea4\u4ece\u5f53\u524d\u5206\u652f\u5386\u53f2\u4e2d\u5220\u9664\u7684\u64cd\u4f5c\uff08\u5982<code>git reset<\/code>\u6216<code>git rebase<\/code>\uff09\uff0c\u4f60\u4ecd\u7136\u53ef\u4ee5\u5728<code>reflog<\/code>\u4e2d\u627e\u5230\u5b83\u4eec\u3002<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-layout-4 wp-block-group-is-layout-flex\">\n<p><strong>Q4: \u5982\u679c\u6211\u4e0d\u5c0f\u5fc3\u6267\u884c\u4e86<code>git reset<\/code>\uff0c\u4f46\u6211\u6ca1\u6709\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u5176\u4ed6\u56e2\u961f\u6210\u5458\u7684\u4ee3\u7801\u4f1a\u53d7\u5230\u5f71\u54cd\u5417\uff1f<\/strong><\/p>\n\n\n\n<p><strong>\u7b54<\/strong>: \u5982\u679c\u4f60\u4ec5\u5728\u672c\u5730\u6267\u884c\u4e86<code>git reset<\/code>\u5e76\u4e14\u6ca1\u6709\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u90a3\u4e48\u5176\u4ed6\u56e2\u961f\u6210\u5458\u7684\u4ee3\u7801\u4e0d\u4f1a\u53d7\u5230\u4efb\u4f55\u5f71\u54cd\u3002\u53ea\u6709\u5f53\u4f60\u5c06\u8fd9\u4e9b\u66f4\u6539\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u65f6\uff0c\u5176\u4ed6\u56e2\u961f\u6210\u5458\u5728\u4e0b\u4e00\u6b21<code>pull<\/code>\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u95ee\u9898\u3002\u5982\u679c\u4f60\u4e0d\u60f3\u5f71\u54cd\u4ed6\u4eec\uff0c\u6700\u597d\u5728\u63a8\u9001\u4efb\u4f55\u91cd\u7f6e\u540e\u7684\u66f4\u6539\u4e4b\u524d\u4e0e\u56e2\u961f\u6c9f\u901a\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\u5728\u4f7f\u7528git reset\u540e\u6062\u590d\u4e22\u5931\u4ee3\u7801\u7684\u6b65\u9aa4\uff1a\u4e00\u3001\u7406\u89e3git reset\u7684\u4f5c\u7528\uff1b\u4e8c\u3001\u4f7f\u7528reflog\u67e5\u627e\u4e22\u5931\u63d0 [&hellip;]","protected":false},"author":7,"featured_media":54949,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/54946"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=54946"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/54946\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/54949"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=54946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=54946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=54946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}