{"id":19234,"date":"2024-11-19T17:41:54","date_gmt":"2024-11-19T09:41:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/19234\/"},"modified":"2024-11-19T17:41:54","modified_gmt":"2024-11-19T09:41:54","slug":"git%e6%80%8e%e4%b9%88%e6%81%a2%e5%a4%8d%e5%88%a0%e9%99%a4%e5%88%86%e6%94%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/19234\/","title":{"rendered":"git\u600e\u4e48\u6062\u590d\u5220\u9664\u5206\u652f"},"content":{"rendered":"<p>git \u662f\u4e00\u6b3e\u5341\u5206\u5b9e\u7528\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u975e\u5e38\u65b9\u4fbf\u5730\u7ba1\u7406\u4ee3\u7801\u7684\u53d8\u66f4\u3002\u4f46\u662f\uff0c\u5728\u4f7f\u7528 git \u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u53ef\u907f\u514d\u5730\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\u3002\u5176\u4e2d\uff0c\u5220\u9664\u5206\u652f\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\u3002<\/p>\n<p>\u5047\u8bbe\u4f60\u5728\u9879\u76ee\u4e2d\u8bef\u5220\u4e86\u4e00\u4e2a\u5206\u652f\uff0c\u4f60\u4f1a\u600e\u4e48\u529e\u5462\uff1f\u4e0d\u8981\u614c\u5f20\uff0cGit \u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6062\u590d\u5220\u9664\u7684\u5206\u652f\u3002<\/p>\n<p>\u4e00\u3001\u4e86\u89e3 Git \u7684\u5783\u573e\u56de\u6536\u673a\u5236<\/p>\n<p>\u5728 Git \u4e2d\uff0c\u5f53\u4f60\u5220\u9664\u4e86\u4e00\u4e2a\u5206\u652f\u65f6\uff0c\u5b9e\u9645\u4e0a\u5b83\u5e76\u6ca1\u6709\u771f\u6b63\u7684\u88ab\u5220\u9664\uff0c\u5b83\u53ea\u662f\u88ab Git \u6807\u8bb0\u4e3a\u201c\u5df2\u5220\u9664\u201d\u3002\u8fd9\u662f\u56e0\u4e3a Git \u6709\u4e00\u79cd\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u4f1a\u5b9a\u671f\u6e05\u7406\u4e0d\u9700\u8981\u7684\u5bf9\u8c61\uff0c\u5305\u62ec\u6807\u8bb0\u4e3a\u201c\u5df2\u5220\u9664\u201d\u7684\u5206\u652f\u3002<\/p>\n<p>\u4e8c\u3001\u4f7f\u7528 Git reflog \u547d\u4ee4<\/p>\n<p><span>\u70b9\u51fb\u4e0b\u8f7d<\/span>\u201c\u201d\uff1b<\/p>\n<p>Git reflog \u547d\u4ee4\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u7684 Git \u5f15\u7528\uff08\u5982\u5206\u652f\u3001\u6807\u7b7e\u7b49\uff09\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u5305\u62ec\u5df2\u7ecf\u88ab\u5220\u9664\u7684\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u4f7f\u7528 Git reflog \u547d\u4ee4\u53ef\u4ee5\u627e\u5230\u4e4b\u524d\u5220\u9664\u7684\u5206\u652f\uff0c\u5e76\u6062\u590d\u5b83\u3002<\/p>\n<p>\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u8fdb\u5165\u4f60\u7684 Git \u4ed3\u5e93\u76ee\u5f55\uff0c\u5e76\u6253\u5f00\u7ec8\u7aef\uff08MacOS \u6216 Linux\uff09\u6216 Git Shell\uff08Windows\uff09\u3002<\/li>\n<li>\u5728\u7ec8\u7aef\u6216 Git Shell \u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u5f15\u7528\u5386\u53f2\u8bb0\u5f55\uff1a<\/li>\n<\/ol>\n<pre>git reflog<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u627e\u5230\u4f60\u5220\u9664\u7684\u5206\u652f\u7684\u6700\u540e\u4e00\u4e2a commit ID\uff0c\u5728\u5f15\u7528\u5386\u53f2\u8bb0\u5f55\u4e2d\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u4fe1\u606f\uff1a<\/li>\n<\/ol>\n<pre>8a79c3f HEAD@{1}: commit: add feature A\nb3a0a50 HEAD@{2}: commit: add feature B\n2abe147 HEAD@{3}: branch: add-feature-C<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c\u201cHEAD@{n}\u201d\u8868\u793a\u7b2c n \u6b21\u5f15\u7528\u64cd\u4f5c\uff0c\u201ccommit:\u201d\u8868\u793a\u8be5\u5f15\u7528\u64cd\u4f5c\u7684\u7c7b\u578b\u662f\u63d0\u4ea4\u64cd\u4f5c\uff0c\u201cadd feature A\u201d\u8868\u793a\u63d0\u4ea4\u64cd\u4f5c\u5bf9\u5e94\u7684 commit message\u3002<\/p>\n<ol>\n<li>\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6062\u590d\u5206\u652f\uff1a<\/li>\n<\/ol>\n<pre>git branch &lt;branch-name&gt; &lt;commit-ID&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0c\u201c \u201d\u662f\u4f60\u8981\u6062\u590d\u7684\u5206\u652f\u540d\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4e00\u4e2a\u65b0\u7684\u5206\u652f\u540d\uff1b\u201c \u201d\u662f\u4e0a\u4e00\u6b65\u4e2d\u627e\u5230\u7684\u6700\u540e\u4e00\u4e2a commit \u7684 ID\u3002 <\/p>\n<ol>\n<li>\u6700\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5207\u6362\u5230\u6062\u590d\u7684\u5206\u652f\uff1a<\/li>\n<\/ol>\n<pre>git checkout &lt;branch-name&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u4f60\u5df2\u7ecf\u6210\u529f\u6062\u590d\u4e86\u4e4b\u524d\u8bef\u5220\u9664\u7684\u5206\u652f\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u901a\u8fc7 Git reflog \u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u627e\u5230\u4e4b\u524d\u8bef\u5220\u7684\u5206\u652f\uff0c\u5e76\u6062\u590d\u5b83\u3002\u8fd9\u79cd\u65b9\u6cd5\u9700\u8981\u6211\u4eec\u624b\u52a8\u627e\u5230\u4e0a\u4e00\u6b21\u5220\u9664\u7684 commit ID\uff0c\u5e76\u4ee5\u6b64\u4e3a\u4f9d\u636e\u6765\u521b\u5efa\u65b0\u7684\u5206\u652f\u3002\u6240\u4ee5\uff0c\u5728\u4f7f\u7528 Git \u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u5e94\u8be5\u65f6\u523b\u6ce8\u610f\u6587\u4ef6\u548c\u5206\u652f\u7684\u5907\u4efd\u548c\u7ba1\u7406\uff0c\u907f\u514d\u8bef\u64cd\u4f5c\u5bfc\u81f4\u4e0d\u5fc5\u8981\u7684\u635f\u5931\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fgit\u600e\u4e48\u6062\u590d\u5220\u9664\u5206\u652f\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>git \u662f\u4e00\u6b3e\u5341\u5206\u5b9e\u7528\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u975e\u5e38\u65b9\u4fbf\u5730\u7ba1\u7406\u4ee3\u7801\u7684\u53d8\u66f4\u3002\u4f46\u662f\uff0c\u5728\u4f7f\u7528 git \u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u53ef\u907f\u514d\u5730\u4f1a\u9047\u5230\u4e00\u4e9b\u95ee\u9898\u3002\u5176\u4e2d\uff0c\u5220\u9664\u5206\u652f\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u95ee\u9898\u3002 \u5047\u8bbe\u4f60\u5728\u9879\u76ee\u4e2d\u8bef\u5220\u4e86\u4e00\u4e2a\u5206\u652f\uff0c\u4f60\u4f1a\u600e\u4e48\u529e\u5462\uff1f\u4e0d\u8981\u614c\u5f20\uff0cGit \u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6062\u590d\u5220\u9664\u7684\u5206\u652f\u3002 \u4e00\u3001\u4e86\u89e3 Git \u7684\u5783\u573e\u56de\u6536\u673a\u5236 \u5728 Git \u4e2d\uff0c\u5f53\u4f60\u5220\u9664\u4e86\u4e00\u4e2a\u5206\u652f\u65f6\uff0c\u5b9e\u9645\u4e0a\u5b83\u5e76\u6ca1\u6709\u771f\u6b63\u7684\u88ab\u5220\u9664\uff0c\u5b83\u53ea\u662f\u88ab Git \u6807\u8bb0\u4e3a\u201c\u5df2\u5220\u9664\u201d\u3002\u8fd9\u662f\u56e0\u4e3a Git \u6709\u4e00\u79cd\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u4f1a\u5b9a\u671f\u6e05\u7406\u4e0d\u9700\u8981\u7684\u5bf9\u8c61\uff0c\u5305\u62ec\u6807\u8bb0\u4e3a\u201c\u5df2\u5220\u9664\u201d\u7684\u5206\u652f\u3002 \u4e8c\u3001\u4f7f\u7528 Git reflog \u547d\u4ee4 \u70b9\u51fb\u4e0b\u8f7d\u201c\u201d\uff1b Git reflog \u547d\u4ee4\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u7684 Git \u5f15\u7528\uff08\u5982\u5206\u652f\u3001\u6807\u7b7e\u7b49\uff09\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u5305\u62ec\u5df2\u7ecf\u88ab\u5220\u9664\u7684\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u4f7f\u7528 Git reflog \u547d\u4ee4\u53ef\u4ee5\u627e\u5230\u4e4b\u524d\u5220\u9664\u7684\u5206\u652f\uff0c\u5e76\u6062\u590d\u5b83\u3002 \u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a \u8fdb\u5165\u4f60\u7684 Git \u4ed3\u5e93\u76ee\u5f55\uff0c\u5e76\u6253\u5f00\u7ec8\u7aef\uff08MacOS \u6216 Linux\uff09\u6216 Git Shell\uff08Windows\uff09\u3002 \u5728\u7ec8\u7aef\u6216 Git Shell \u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u5f15\u7528\u5386\u53f2\u8bb0\u5f55\uff1a git reflog \u767b\u5f55\u540e\u590d\u5236 \u627e\u5230\u4f60\u5220\u9664\u7684\u5206\u652f\u7684\u6700\u540e\u4e00\u4e2a commit ID\uff0c\u5728\u5f15\u7528\u5386\u53f2\u8bb0\u5f55\u4e2d\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u4fe1\u606f\uff1a 8a79c3f HEAD@{1}: commit: add feature A b3a0a50 HEAD@{2}: [&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-19234","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19234","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=19234"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/19234\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=19234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=19234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=19234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}