{"id":797,"date":"2026-02-28T14:59:41","date_gmt":"2026-02-28T06:59:41","guid":{"rendered":"https:\/\/znl.pub\/?p=797"},"modified":"2026-02-28T15:00:46","modified_gmt":"2026-02-28T07:00:46","slug":"git%e5%ae%9e%e6%88%98%ef%bc%9a%e5%bd%93%e6%88%91%e5%9c%a8%e5%8e%86%e5%8f%b2%e6%8f%90%e4%ba%a4%e4%b8%8a%e5%bc%80%e5%8f%91%e5%90%8e%ef%bc%8c%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a1%ae%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/znl.pub\/?p=797","title":{"rendered":"Git\u5b9e\u6218\uff1a\u5f53\u6211\u5728\u5386\u53f2\u63d0\u4ea4\u4e0a\u5f00\u53d1\u540e\uff0c\u5982\u4f55\u6b63\u786e\u540c\u6b65\u5230\u539f\u5206\u652f\uff1f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u95ee\u9898\u573a\u666f<\/h2>\n\n\n\n<p>\u6211\u9047\u5230\u4e86\u4e00\u4e2a\u5178\u578b\u7684Git\u4f7f\u7528\u95ee\u9898\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6211\u5728 <code>feature\/mail<\/code> \u5206\u652f\u7684\u67d0\u4e2a\u5386\u53f2\u63d0\u4ea4\u4e0a\uff08\u6bd4\u5982\u63d0\u4ea4c\uff09\u5f00\u59cb\u5f00\u53d1<\/li>\n\n\n\n<li>\u57fa\u4e8e\u8fd9\u4e2a\u5386\u53f2\u63d0\u4ea4\uff0c\u6211\u8fde\u7eed\u63d0\u4ea4\u4e86\u591a\u6b21\uff08x\u3001y\u3001z\uff09<\/li>\n\n\n\n<li>\u5f53\u6211\u60f3\u63a8\u9001\u65f6\uff0cGit\u63d0\u793a\u8fd9\u662f\u4e00\u4e2a&#8221;\u5b64\u7acb\u5206\u652f&#8221;\uff08Detatched HEAD\uff09\uff0c\u4e0d\u80fd\u63d0\u4ea4\u3002<\/li>\n\n\n\n<li>\u5b9e\u9645\u4e0a\uff0c\u6211\u60f3\u8981\u7684\u662f\u7528\u6211\u7684\u65b0\u63d0\u4ea4\uff08x\u3001y\u3001z\uff09\u66ff\u6362\u539f\u6765\u7684d\u3001e\u63d0\u4ea4<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u95ee\u9898\u672c\u8d28<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u95ee\u9898\u770b\u4f3c\u590d\u6742\uff0c\u4f46\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5206\u652f\u53ea\u662f\u6307\u5411\u63d0\u4ea4\u7684\u6307\u9488<\/strong>\uff08\u53ef\u4ee5\u7406\u89e3\u4e3a\u6807\u7b7e\uff09<\/li>\n\n\n\n<li>\u6211\u5f53\u524d\u7684\u5de5\u4f5c\uff08x\u3001y\u3001z\uff09\u6ca1\u6709\u5206\u652f\u540d\u6307\u5411\u5b83\u4eec<\/li>\n\n\n\n<li>\u6211\u9700\u8981\u628a <code>feature\/mail<\/code> \u8fd9\u4e2a\u6307\u9488\u4ece e \u79fb\u52a8\u5230 z<\/li>\n<\/ul>\n\n\n\n<p>\u89e3\u51b3\u65b9\u6848<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. \u9996\u5148\u786e\u4fdd\u6240\u6709\u4fee\u6539\u90fd\u5df2\u63d0\u4ea4\uff08\u91cd\u8981\uff01\uff09\ngit add .\ngit commit -m \"\u5907\u4efd\u5f53\u524d\u6240\u6709\u4fee\u6539\"  # \u786e\u4fdd\u6ca1\u6709\u672a\u63d0\u4ea4\u7684\u66f4\u6539\n\n# 2. \u786e\u8ba4\u5f53\u524d\u72b6\u6001\ngit log --oneline\n\n# 3. \u5c06\u5f53\u524d\u5de5\u4f5c\u4fdd\u5b58\u4e3a\u4e34\u65f6\u5206\u652f\uff08\u5b89\u5168\u5907\u4efd\uff09\ngit checkout -b temp-work\n\n# 4. \u5f3a\u5236\u79fb\u52a8\u539f\u5206\u652f\u6307\u9488\u5230\u5f53\u524d\u4f4d\u7f6e\ngit branch -f feature\/mail temp-work\n\n# 5. \u5207\u6362\u56de\u539f\u5206\u652f\ngit checkout feature\/mail\n\n# 6. \u5220\u9664\u4e34\u65f6\u5206\u652f\uff08\u53ef\u9009\uff09\ngit branch -d temp-work\n\n# 7. \u63a8\u9001\u5230\u8fdc\u7a0b\uff08\u9700\u8981\u5f3a\u5236\u63a8\u9001\uff09\ngit push -f origin feature\/mail<\/code><\/pre>\n\n\n\n<p>\u5f53\u7136\u4e86\uff0c\u4f60\u5982\u679c\u7b2c\u4e00\u6b65\u4e0d\u60f3\u63d0\u4ea4\u4fdd\u5b58\u4fee\u6539\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u4f7f\u7528 git stash \u6682\u5b58\uff0c\u603b\u4e4b\u539f\u7406\u662f\u4e00\u6837\u7684\u3002\u5c31\u662f\u5c06\u539f\u6765\u7684\u5206\u652f\u540d\u5b57\uff08ref \u540d\uff09\u6307\u5411\u4f60\u73b0\u5728HEAD\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"43ac3\">\u4ec0\u4e48\u662f Git \u7684 ref \u548c head\uff1f<\/h2>\n\n\n\n<p><strong>commit ID<\/strong>\uff1aGit \u4ed3\u5e93\u7684\u8bb0\u5f55\u662f\u7531\u4e00\u6b21\u6b21\u7684 Commit \u6784\u6210\u7684\uff0c\u6bcf\u6b21 commit \u90fd\u7531\u4e00\u4e2a commit ID <strong>\u552f\u4e00\u6807\u8bc6<\/strong>\u3002\u8fd9\u79cd\u552f\u4e00\u6807\u8bc6\u662f\u4e00\u4e2a\u957f\u5ea6 40 \u4f4d\u7684\u54c8\u5e0c\u503c\uff08\u4f8b\u5982\uff1af5946c1e5d45d811e40ac7d2bb862e4911fcb1a6\uff09\u3002\u663e\u7136\uff0c\u8fd9\u79cd\u6807\u8bc6\u662f\u4e3a\u8ba1\u7b97\u673a\u670d\u52a1\u7684\uff0c\u4e0d\u9002\u5408\u4f9b\u4eba\u7c7b\u9605\u8bfb\u548c\u8bb0\u5fc6\u3002<\/p>\n\n\n\n<p><strong>ref<\/strong>\uff1aGit \u7684 ref \u662f\u9002\u5408\u4eba\u7c7b\u9605\u8bfb\u548c\u8bb0\u5fc6\u7684\uff0c\u6307\u5411\u67d0 commit ID \u7684\u6307\u9488\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5206\u652f\uff08branch\uff09\u7684\u540d\u5b57\uff08\u4f8b\u5982\uff1amaster\u3001dev\uff09\u5c31\u662f\u4e00\u79cd ref\u3002<\/li>\n\n\n\n<li>\u6807\u7b7e\uff08tag\uff09\u7684\u540d\u5b57\uff08\u4f8b\u5982\uff1av0.1\u3001v0.2\uff09\u4e5f\u662f\u4e00\u79cd ref\u3002<\/li>\n\n\n\n<li>\u8fdc\u7a0b\u4ed3\u5e93\uff08remote\uff09\u4e2d\u7684\u5206\u652f\u4e5f\u662f ref\u3002<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u6ce8\uff1aGit \u7684 ref \u5b58\u50a8\u5728\u9879\u76ee\u672c\u5730\u4ed3\u5e93\u4e2d\u7684 <code>.git\/refs\/<\/code> \u76ee\u5f55\u4e0b\uff0c\u6587\u4ef6\u5185\u5bb9\u662f ref \u6240\u6307\u5411\u7684 commit ID\u3002<\/p>\n<\/blockquote>\n\n\n\n<p><strong>head<\/strong>\uff1aGit \u7684 head \u4e5f\u662f\u4e00\u79cd ref\uff0c\u5e76\u4e14\u5b83\u4eec\u5c31\u662f\u4ee3\u8868\u6211\u4eec\u672c\u5730\u5206\u652f\uff08\u4f8b\u5982\uff1amaster\u3001dev\u7b49\uff09\u7684 ref\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0c\u6307\u4ee3\u5206\u652f\u7684 ref \u547d\u540d\u4e3a head \u4e5f\u6709\u5b83\u7684\u5185\u6db5\uff0c\u5373 head \u6c38\u8fdc\u6307\u5411\u5b83\u6240\u6307\u4ee3\u5206\u652f\u7684\u6700\u201c\u5934\u90e8\u201d\u7684\u63d0\u4ea4\uff08\u5373\u6700\u65b0\u7684\u4e00\u6b21\u63d0\u4ea4\uff09\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u4f8b\u5982\u5206\u652f <code>master<\/code>\uff0c<code>master<\/code> \u8fd9\u4e2a\u540d\u5b57\u662f\u4e0d\u53d8\u7684\uff0c\u4f46\u5b83\u6307\u5411\u7684 commit ID \u4f1a\u968f\u7740\u4f60\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\u7684\u63d0\u4ea4\u800c\u6539\u53d8\uff0c\u6c38\u8fdc\u6307\u5411\u4f60\u6700\u65b0\u4e00\u6b21\u7684\u63d0\u4ea4\u3002<\/p>\n\n\n\n<p><strong>Git \u5206\u652f\u7684\u672c\u8d28<\/strong>\uff1a\u5206\u652f\u53ea\u662f<strong>\u6307\u5411\u63d0\u4ea4\u7684\u6307\u9488\/\u6807\u7b7e<\/strong>\uff0c\u4e0d\u662f\u6587\u4ef6\u7684\u62f7\u8d1d\u6216\u96c6\u5408\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5206\u652f\u7684\u771f\u5b9e\u672c\u8d28<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5206\u652f = \u6307\u9488<\/strong>\uff1a\u6bcf\u4e2a\u5206\u652f\u53ea\u662f\u4e00\u4e2a\u6307\u5411\u67d0\u4e2a\u63d0\u4ea4\u7684\u6307\u9488<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u5206\u652f\u6210\u672c\u6781\u4f4e<\/strong>\uff1a\u53ea\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u6307\u9488\uff0c\u4e0d\u590d\u5236\u6587\u4ef6<\/li>\n\n\n\n<li><strong>\u5206\u652f\u540d\u662f\u5f15\u7528<\/strong>\uff1a\u5982 <code>main<\/code>\u3001<code>develop<\/code> \u90fd\u662f\u6307\u5411\u63d0\u4ea4\u7684\u53ef\u53d8\u5f15\u7528<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5e38\u89c1\u8bef\u89e3\u7ea0\u6b63<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u274c \u8bef\u89e3\uff1a\u5206\u652f\u662f\u6587\u4ef6\u7684\u62f7\u8d1d\u6216\u5feb\u7167<\/li>\n\n\n\n<li>\u2705 \u771f\u76f8\uff1a\u5206\u652f\u53ea\u662f\u63d0\u4ea4\u5386\u53f2\u7684&#8221;\u4e66\u7b7e&#8221;<\/li>\n\n\n\n<li>\u274c \u8bef\u89e3\uff1a\u5207\u6362\u5206\u652f\u662f\u5207\u6362\u6587\u4ef6\u5185\u5bb9<\/li>\n\n\n\n<li>\u2705 \u771f\u76f8\uff1a\u5207\u6362\u5206\u652f\u662f\u79fb\u52a8HEAD\u6307\u9488<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u6280\u672f\u5b9e\u73b0<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.git\/refs\/heads\/<\/code> \u76ee\u5f55\u5b58\u653e\u5206\u652f\u6307\u9488\u6587\u4ef6<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u6587\u4ef6\u5305\u542b\u4e00\u4e2a40\u5b57\u7b26\u7684SHA-1\u54c8\u5e0c\u503c<\/li>\n\n\n\n<li>\u5206\u652f\u64cd\u4f5c\u672c\u8d28\u662f\u66f4\u65b0\u8fd9\u4e9b\u6307\u9488\u6587\u4ef6<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u91cd\u8981\u64cd\u4f5c\u89e3\u6790<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u521b\u5efa\u5206\u652f<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Bash<code>git branch feature  <em># \u53ea\u662f\u521b\u5efa\u65b0\u6307\u9488\u6307\u5411\u5f53\u524d\u63d0\u4ea4<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u6539\u53d8\u5de5\u4f5c\u533a<\/li>\n\n\n\n<li>\u4e0d\u6539\u53d8HEAD\u4f4d\u7f6e<\/li>\n\n\n\n<li>\u53ea\u662f\u6dfb\u52a0\u4e00\u4e2a\u65b0\u6807\u7b7e<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u5207\u6362\u5206\u652f<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Bash<code>git checkout feature  <em># \u79fb\u52a8HEAD\u6307\u9488<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u66f4\u65b0\u5de5\u4f5c\u533a\u6587\u4ef6<\/li>\n\n\n\n<li>\u6539\u53d8HEAD\u6307\u5411<\/li>\n\n\n\n<li>\u53ef\u80fd\u89e6\u53d1\u6587\u4ef6\u53d8\u66f4<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u63d0\u4ea4\u64cd\u4f5c<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">Bash<code>git commit  <em># \u521b\u5efa\u65b0\u63d0\u4ea4\uff0c\u79fb\u52a8\u5f53\u524d\u5206\u652f\u6307\u9488<\/em><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u521b\u5efa\u65b0\u7684\u63d0\u4ea4\u5bf9\u8c61<\/li>\n\n\n\n<li>\u81ea\u52a8\u5c06\u5f53\u524d\u5206\u652f\u6307\u9488\u79fb\u52a8\u5230\u65b0\u63d0\u4ea4<\/li>\n\n\n\n<li>\u5176\u4ed6\u5206\u652f\u6307\u9488\u4e0d\u52a8<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u53ef\u89c6\u5316\u7406\u89e3<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">\u521d\u59cb\uff1aA \u2190 B \u2190 C (main, HEAD)<br>\u521b\u5efa\u5206\u652f\uff1aA \u2190 B \u2190 C (main, feature, HEAD)<br>\u63d0\u4ea4\u540e\uff1aA \u2190 B \u2190 C \u2190 D (feature, HEAD)<br>                 \u2191 (main\u4ecd\u6307\u5411C)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u5b9e\u9645\u610f\u4e49<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u8f7b\u91cf\u7ea7\u5206\u652f<\/strong>\uff1a\u53ef\u4ee5\u968f\u610f\u521b\u5efa\/\u5220\u9664\u5206\u652f<\/li>\n\n\n\n<li><strong>\u5feb\u901f\u5207\u6362<\/strong>\uff1a\u5207\u6362\u5206\u652f\u53ea\u662f\u6539\u53d8\u6307\u9488<\/li>\n\n\n\n<li><strong>\u9ad8\u6548\u5b58\u50a8<\/strong>\uff1a\u591a\u4e2a\u5206\u652f\u5171\u4eab\u76f8\u540c\u63d0\u4ea4\u7684\u6587\u4ef6\u5185\u5bb9<\/li>\n\n\n\n<li><strong>\u7075\u6d3b\u5408\u5e76<\/strong>\uff1a\u5408\u5e76\u672c\u8d28\u662f\u521b\u5efa\u65b0\u63d0\u4ea4\uff0c\u8c03\u6574\u6307\u9488<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u4e0eSVN\u7684\u5bf9\u6bd4<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Git<\/strong>\uff1a\u5206\u652f\u662f\u6307\u9488\uff0c\u521b\u5efa\u5feb\u901f\uff0c\u5207\u6362\u65b9\u4fbf<\/li>\n\n\n\n<li><strong>SVN<\/strong>\uff1a\u5206\u652f\u662f\u76ee\u5f55\u62f7\u8d1d\uff0c\u521b\u5efa\u6162\uff0c\u5360\u7528\u7a7a\u95f4\u5927<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u8df5\u542f\u793a<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5927\u80c6\u521b\u5efa\u5206\u652f<\/strong>\uff1a\u4e0d\u7528\u62c5\u5fc3\u6027\u80fd\u6216\u5b58\u50a8\u95ee\u9898<\/li>\n\n\n\n<li><strong>\u7406\u89e3\u6307\u9488\u79fb\u52a8<\/strong>\uff1a\u6240\u6709\u5206\u652f\u64cd\u4f5c\u90fd\u662f\u6307\u9488\u64cd\u4f5c<\/li>\n\n\n\n<li><strong>\u638c\u63e1HEAD\u6982\u5ff5<\/strong>\uff1aHEAD\u6307\u5411\u5f53\u524d&#8221;\u6d3b\u52a8&#8221;\u7684\u6307\u9488<\/li>\n\n\n\n<li><strong>\u5229\u7528reflog<\/strong>\uff1a\u6307\u9488\u5386\u53f2\u8bb0\u5f55\u53ef\u6062\u590d\u8bef\u64cd\u4f5c<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u53e5\u8bdd\u603b\u7ed3<\/h2>\n\n\n\n<p><strong>Git\u5206\u652f\u4e0d\u662f\u6587\u4ef6\u7684\u62f7\u8d1d\uff0c\u800c\u662f\u63d0\u4ea4\u5386\u53f2\u7684\u53ef\u79fb\u52a8\u6807\u7b7e\u3002\u7406\u89e3\u8fd9\u4e00\u70b9\u662f\u638c\u63e1Git\u9ad8\u7ea7\u7528\u6cd5\u7684\u5173\u952e\u3002<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u573a\u666f \u6211\u9047\u5230\u4e86\u4e00\u4e2a\u5178\u578b\u7684Git\u4f7f\u7528\u95ee\u9898\uff1a \u95ee\u9898\u672c\u8d28 \u8fd9\u4e2a\u95ee\u9898\u770b\u4f3c\u590d\u6742\uff0c\u4f46\u5176\u5b9e\u5f88\u7b80\u5355\uff1a \u89e3\u51b3\u65b9\u6848 \u5f53\u7136\u4e86\uff0c\u4f60&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=797"}],"version-history":[{"count":2,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":799,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions\/799"}],"wp:attachment":[{"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}