{"id":2073,"date":"2019-09-05T18:05:02","date_gmt":"2019-09-05T10:05:02","guid":{"rendered":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/?p=2073"},"modified":"2026-04-10T13:44:29","modified_gmt":"2026-04-10T05:44:29","slug":"git%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/2019\/09\/05\/git%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86\/","title":{"rendered":"Git\u5165\u95e8\u57fa\u7840\u77e5\u8bc6"},"content":{"rendered":"\n<p>\u591a\u5e74\u5f00\u53d1\u5de5\u4f5c\u4ee5\u6765\uff0c\u524d\u524d\u540e\u540e\u7528\u8fc7\u5f88\u591a\u4e2a\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u4ece\u6700\u65e9\u7684VSS\uff08\u5fae\u8f6f\u7684\u5de5\u5177\uff0c\u73b0\u5728\u5927\u6982\u6ca1\u4eba\u77e5\u9053\u8fd9\u662f\u4e2a\u4ec0\u4e48\u4e1c\u4e1c\u4e86\uff09\uff0c\u5230SVN\u3001ClearCase\u3001mercurial\uff08hg\uff09\uff0c\u73b0\u5728\u7ec8\u4e8e\u8981\u8fc7\u6e21\u5230Git\u4e86\u3002<\/p>\n\n\n\n<p>\u5176\u5b9e\u6211\u4eec\u6700\u8fd1\u8fd9\u4e9b\u5e74\u4e00\u76f4\u7528\u7740hg\uff0c\u611f\u89c9\u633a\u597d\u7684\uff0c\u975e\u5e38\u6ee1\u610f\uff0c\u6ca1\u6709\u6253\u7b97\u6362\u5176\u4ed6\u5de5\u5177\u3002\u65e0\u5948BitBucket\u53d1\u90ae\u4ef6\u901a\u77e5\uff0c\u660e\u5e74\u8981\u5207\u6362\u5230Git\uff08\u8be6\u60c5\u8bf7<a rel=\"noreferrer noopener\" aria-label=\"\u70b9\u51fb\u8fd9\u91cc\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/bitbucket.org\/blog\/sunsetting-mercurial-support-in-bitbucket\" target=\"_blank\">\u70b9\u51fb\u8fd9\u91cc<\/a>\uff09\uff0c\u8003\u8651\u5230\u5e74\u5e95\u4e8b\u53ef\u80fd\u4f1a\u6bd4\u8f83\u591a\uff0c\u4e58\u7740\u73b0\u5728\u8fd8\u4e0d\u592a\u5fd9\uff0c\u8d76\u7d27\u5148\u5b66\u4e60\uff0c\u6293\u7d27\u65f6\u95f4\u8fc1\u79fb\u3002<\/p>\n\n\n\n<p>HG\u548cGit\u7684\u57fa\u672c\u539f\u7406\u548c\u64cd\u4f5c\u662f\u76f8\u901a\u7684\uff0c\u90fd\u662f\u5206\u5e03\u5f0f\u7684\u7248\u672c\u7ba1\u7406\u5de5\u5177\u3002\u5177\u4f53\u5728\u67d0\u4e9b\u7ec6\u8282\u4e0a\uff0c\u786e\u5b9e\u6709\u4e9b\u5dee\u5f02\u3002\u6bd4\u5982HG\u7684commit\u64cd\u4f5c\uff0c\u5b9e\u9645\u4e0a\u76f8\u5f53\u4e8eGit\u7684add+commit\u4e24\u6b65\u64cd\u4f5c\u3002Git\u591a\u4e86<em>\u672c\u5730\u7f13\u51b2\u533a<\/em>\u7684\u6982\u5ff5\uff0c\u5728branch\u90e8\u5206\uff0cHG\u548cGit\u6709\u5f88\u5927\u5dee\u5f02\u3002Git\u7684\u672c\u5730branch\u548c\u8fdc\u7aefbranch\u53ef\u4ee5\u4e0d\u4e00\u81f4\uff0c\u9700\u8981\u5efa\u7acb\u6620\u5c04\u5173\u8054\uff0c\u800cHG\u672c\u5730branch\u548c\u8fdc\u7aefbranch\u603b\u662f\u4e00\u81f4\u7684\u3002Git\u5f53\u7136\u66f4\u7075\u6d3b\u4e9b\uff0c\u800c\u4ece\u7ba1\u7406\u89d2\u5ea6\u8003\u8651\uff0c\u6211\u66f4\u559c\u6b22HG\u7684\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p>HG\u7684branch\u4e0d\u80fd\u88ab\u5220\u9664\uff0c\u53ea\u80fd\u88ab\u5173\u95ed\uff0c\u800cGit\u7684branch\u53ef\u4ee5\u88ab\u5220\u9664\uff01\u6211\u89c9\u5f97\u8fd9\u662f\u4e24\u8005\u6700\u5927\u7684\u4e00\u4e2a\u5dee\u5f02\u3002\u663e\u7136\uff0cGit\u66f4\u9f13\u52b1\u9891\u7e41\u5730\u64cd\u4f5cbranch\u3002\u8fd9\u70b9\u6211\u66f4\u559c\u6b22Git\uff0c\u5b9e\u9645\u5de5\u4f5c\u4e2d\uff0c\u5b9a\u4f4d\u95ee\u9898\u3001\u51fa\u4e34\u65f6\u7248\u672c\uff0c\u90fd\u53ef\u4ee5\u5e94\u7528\u4e00\u4e9b\u4e34\u65f6\u7684branch\uff0c\u4e8b\u540e\u5220\u9664\uff0c\u7248\u672c\u5e93\u4e5f\u5e72\u51c0\u5f88\u591a\u3002<\/p>\n\n\n\n<p>\u7f51\u4e0a\u7684\u5b66\u4e60\u8d44\u6599\u5f88\u591a\uff0c\u6211\u89c9\u5f97\u5ed6\u96ea\u5cf0\u5199\u7684\u6559\u7a0b\u975e\u5e38\u8be6\u7ec6\u3001\u6613\u61c2\uff0c\u63a8\u8350\u7ed9\u5927\u5bb6\uff0c\u8bf7<a rel=\"noreferrer noopener\" aria-label=\"\u70b9\u51fb\u6b64\u5904\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\" href=\"https:\/\/www.liaoxuefeng.com\/wiki\/896043488029600\" target=\"_blank\">\u70b9\u51fb\u6b64\u5904<\/a>\u3002<\/p>\n\n\n\n<p>\u5728windows\u7cfb\u7edf\u4e2d\uff0c\u76f4\u63a5\u4e0b\u8f7d\u3001\u5b89\u88c5<a href=\"https:\/\/www.sourcetreeapp.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"SourceTree\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">SourceTree<\/a>\u5373\u53ef\uff0c\u800c\u5728Debian\u7cfb\u7edf\u4e2d\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u76f4\u63a5\u5b89\u88c5Git\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apt install git<\/pre>\n\n\n\n<p>SourceTree \u4f7f\u7528\u65b9\u4fbf\u3001\u76f4\u89c2\uff0c\u5982\u679c\u5e73\u65f6\u662f\u5de5\u4f5c\u5728windows\u7cfb\u7edf\uff0c\u7528\u8fd9\u4e2a\u5de5\u5177\u5c31\u633a\u597d\u3002\u50cf\u6211\u5f88\u5927\u4e00\u90e8\u5206\u65f6\u95f4\u662f\u5de5\u4f5c\u5728Debian\u7cfb\u7edf\u4e0a\uff0c\u56e0\u6b64\u638c\u63e1\u4e00\u4e9bGit\u7684\u547d\u4ee4\u884c\u64cd\u4f5c\u5c31\u6bd4\u8f83\u91cd\u8981\uff0c\u597d\u5728\u4e0d\u592a\u591a\uff0c\u5e76\u4e14\u548cHG\u76f8\u5dee\u4e0d\u5927\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u8bb0\u5f55\u4e00\u4e9b\u5e38\u89c1\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5168\u5c40\u914d\u7f6e<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh-keygen -t rsa -C \"git@demo.com\"<\/pre>\n\n\n\n<p>BitBucket\u7684Git\u652f\u6301 SSH \u548c HTTPS \u4e24\u79cd\u4f20\u8f93\u65b9\u5f0f\uff0c\u63a8\u8350\u91c7\u7528SSH\uff0c\u5e76\u4e14\u91c7\u7528\u8bc1\u4e66\u63a5\u5165\uff0c\u8fd9\u6837\u6709\u4e24\u70b9\u597d\u5904\uff1a\uff081\uff09\u9632\u6b62\u5176\u4ed6\u4eba\u767b\u5f55\u3002\u8d26\u53f7\u3001\u5bc6\u7801\u9274\u6743\u65b9\u5f0f\u6bd4\u8f83\u5bb9\u6613\u6cc4\u5bc6\uff0c\u800cSSH\u8bc1\u4e66\u5728\u672c\u5730\u4fdd\u5b58\uff0c\u53ea\u8981\u522b\u4eba\u4e0d\u80fd\u8f7b\u6613\u83b7\u53d6\u4f60\u7684\u5bc6\u94a5\u6587\u4ef6\uff0c\u5c31\u65e0\u6cd5\u4ece\u5176\u4ed6\u8ba1\u7b97\u673a\u4e0a\u767b\u5f55Git\u670d\u52a1\u5668\u3002\uff082\uff09\u6bcf\u6b21\u767b\u5f55\u3001\u64cd\u4f5c\u65e0\u9700\u8f93\u5165\u8d26\u6237\u5bc6\u7801\uff0c\u80fd\u7701\u70b9\u65f6\u95f4\u5427\u3002<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c31\u662f\u521b\u5efaSSH\u5bc6\u94a5\uff0c\u9ed8\u8ba4\u5728~\/.ssh \u76ee\u5f55\u4e0b\u521b\u5efa\u4e24\u4e2a\u6587\u4ef6\uff1a<em>id_rsa<\/em>\u4ee5\u53ca<em>id_rsa.pub<\/em>\u3002id_rsa.pub\u4e2d\u8bb0\u5f55\u516c\u94a5\uff0c\u5c06\u5176\u5185\u5bb9\u62f7\u8d1d\u51fa\u6765\uff0c\u4fdd\u5b58\u5728BitBucket\u8d26\u6237\u4e2d\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git config --global user.name \"git\"\ngit config --global user.email \"git@demo.com\"<\/pre>\n\n\n\n<p>\u914d\u7f6e\u5168\u5c40\u7528\u6237\u540d\u3002\u8fd9\u4e2a\u4e0d\u662fGit\u8d26\u53f7\u7684\u767b\u5f55\u540d\uff0c\u53ea\u662f\u5728\u6bcf\u6b21\u63d0\u4ea4\u4ee3\u7801\u65f6\uff0c\u7cfb\u7edf\u7528\u8fd9\u4e9b\u53c2\u6570\u505a\u4e00\u4e9b\u63cf\u8ff0\u6027\u4fe1\u606f\uff0c\u6bd4\u5982\u663e\u793a\u6539\u52a8\u7684\u7528\u6237\u662f\u8c01\uff0c\u8bf8\u5982\u6b64\u7c7b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">git config --global color.ui true<\/pre>\n\n\n\n<p>Git\u547d\u4ee4\u884c\u91c7\u7528\u5f69\u8272\u663e\u793a\uff08\u65e0\u5173\u7d27\u8981\uff0c\u53ea\u662f\u4e2a\u4eba\u7684\u6076\u8da3\u5473\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u672c\u547d\u4ee4<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">git init --bare \u5728\u670d\u52a1\u5668\u76ee\u5f55\u4e0b\u4f7f\u7528\u8be5\u547d\u4ee4\u521b\u5efa git \u4ed3\u5e93<br>git clone my_name@my_server_addr:\/home\/my_name\/repos\/xxx \u4ee5 my_name \u767b\u5f55 my_server_addr\uff0c\u5e76\u514b\u9686 \/home\/my_name\/repos\/xxx \u5e93\u81f3\u672c\u5730 xxx \u76ee\u5f55<br>git gc --prune=now --aggressive \u5728\u672c\u5730\u6216\u8005\u670d\u52a1\u5668\u4e0a\u6267\u884c\u8be5\u547d\u4ee4\uff0c\u6e05\u7406\u53ca\u56de\u6536\u7a7a\u95f4<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">git add xxx \u5c06\u4fee\u6539\u63d0\u4ea4\u5230\u7f13\u51b2\u533a\ngit commit -m \"1234\"  \u5c06\u7f13\u51b2\u533a\u63d0\u4ea4\u5230\u672c\u5730\u5e93\ngit restore &lt;filename&gt; \u653e\u5f03\u672c\u5730\u7684\u4fee\u6539<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">git checkout -b xxx \u521b\u5efa\u672c\u5730\u5206\u652fxxx<br>git push --set-upstream origin xxx \u5c06\u672c\u5730xxx\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93<br>git checkout -b xxx --track origin\/xxx \u521b\u5efa\u672c\u5730xxx\u5206\u652f\uff0c\u5e76\u5173\u8054\u5230\u8fdc\u7a0borigin\/xxx\u5206\u652f<br>git checkout xxx \u5207\u6362\u5230xxx\u5206\u652f<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">git prune \u6e05\u7406\u5e76\u5220\u9664\u4e0d\u518d\u88ab\u5f15\u7528\u7684\u5b64\u7acb\u5bf9\u8c61\uff08\u4f8b\u5982\u4e22\u5f03\u7684\u5206\u652f\u7b49\uff09<br>git gc \u6e05\u7406\u5e76\u5783\u573e\u56de\u6536\uff0c\u540c\u65f6\u4f18\u5316\u4ed3\u5e93\u5b58\u50a8\u7a7a\u95f4\uff0c\u538b\u7f29\u5bf9\u8c61\u3001\u4f18\u5316\u6027\u80fd<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Branch\u76f8\u5173\u547d\u4ee4<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">git branch \u67e5\u8be2\u5f53\u524d\u672c\u5730\u5206\u652f<br>git branch -a \u67e5\u8be2\u6240\u6709\u672c\u5730\u548c\u8fdc\u7aef\u5206\u652f<br>git branch -r \u67e5\u8be2\u8fdc\u7aef\u5206\u652f <br>git branch -d xxx \u5220\u9664\u672c\u5730\u5206\u652fxxx<br>git push origin -d xxx \u5220\u9664\u8fdc\u7a0b\u5206\u652fxxx \uff08\u6ce8\u610f\uff1a\u5206\u652f\u540d\u4e0d\u8981\u5e26\u4e0a origin\uff09<br>git remote prune origin \u5220\u9664\u8fdc\u7a0b\u5206\u652f\u540e\uff0c\u66f4\u65b0\u672c\u5730\u7684\u8fdc\u7a0b\u4fe1\u606f<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">git merge xxx \u5c06\u5206\u652fxxx\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\uff0c\u4fdd\u7559\u5206\u652f\u6240\u6709\u8282\u70b9\u4fe1\u606f<br>git rebase xxx \u5c06\u5206\u652fxxx\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\uff08\u901a\u5e38\u5408\u5e76\u5f00\u53d1\u5206\u652f\u5230\u516c\u5171\u5206\u652f\u7528merge\uff0c\u5408\u5e76\u516c\u5171\u5206\u652f\u5230\u5f00\u53d1\u5206\u652f\u7528rebase\uff09<br>git merge --squash xxx \u5c06\u5206\u652fxxx\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\uff0c\u540c\u65f6\u5c06\u6240\u6709\u63d0\u4ea4\u8bb0\u5f55\u538b\u7f29\u4e3a\u4e00\u4e2a\u63d0\u4ea4\u8bb0\u5f55<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">git pull \u4ece\u8fdc\u7a0b\u4ed3\u5e93\u66f4\u65b0\u5230\u672c\u5730\u4ed3\u5e93\ngit fetch --all \u66f4\u65b0\u6240\u6709\u5206\u652f\ngit pull --all \u62c9\u53d6\u6240\u6709\u5206\u652f\ngit remote show origin \u68c0\u67e5\u8fdc\u7a0b\u5206\u652f\u4e0e\u672c\u5730\u5206\u652f\u7684\u5173\u7cfb<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tag\u76f8\u5173\u547d\u4ee4<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">git tag \u67e5\u8be2\u6240\u6709\u7684\u6807\u7b7e<br>git tag ttt \u6253\u4e00\u4e2a\u6807\u7b7ettt<br>git tag -a ttt -m \"xxx\" \u6253\u6807\u7b7ettt\uff0c\u8bf4\u660e\u6587\u5b57xxx<br>git show ttt \u67e5\u770btag\u53ca\u5176\u8bf4\u660e\u6587\u5b57<br>git push origin ttt \u63a8\u9001\u6807\u7b7e\u5230\u8fdc\u7a0b\u4ed3\u5e93<br>git push origin --tags \u63a8\u9001\u6240\u6709\u672c\u5730\u6807\u7b7e\u5230\u8fdc\u7a0b\u4ed3\u5e93<br>git checkout tag_name \u83b7\u53d6tag\u6807\u7b7e\u5bf9\u5e94\u7684\u4ee3\u7801\uff08\u53ea\u662f\u5feb\u7167\uff0c\u65e0\u6cd5\u66f4\u6539\uff09<br>git checkout -b branch_name tag_name \u5728tag\u57fa\u7840\u4e0a\u521b\u5efa\u5206\u652f\uff08\u53ef\u4ee5\u8fdb\u884c\u4fee\u6539\uff09<br>git tag -d ttt \u5220\u9664\u672c\u5730\u6807\u7b7ettt \uff08\u5c1a\u672a\u63a8\u9001\u5230\u8fdc\u7a0b\uff09<br>git push origin --delete ttt (\u5220\u9664\u8fdc\u7a0b\u5e93\u4e2d\u7684ttt\u6807\u7b7e)<br>git fetch --prune --prune-tags \uff08\u6e05\u7406\u672c\u5730\u4e0d\u5b58\u5728\u7684\u8fdc\u7aef tag\uff09<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u5e74\u5f00\u53d1\u5de5\u4f5c\u4ee5\u6765\uff0c\u524d\u524d\u540e\u540e\u7528\u8fc7\u5f88\u591a\u4e2a\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff0c\u4ece\u6700\u65e9\u7684VSS\uff08\u5fae\u8f6f\u7684\u5de5\u5177\uff0c\u73b0\u5728\u5927\u6982\u6ca1\u4eba\u77e5\u9053\u8fd9\u662f\u4e2a\u4ec0\u4e48\u4e1c\u4e1c\u4e86\uff09\uff0c\u5230SVN\u3001ClearCase\u3001mercuria&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.myvoipapp.com\/blogs\/yxh\/2019\/09\/05\/git%e5%85%a5%e9%97%a8%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86\/\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[421,312,314,88,747,315],"class_list":["post-2073","post","type-post","status-publish","format-standard","hentry","category-53","tag-branch","tag-git","tag-hg","tag-svn","tag-747","tag-315"],"_links":{"self":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/2073","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/comments?post=2073"}],"version-history":[{"count":30,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/2073\/revisions"}],"predecessor-version":[{"id":2758,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/posts\/2073\/revisions\/2758"}],"wp:attachment":[{"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/media?parent=2073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/categories?post=2073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myvoipapp.com\/blogs\/yxh\/wp-json\/wp\/v2\/tags?post=2073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}