{"id":515,"date":"2021-06-13T17:21:12","date_gmt":"2021-06-13T09:21:12","guid":{"rendered":"https:\/\/www.wangliguang.cn\/?p=515"},"modified":"2021-06-13T17:21:12","modified_gmt":"2021-06-13T09:21:12","slug":"git%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/wangliguang.cn\/?p=515","title":{"rendered":"git\u5165\u95e8\u6559\u7a0b"},"content":{"rendered":"<h2>\u80cc\u666f<\/h2>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u6c47\u603b\u4e86\u6211\u5e73\u65f6\u7528\u5230\u7684git\u76f8\u5173\u77e5\u8bc6\u548c\u547d\u4ee4\uff0c\u540c\u65f6\u8bb0\u5f55\u4e86\u6211\u9047\u5230\u7684\u7591\u96be\u70b9\u548c\u7b54\u6848\uff0c\u529b\u6c42\u4ece\u4e0b\u8f7dgit\u5230\u5b66\u4f1a\u4f7f\u7528\u4e00\u6587\u89e3\u51b3\u3002\u5728\u64b0\u5199\u672c\u6587\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4e5f\u53c2\u8003\u4e86\u8bb8\u591a\u7f51\u9875\u548c\u8d44\u6599\uff0c\u5c06\u5728\u6587\u540e\u53c2\u8003\u8d44\u6599\u5c0f\u8282\u5168\u90e8\u5217\u51fa\u3002<\/p>\n<h2>\u5305\u542b\u5185\u5bb9<\/h2>\n<p>\u8bfb\u5b8c\u672c\u6587\uff0c\u5c06\u53ef\u4ee5\u89e3\u51b3\u4ee5\u4e0b\u95ee\u9898\uff1a<br \/>\ngit\u5982\u4f55\u914d\u7f6e\uff0c\u5982\u4f55\u5c06\u672c\u673a\u548cgithub\u901a\u8fc7\u5bc6\u94a5\u5173\u8054<br \/>\ngit\u5982\u4f55\u5efa\u7acb\u672c\u5730\u7248\u672c\u5e93\uff0c\u5982\u4f55\u4e0egithub\u6216gitee\u7b49\u8fdc\u7a0b\u4ed3\u5e93\u8fde\u63a5\uff0c\u5982\u4f55\u540c\u65f6\u4e0egithub\u548cgitee\u7684\u8fdc\u7a0b\u4ed3\u5e93\u8fde\u63a5\u3002<br \/>\ngit\u5982\u4f55\u63a8\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<br \/>\ngit\u5982\u4f55\u5efa\u7acb\u5206\u652f\uff0c\u5982\u4f55\u5207\u6362\u5206\u652f\uff0c\u5982\u4f55\u5408\u5e76\u5206\u652f\u3002<br \/>\ngit\u5982\u4f55\u56de\u9000\u5230\u4e0a\u4e00\u4e2a\u7248\u672c\uff0c\u6709\u4e9b\u6587\u4ef6\u6539\u9519\u4e86\uff0c\u4e0d\u77e5\u9053\u6539\u4e86\u54ea\u4e9b\uff0c\u5982\u4f55\u653e\u5f03\u6389\u672c\u5730\u7684\u66f4\u6539\u3002<\/p>\n<h2>1 git\u914d\u7f6e<\/h2>\n<p>1\u3001\u8bbe\u7f6e\u7528\u6237\u540d\u548c\u90ae\u7bb1(--global \u4e3a\u5168\u5c40\u53c2\u6570\uff0c\u8868\u660e\u672c\u5730\u6240\u6709Git\u4ed3\u5e93\u90fd\u4f1a\u4f7f\u7528\u8fd9\u4e2a\u914d\u7f6e)<\/p>\n<pre><code>git config --global user.name &quot;yourname&quot;\ngit config --global user.email &quot;your_email@youremail.com&quot;<\/code><\/pre>\n<p>2\u3001\u751f\u6210\u5bc6\u94a5(SSH key)<\/p>\n<pre><code>ssh-keygen -t rsa -C &quot;your_email@youremail.com&quot;<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/liguang.wang\/usr\/uploads\/2021\/06\/4076730804.png\" alt=\"967677-20180127235546537-326832952.png\" \/><br \/>\n3\u3001\u5728github\u4e2d\u6dfb\u52a0\u5bc6\u94a5\u3002<br \/>\n\u5c06\u4e0a\u4e00\u6b65\u9aa4\u751f\u6210\u7684\u5bc6\u94a5\u5373.ssh\/id_rsa.pub\u4e2d\u5185\u5bb9\u5168\u90e8\u590d\u5236\u3002\u5728github\u7684 Settings--&gt;SSH and GPG keys--&gt;New SSH key\uff0ckey\u4e2d\u7c98\u8d34\u590d\u5236\u7684\u5185\u5bb9(Title\u81ea\u5b9a\u4e49)\u3002<\/p>\n<h2>2 \u521b\u5efa\u7248\u672c\u5e93\u5e76\u8fde\u63a5\u8fdc\u7a0b\u4ed3\u5e93<\/h2>\n<p>1\u3001\u5148\u6765\u4e86\u89e3git\u7684\u5de5\u4f5c\u6d41\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/liguang.wang\/usr\/uploads\/2021\/06\/2755306465.png\" alt=\"Screenshot from 2021-06-13 16-26-56.png\" \/><br \/>\ngit\u7684\u5de5\u4f5c\u8fc7\u7a0b\u5c31\u662f\uff0c\u81ea\u5df1\u4fee\u6539\u4e86\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u5185\u5bb9\uff0c\u7136\u540e\u901a\u8fc7\u547d\u4ee4\u63d0\u4ea4\u5230\u6682\u5b58\u533a\uff0c\u7136\u540e\u901a\u8fc7\u547d\u4ee4\u63d0\u4ea4HEAD\uff0c\u5b83\u6307\u5411\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u7ed3\u679c\uff0c\u7136\u540e\u901a\u8fc7\u547d\u4ee4\u63d0\u4ea4\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<br \/>\n2\u3001\u8fdb\u5165\u81ea\u5df1\u9879\u76ee\u6587\u4ef6\u5939\uff0c\u8f93\u5165<code>git init<\/code>\uff0c\u4e5f\u5c31\u662f\u5728\u672c\u5730\u5efa\u7acb\u4e86\u65b0\u7684\u4ed3\u5e93\u3002<br \/>\n3\u3001\u8fde\u63a5\u8fdc\u7aef\u4ed3\u5e93\u3002\u9996\u5148\u9700\u8981\u5148\u5728github\u6216\u8005gitee\u5efa\u7acb\u4e00\u4e2a\u4ed3\u5e93\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u548c\u8fdc\u7aef\u4ed3\u5e93\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<pre><code>git remote add origin git@github.com:yourName\/repositoryname.git  #\u901a\u8fc7ssh\u65b9\u5f0f\uff08\u63a8\u8350\uff0c\u56e0\u4e3a\u6211\u4eec\u524d\u9762\u5df2\u7ecf\u914d\u7f6e\u4e86ssh\uff09\ngit remote add origin https:\/\/github.com\/yourName\/repositoryname.git  #\u901a\u8fc7https\u65b9\u5f0f<\/code><\/pre>\n<p>\u8fd9\u91cc\u6709\u4eba\u5c31\u4f1a\u95ee\u4e86\uff0c\u540e\u9762\u8fd9\u4e2a\u5730\u5740\u600e\u4e48\u5f97\u5230\u5462\uff1f\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5728github\u6216\u8005gitee\u7684\u53f3\u4e0a\u89d2\uff0c\u9009\u62e9\u4e0b\u8f7d\u4ee3\u7801\uff0c\u91cc\u9762\u9009\u62e9ssh\uff0c\u7136\u540e\u628a\u5730\u5740\u590d\u5236\u4e0b\u6765\u5c31\u597d\u4e86\u3002\u5982\u56fe\u6240\u793a\u5927\u6982\u4f4d\u7f6e\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/liguang.wang\/usr\/uploads\/2021\/06\/1546036858.png\" alt=\"Screenshot from 2021-06-13 16-34-35.png\" \/><br \/>\n\u8fd9\u91cc\u6ce8\u610f\uff0c\u8fd9\u4e2a\u547d\u4ee4\u91cc\u9762\u7684origin\u662f\u4f60\u81ea\u5df1\u8d77\u7684\u540d\u5b57\uff0c\u53ef\u4ee5\u4efb\u610f\u6539\u3002\u5982\u679c\u8981\u540c\u65f6\u5c06\u672c\u5730\u4ed3\u5e93\u548cgithub\u4e0egitee\u4ed3\u5e93\u8fde\u63a5\u8d77\u6765\u7684\u8bdd\uff0c\u90a3\u5c31\u4e00\u4e2a\u7528origin1\uff0c\u4e00\u4e2a\u7528origin2\u5c31\u597d\u4e86\uff0c\u6267\u884c\u4e24\u904d\u4e0a\u9762\u7684\u547d\u4ee4\uff0c\u90a3\u5c31\u662f\u5206\u522b\u548cgithub\u4e0egitee\u5efa\u7acb\u4e86\u8fde\u63a5\u3002<\/p>\n<h2>3 \u5982\u4f55\u63a8\u5230\u8fdc\u7aef\u4ed3\u5e93<\/h2>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5206\u522b\u5c06\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\uff08\u5728\u672c\u5730\u76ee\u5f55\u4e2d\uff09\uff0c\u63d0\u4ea4\u5230\u6682\u5b58\u533a\uff0c\u7136\u540e\u63d0\u4ea4\u5230HEAD\uff0c\u7136\u540e\u63d0\u4ea4\u5230\u8fdc\u7aef\u4ed3\u5e93\u3002<\/p>\n<pre><code>git add &lt;file&gt;\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u5c06\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff0c\u5982\u679c\u8981\u5c06\u5de5\u4f5c\u76ee\u5f55\u4e2d\u6240\u6709\u7684\u6587\u4ef6\u90fd\u63d0\u4ea4\u5230\u6682\u5b58\u533a\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528git add .\ngit commit -m &quot;commnet&quot; \u3000\u3000\u63d0\u4ea4\u66f4\u6539,\u6dfb\u52a0\u5907\u6ce8\u4fe1\u606f(\u6b64\u65f6\u5c06\u6682\u5b58\u533a\u7684\u4fe1\u606f\u63d0\u4ea4\u5230\u672c\u5730HEAD)\ngit push origin master \u3000\u3000 \u5c06\u672c\u5730\u4ed3\u5e93\u7684\u6587\u4ef6push\u5230\u8fdc\u7a0b\u4ed3\u5e93(\u82e5 push \u4e0d\u6210\u529f\uff0c\u53ef\u52a0 -f \u8fdb\u884c\u5f3a\u63a8\u64cd\u4f5c)<\/code><\/pre>\n<h2>4 \u5982\u4f55\u5efa\u7acb\u3001\u5207\u6362\u3001\u5408\u5e76\u5206\u652f<\/h2>\n<p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981\u5f00\u53d1\u65b0\u7684\u7279\u6027\uff0c\u4e0d\u8981\u76f4\u63a5\u5728\u4e3b\u5206\u652f\u4e0a\u5f00\u53d1\uff0c\u800c\u662f\u5e94\u8be5\u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u7136\u540e\u5728\u65b0\u7684\u5206\u652f\u4e0a\u5f00\u53d1\uff0c\u6700\u540e\u4e0e\u4e3b\u5206\u652f\u5408\u5e76\u3002<br \/>\n1\u3001\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5efa\u7acb\u5e76\u5207\u6362\u5230\u65b0\u7684\u5206\u652f\u3002<\/p>\n<pre><code>git checkout -b branch_name<\/code><\/pre>\n<p>2\u3001\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5207\u6362\u5206\u652f<\/p>\n<pre><code>git chceckout branch_name<\/code><\/pre>\n<p>3\u3001\u5c06\u5176\u4ed6\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<pre><code>git merge branch_name_you_want_to_merge<\/code><\/pre>\n<h2>5 \u5982\u4f55\u56de\u9000\u7248\u672c<\/h2>\n<p>1\u3001\u4f7f\u7528<code>git log<\/code>\u67e5\u5230\u4f60\u60f3\u56de\u9000\u7248\u672c\u7684id\u3002<br \/>\n2\u3001\u4f7f\u7528<code>git reset --hard id<\/code>\u8fdb\u884c\u56de\u9000\u3002\u6ce8\u610f\uff0c\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u540e\uff0c\u518d\u4f7f\u7528<code>git log<\/code>\u67e5\u770bid\u7684\u65f6\u5019\uff0c\u4f1a\u53d1\u73b0\u53ea\u4fdd\u7559\u5230\u4f60\u9000\u8fc7\u6765\u7684\u8fd9\u4e2aid\uff0c\u6bd4\u5b83\u65b0\u7684\u90fd\u5df2\u7ecf\u6ca1\u6709\u4e86\u3002\u5982\u679c\u8fd9\u65f6\u5019\u4f60\u60f3\u53cd\u6094\uff0c\u4e5f\u5c31\u662f\u60f3\u201c\u5f80\u524d\u56de\u9000\u201d\uff0c\u9700\u8981\u4f7f\u7528<code>git reflog<\/code>\u547d\u4ee4\u67e5id\uff0c\u7136\u540e\u4f7f\u7528\u76f8\u540c\u7684\u547d\u4ee4\u5c31\u53ef\u4ee5\u201c\u5f80\u524d\u56de\u9000\u201d\u4e86\u3002<br \/>\n3\u3001\u5982\u679c\u4e0d\u60f3\u5411\u4e0a\u9762\u90a3\u6837\u56de\u9000\uff08\u56e0\u4e3aid\u4f1a\u6d88\u5931\uff09\uff0c\u90a3\u5c31\u4f7f\u7528<code>git convert --hard id<\/code>\u6765\u8fdb\u884c\u56de\u9000\u3002\u8fd9\u65f6\u5019\u4f7f\u7528<code>git log<\/code>\u8fd8\u80fd\u770b\u5230\u6bd4\u5f53\u524d\u7248\u672c\u66f4\u65b0\u7684<code>commit id<\/code>\u3002<br \/>\n4\u3001\u4f7f\u7528<code>git push -f origin master<\/code>\u6765\u66f4\u65b0\u8fdc\u7aef\u4ed3\u5e93\u4e2d\u7684\u5185\u5bb9\u3002<br \/>\n5\u3001\u5982\u679c\u4e0d\u5c0f\u5fc3\u6539\u9519\u4e86\uff0c\u60f3\u653e\u5f03\u4fee\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528<code>git checkout -- \u6539\u9519\u7684\u6587\u4ef6\u540d<\/code>\u6765\u653e\u5f03\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u4fee\u6539\uff0c\u56de\u5230\u4f60\u4e0a\u6b21\u63d0\u4ea4\u7684\u7248\u672c\u3002\u6ce8\u610f\uff0c\u5982\u679c\u6b64\u65f6\u4f60\u5df2\u7ecf\u5c06\u9519\u8bef\u7684\u547d\u4ee4\u63d0\u4ea4\u5230\u6682\u5b58\u533a\uff0c\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\u662f\u65e0\u6548\u7684\uff0c\u4f60\u9700\u8981\u5148\u4f7f\u7528<code>git reset HEAD \u6539\u9519\u7684\u6587\u4ef6\u540d<\/code>\u6765\u653e\u5f03\u6682\u5b58\u533a\u4e2d\u7684\u5185\u5bb9\uff0c\u7136\u540e\u518d\u4f7f\u7528<code>git checkout -- \u6539\u9519\u7684\u6587\u4ef6\u540d<\/code>\u6765\u653e\u5f03\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u4fee\u6539\u3002<\/p>\n<h2>6 \u7591\u96be\u95ee\u9898<\/h2>\n<p>1\u3001\u6211\u6709\u4e24\u4e2a\u5206\u652f\uff0c\u6211\u6539\u4e86\u4e00\u4e2a\u5206\u652f\u4e2d\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u90a3\u53e6\u4e00\u4e2a\u5206\u652f\u4e2d\u7684\u672c\u5730\u76ee\u5f55\u7684\u6587\u4ef6\u4f1a\u88ab\u4fee\u6539\u5417\uff1f<br \/>\n\u8fd9\u4e2a\u9700\u8981\u5206\u60c5\u51b5\u8ba8\u8bba\u3002<br \/>\n\u5982\u679c\u4f60\u5728A\u5206\u652f\u66f4\u6539\u4e86\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u7136\u540e\u6ca1\u6709\u4fdd\u5b58\u5230\u6682\u5b58\u533a\u5c31\u4f7f\u7528<code>git checkout<\/code>\u5207\u6362\u4e86\u5206\u652f\uff0c\u90a3\u4e48\u5f88\u62b1\u6b49\u53e6\u4e00\u4e2a\u5206\u652f\u7684\u672c\u5730\u76ee\u5f55\u7684\u76f8\u5e94\u6587\u4ef6\u4e5f\u88ab\u66f4\u6539\u4e86\u3002<br \/>\n\u5982\u679c\u4f60\u5728A\u5206\u652f\u66f4\u6539\u4e86\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u7136\u540e\u4fdd\u5b58\u5230\u4e86\u6682\u5b58\u533a\u540e\u60f3\u4f7f\u7528<code>git checkout<\/code>\u5207\u6362\u5206\u652f\uff0c\u90a3\u4e48\u6b64\u65f6\u4f1a\u62a5\u9519\u65e0\u6cd5\u6210\u529f\u5b8c\u6210\u5206\u652f\u5207\u6362\uff0c\u4f1a\u63d0\u793a\u4f60\u5148\u63d0\u4ea4\u3002<br \/>\n\u5982\u679c\u4f60\u5728A\u5206\u652f\u66f4\u6539\u4e86\u672c\u5730\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\uff0c\u7136\u540e\u4fdd\u5b58\u5230\u4e86\u6682\u5b58\u533a\uff0c\u7136\u540e\u63d0\u4ea4\u5230\u4e86HEAD\uff0c\u7136\u540e\u4f7f\u7528<code>git checkout<\/code>\u5207\u6362\u5206\u652f\uff0c\u90a3\u4e48\u5e76\u4e0d\u4f1a\u66f4\u6539\u4f60\u521a\u5207\u6362\u5230\u7684\u8fd9\u4e2a\u5206\u652f\u91cc\u7684\u672c\u5730\u76ee\u5f55\u7684\u6587\u4ef6\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<p>\u4ee5\u4e0b\u4e24\u4e2a\u7f51\u7ad9\u5185\u5bb9\u4e30\u5bcc\uff0c\u63a8\u8350\u9605\u8bfb\uff01<br \/>\n<a href=\"https:\/\/rogerdudler.github.io\/git-guide\/index.zh.html\">https:\/\/rogerdudler.github.io\/git-guide\/index.zh.html<\/a><br \/>\n<a href=\"https:\/\/www.cnblogs.com\/zeo-to-one\/p\/8367801.html\">https:\/\/www.cnblogs.com\/zeo-to-one\/p\/8367801.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u8fd9\u7bc7\u6587\u7ae0\u6c47\u603b\u4e86\u6211\u5e73\u65f6\u7528\u5230\u7684git\u76f8\u5173\u77e5\u8bc6\u548c\u547d\u4ee4\uff0c\u540c\u65f6\u8bb0\u5f55\u4e86\u6211\u9047\u5230\u7684\u7591\u96be\u70b9\u548c\u7b54\u6848\uff0c\u529b\u6c42\u4ece\u4e0b\u8f7dgit\u5230\u5b66\u4f1a\u4f7f&hellip; <a href=\"https:\/\/wangliguang.cn\/?p=515\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">git\u5165\u95e8\u6559\u7a0b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-515","post","type-post","status-publish","format-standard","hentry","category-git"],"_links":{"self":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=515"}],"version-history":[{"count":0,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/515\/revisions"}],"wp:attachment":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}