{"id":271,"date":"2021-04-27T20:25:32","date_gmt":"2021-04-27T12:25:32","guid":{"rendered":"http:\/\/112.124.66.68\/?p=271"},"modified":"2021-04-27T20:25:32","modified_gmt":"2021-04-27T12:25:32","slug":"%e9%85%8d%e7%bd%ae%e5%8f%8a%e4%bd%bf%e7%94%a8git","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2021\/04\/27\/%e9%85%8d%e7%bd%ae%e5%8f%8a%e4%bd%bf%e7%94%a8git\/","title":{"rendered":"\u914d\u7f6e\u53ca\u4f7f\u7528Git"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u9996\u5148\u5728\u672c\u5730\u521b\u5efa<code>ssh key<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh-keygen -t rsa -C \"your_email@youremail.com\"<\/code><\/pre>\n\n\n\n<p>\u540e\u9762\u7684<code>your_email@youremail.com<\/code>\u6539\u4e3a\u4f60\u5728github\u4e0a\u6ce8\u518c\u7684\u90ae\u7bb1\uff0c\u4e4b\u540e\u4f1a\u8981\u6c42\u786e\u8ba4\u8def\u5f84\u548c\u8f93\u5165\u5bc6\u7801\uff0c\u6211\u4eec\u8fd9\u4f7f\u7528\u9ed8\u8ba4\u7684\u4e00\u8def\u56de\u8f66\u5c31\u884c\u3002\u6210\u529f\u7684\u8bdd\u4f1a\u5728<code>~\/<\/code>\u4e0b\u751f\u6210<code>.ssh<\/code>\u6587\u4ef6\u5939\uff0c\u8fdb\u53bb\uff0c\u6253\u5f00<code>id_rsa.pub<\/code>\uff0c\u590d\u5236\u91cc\u9762\u7684<code>key<\/code>\u3002<\/p>\n\n\n\n<p>\u56de\u5230github\u4e0a\uff0c\u8fdb\u5165 Account Settings\uff08\u8d26\u6237\u914d\u7f6e\uff09\uff0c\u5de6\u8fb9\u9009\u62e9SSH Keys\uff0cAdd SSH Key,title\u6309\u81ea\u5df1\u610f\u613f\u586b\uff0c\u7c98\u8d34\u5728\u4f60\u7535\u8111\u4e0a\u751f\u6210\u7684key\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u9a8c\u8bc1\u662f\u5426\u6210\u529f\uff0c\u5728git bash\u4e0b\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh -T git@github.com<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u662f\u7b2c\u4e00\u6b21\u7684\u4f1a\u63d0\u793a\u662f\u5426continue\uff0c\u8f93\u5165yes\u5c31\u4f1a\u770b\u5230\uff1aYou&#8217;ve successfully authenticated, but GitHub does not provide shell access \u3002\u8fd9\u5c31\u8868\u793a\u5df2\u6210\u529f\u8fde\u4e0agithub\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u505a\u7684\u5c31\u662f\u628a\u672c\u5730\u4ed3\u5e93\u4f20\u5230github\u4e0a\u53bb\uff0c\u5728\u6b64\u4e4b\u524d\u8fd8\u9700\u8981\u8bbe\u7f6eusername\u548cemail\uff0c\u56e0\u4e3agithub\u6bcf\u6b21commit\u90fd\u4f1a\u8bb0\u5f55\u4ed6\u4eec\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git config --global user.name \"your name\"\n$ git config --global user.email \"your_email@youremail.com\"<\/code><\/pre>\n\n\n\n<p>\u8fdb\u5165\u8981\u4e0a\u4f20\u7684\u4ed3\u5e93\uff0c\u53f3\u952egit bash\uff0c\u6dfb\u52a0\u8fdc\u7a0b\u5730\u5740\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git remote add origin git@github.com:yourName\/yourRepo.git<\/code><\/pre>\n\n\n\n<p>\u540e\u9762\u7684yourName\u548cyourRepo\u8868\u793a\u4f60\u518dgithub\u7684\u7528\u6237\u540d\u548c\u521a\u624d\u65b0\u5efa\u7684\u4ed3\u5e93\uff0c\u52a0\u5b8c\u4e4b\u540e\u8fdb\u5165.git\uff0c\u6253\u5f00config\uff0c\u8fd9\u91cc\u4f1a\u591a\u51fa\u4e00\u4e2aremote &#8220;origin&#8221;\u5185\u5bb9\uff0c\u8fd9\u5c31\u662f\u521a\u624d\u6dfb\u52a0\u7684\u8fdc\u7a0b\u5730\u5740\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539config\u6765\u914d\u7f6e\u8fdc\u7a0b\u5730\u5740\u3002\u521b\u5efa\u65b0\u6587\u4ef6\u5939\uff0c\u6253\u5f00\uff0c\u7136\u540e\u6267\u884c<code>\u00a0git init<\/code>\u00a0\u4ee5\u521b\u5efa\u65b0\u7684 git \u4ed3\u5e93\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u68c0\u51fa\u4ed3\u5e93<\/h3>\n\n\n\n<p>\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u4ee5\u521b\u5efa\u4e00\u4e2a\u672c\u5730\u4ed3\u5e93\u7684\u514b\u9686\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone \/path\/to\/repository <\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u662f\u8fdc\u7aef\u670d\u52a1\u5668\u4e0a\u7684\u4ed3\u5e93\uff0c\u4f60\u7684\u547d\u4ee4\u4f1a\u662f\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone username@host:\/path\/to\/repository<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5de5\u4f5c\u6d41<\/h3>\n\n\n\n<p>\u4f60\u7684\u672c\u5730\u4ed3\u5e93\u7531 git \u7ef4\u62a4\u7684\u4e09\u68f5&#8221;\u6811&#8221;\u7ec4\u6210\u3002\u7b2c\u4e00\u4e2a\u662f\u4f60\u7684&nbsp;<code>\u5de5\u4f5c\u76ee\u5f55<\/code>\uff0c\u5b83\u6301\u6709\u5b9e\u9645\u6587\u4ef6\uff1b\u7b2c\u4e8c\u4e2a\u662f&nbsp;<code>\u6682\u5b58\u533a\uff08Index\uff09<\/code>\uff0c\u5b83\u50cf\u4e2a\u7f13\u5b58\u533a\u57df\uff0c\u4e34\u65f6\u4fdd\u5b58\u4f60\u7684\u6539\u52a8\uff1b\u6700\u540e\u662f&nbsp;<code>HEAD<\/code>\uff0c\u5b83\u6307\u5411\u4f60\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u63d0\u51fa\u66f4\u6539\uff08\u628a\u5b83\u4eec\u6dfb\u52a0\u5230\u6682\u5b58\u533a\uff09\uff0c\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<br><code>git add &lt;filename><\/code><br><code>git add *<\/code><br>\u8fd9\u662f git \u57fa\u672c\u5de5\u4f5c\u6d41\u7a0b\u7684\u7b2c\u4e00\u6b65\uff1b\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u4ee5\u5b9e\u9645\u63d0\u4ea4\u6539\u52a8\uff1a<br><code>git commit -m \"\u4ee3\u7801\u63d0\u4ea4\u4fe1\u606f\"<\/code><br>\u73b0\u5728\uff0c\u4f60\u7684\u6539\u52a8\u5df2\u7ecf\u63d0\u4ea4\u5230\u4e86\u00a0<strong>HEAD<\/strong>\uff0c\u4f46\u662f\u8fd8\u6ca1\u5230\u4f60\u7684\u8fdc\u7aef\u4ed3\u5e93\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u63a8\u9001\u6539\u52a8<\/h3>\n\n\n\n<p>\u4f60\u7684\u6539\u52a8\u73b0\u5728\u5df2\u7ecf\u5728\u672c\u5730\u4ed3\u5e93\u7684&nbsp;<strong>HEAD<\/strong>&nbsp;\u4e2d\u4e86\u3002\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u4ee5\u5c06\u8fd9\u4e9b\u6539\u52a8\u63d0\u4ea4\u5230\u8fdc\u7aef\u4ed3\u5e93\uff1a<br><code>git push origin master<\/code><br>\u53ef\u4ee5\u628a&nbsp;<em>master<\/em>&nbsp;\u6362\u6210\u4f60\u60f3\u8981\u63a8\u9001\u7684\u4efb\u4f55\u5206\u652f\u3002&nbsp;<br><br>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u514b\u9686\u73b0\u6709\u4ed3\u5e93\uff0c\u5e76\u6b32\u5c06\u4f60\u7684\u4ed3\u5e93\u8fde\u63a5\u5230\u67d0\u4e2a\u8fdc\u7a0b\u670d\u52a1\u5668\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u6dfb\u52a0\uff1a<br><code>git remote add origin &lt;server&gt;<\/code><br>\u5982\u6b64\u4f60\u5c31\u80fd\u591f\u5c06\u4f60\u7684\u6539\u52a8\u63a8\u9001\u5230\u6240\u6dfb\u52a0\u7684\u670d\u52a1\u5668\u4e0a\u53bb\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5206\u652f<\/h3>\n\n\n\n<p>\u5206\u652f\u662f\u7528\u6765\u5c06\u7279\u6027\u5f00\u53d1\u7edd\u7f18\u5f00\u6765\u7684\u3002\u5728\u4f60\u521b\u5efa\u4ed3\u5e93\u7684\u65f6\u5019\uff0c<em>master<\/em>\u00a0\u662f&#8221;\u9ed8\u8ba4\u7684&#8221;\u5206\u652f\u3002\u5728\u5176\u4ed6\u5206\u652f\u4e0a\u8fdb\u884c\u5f00\u53d1\uff0c\u5b8c\u6210\u540e\u518d\u5c06\u5b83\u4eec\u5408\u5e76\u5230\u4e3b\u5206\u652f\u4e0a\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u4e00\u4e2a\u53eb\u505a&#8221;feature_x&#8221;\u7684\u5206\u652f\uff0c\u5e76\u5207\u6362\u8fc7\u53bb\uff1a<br><code>git checkout -b feature_x<\/code><br>\u5207\u6362\u56de\u4e3b\u5206\u652f\uff1a<br><code>git checkout master<\/code><br>\u518d\u628a\u65b0\u5efa\u7684\u5206\u652f\u5220\u6389\uff1a<br><code>git branch -d feature_x<\/code><br>\u9664\u975e\u4f60\u5c06\u5206\u652f\u63a8\u9001\u5230\u8fdc\u7aef\u4ed3\u5e93\uff0c\u4e0d\u7136\u8be5\u5206\u652f\u5c31\u662f&nbsp;<em>\u4e0d\u4e3a\u4ed6\u4eba\u6240\u89c1\u7684<\/em>\uff1a<br><code>git push origin &lt;branch&gt;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u66f4\u65b0\u4e0e\u5408\u5e76<\/h3>\n\n\n\n<p>\u8981\u66f4\u65b0\u4f60\u7684\u672c\u5730\u4ed3\u5e93\u81f3\u6700\u65b0\u6539\u52a8\uff0c\u6267\u884c\uff1a<br><code>git pull<\/code><br>\u4ee5\u5728\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55\u4e2d&nbsp;<em>\u83b7\u53d6\uff08fetch\uff09<\/em>&nbsp;\u5e76&nbsp;<em>\u5408\u5e76\uff08merge\uff09<\/em>&nbsp;\u8fdc\u7aef\u7684\u6539\u52a8\u3002<br>\u8981\u5408\u5e76\u5176\u4ed6\u5206\u652f\u5230\u4f60\u7684\u5f53\u524d\u5206\u652f\uff08\u4f8b\u5982 master\uff09\uff0c\u6267\u884c\uff1a<br><code>git merge &lt;branch&gt;<\/code><br>\u5728\u8fd9\u4e24\u79cd\u60c5\u51b5\u4e0b\uff0cgit \u90fd\u4f1a\u5c1d\u8bd5\u53bb\u81ea\u52a8\u5408\u5e76\u6539\u52a8\u3002\u9057\u61be\u7684\u662f\uff0c\u8fd9\u53ef\u80fd\u5e76\u975e\u6bcf\u6b21\u90fd\u6210\u529f\uff0c\u5e76\u53ef\u80fd\u51fa\u73b0<em>\u51b2\u7a81\uff08conflicts\uff09<\/em>\u3002 \u8fd9\u65f6\u5019\u5c31\u9700\u8981\u4f60\u4fee\u6539\u8fd9\u4e9b\u6587\u4ef6\u6765\u624b\u52a8\u5408\u5e76\u8fd9\u4e9b<em>\u51b2\u7a81\uff08conflicts\uff09<\/em>\u3002\u6539\u5b8c\u4e4b\u540e\uff0c\u4f60\u9700\u8981\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u4ee5\u5c06\u5b83\u4eec\u6807\u8bb0\u4e3a\u5408\u5e76\u6210\u529f\uff1a<br><code>git add &lt;filename&gt;<\/code><br>\u5728\u5408\u5e76\u6539\u52a8\u4e4b\u524d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u9884\u89c8\u5dee\u5f02\uff1a<br><code>git diff &lt;source_branch&gt; &lt;target_branch&gt;<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6807\u7b7e<\/h3>\n\n\n\n<p>\u4e3a\u8f6f\u4ef6\u53d1\u5e03\u521b\u5efa\u6807\u7b7e\u662f\u63a8\u8350\u7684\u3002\u8fd9\u4e2a\u6982\u5ff5\u65e9\u5df2\u5b58\u5728\uff0c\u5728 SVN \u4e2d\u4e5f\u6709\u3002\u4f60\u53ef\u4ee5\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u53eb\u505a&nbsp;<em>1.0.0<\/em>&nbsp;\u7684\u6807\u7b7e\uff1a<br><code>git tag 1.0.0 1b2e1d63ff<\/code><br><em>1b2e1d63ff<\/em>&nbsp;\u662f\u4f60\u60f3\u8981\u6807\u8bb0\u7684\u63d0\u4ea4 ID \u7684\u524d 10 \u4f4d\u5b57\u7b26\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0b\u5217\u547d\u4ee4\u83b7\u53d6\u63d0\u4ea4 ID\uff1a<br><code>git log<\/code><br>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5c11\u4e00\u70b9\u7684\u63d0\u4ea4 ID \u524d\u51e0\u4f4d\uff0c\u53ea\u8981\u5b83\u7684\u6307\u5411\u5177\u6709\u552f\u4e00\u6027\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u66ff\u6362\u672c\u5730\u6539\u52a8<\/h3>\n\n\n\n<p>\u5047\u5982\u4f60\u64cd\u4f5c\u5931\u8bef\uff08\u5f53\u7136\uff0c\u8fd9\u6700\u597d\u6c38\u8fdc\u4e0d\u8981\u53d1\u751f\uff09\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u66ff\u6362\u6389\u672c\u5730\u6539\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout -- &lt;filename><\/code><\/pre>\n\n\n\n<p><br>\u6b64\u547d\u4ee4\u4f1a\u4f7f\u7528 HEAD \u4e2d\u7684\u6700\u65b0\u5185\u5bb9\u66ff\u6362\u6389\u4f60\u7684\u5de5\u4f5c\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002\u5df2\u6dfb\u52a0\u5230\u6682\u5b58\u533a\u7684\u6539\u52a8\u4ee5\u53ca\u65b0\u6587\u4ef6\u90fd\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u5047\u5982\u4f60\u60f3\u4e22\u5f03\u4f60\u5728\u672c\u5730\u7684\u6240\u6709\u6539\u52a8\u4e0e\u63d0\u4ea4\uff0c\u53ef\u4ee5\u5230\u670d\u52a1\u5668\u4e0a\u83b7\u53d6\u6700\u65b0\u7684\u7248\u672c\u5386\u53f2\uff0c\u5e76\u5c06\u4f60\u672c\u5730\u4e3b\u5206\u652f\u6307\u5411\u5b83\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git fetch origin\ngit reset --hard origin\/master<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b9e\u7528\u5c0f\u8d34\u58eb<\/h3>\n\n\n\n<p>\u5185\u5efa\u7684\u56fe\u5f62\u5316 git<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitk<\/code><\/pre>\n\n\n\n<p><br>\u5f69\u8272\u7684 git \u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config color.ui true<\/code><\/pre>\n\n\n\n<p><br>\u663e\u793a\u5386\u53f2\u8bb0\u5f55\u65f6\uff0c\u6bcf\u4e2a\u63d0\u4ea4\u7684\u4fe1\u606f\u53ea\u663e\u793a\u4e00\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config format.pretty oneline<\/code><\/pre>\n\n\n\n<p><br>\u4ea4\u4e92\u5f0f\u6dfb\u52a0\u6587\u4ef6\u5230\u6682\u5b58\u533a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add -i<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u5728\u672c\u5730\u521b\u5efassh key \u540e&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-github"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=271"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/271\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/274"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}