{"id":509,"date":"2019-07-09T23:14:00","date_gmt":"2019-07-09T15:14:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=509"},"modified":"2023-11-03T23:16:02","modified_gmt":"2023-11-03T15:16:02","slug":"git-basic","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/509","title":{"rendered":"Git basic"},"content":{"rendered":"\n<p>\u5206\u6563\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7d71<br>Git was created by Linus Torvalds in 2005 for development of the Linux kernel<br>Git is free software distributed under the terms of the GNU General Public License version 2<\/p>\n\n\n\n<p><strong>\u5e38\u898b\u7684online Git server<\/strong><br>Github&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/<\/a><br>Gitlab&nbsp;<a href=\"https:\/\/about.gitlab.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/about.gitlab.com\/<\/a><\/p>\n\n\n\n<p><br>refer<br>http:\/\/blog.gogojimmy.net\/2012\/01\/17\/how-to-use-git-1-git-basic\/<br>http:\/\/www.openfoundry.org\/en\/foss-programs\/9318-git-github-firsttry<br>http:\/\/dylandy.github.io\/Easy-Git-Tutorial\/<br>http:\/\/mropengate.blogspot.tw\/2015\/04\/git-github.html<br>http:\/\/gogojimmy.net\/2012\/01\/17\/how-to-use-git-1-git-basic\/<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5f9egit server\u8907\u88fdproject\u5230local<\/strong><\/h2>\n\n\n\n<p>\u5728git server\u4e0a\u770b\u5230\u5f88\u9177\u7684project,\u60f3\u8981\u4e0b\u8f09\u5b83\u73a9\u73a9\u770b\u6642,\u5c31\u8981\u7528clone\u7684\u65b9\u5f0f\u8907\u88fd\u5230\u81ea\u5df1\u7684\u96fb\u8166\u4e0a<\/p>\n\n\n\n<p><strong>\u65b9\u6cd51 \u900f\u904ehttps<\/strong><br>\u9700\u8981\u5bc6\u78bc,\u4f46\u4e0d\u7528\u653ekey\u5728git server\u4e0a<br>\u5f9egit-lab project clone\u5230local<br><strong>git clone https:\/\/gitlab.com\/&lt; account &gt;\/&lt; proejct name &gt;.git<\/strong><\/p>\n\n\n\n<p><strong>\u65b9\u6cd52 \u900f\u904essh<\/strong><br>\u4e0d\u9700\u5bc6\u78bc,\u4f46\u8981\u5148\u653epublic key\u5728git server\u4e0a\u624d\u53ef\u4f7f\u7528<br>\u5f9egit-hub project clone\u5230local<br><strong>git clone -v git@github.com:&lt; account &gt;\/&lt; project name&gt;.git<\/strong><br>\u5f9egit-lab project clone\u5230local<br><strong>git clone -v git@gitlab.com:&lt; account &gt;\/&lt; project name&gt;.git<\/strong><\/p>\n\n\n\n<p><br>ex:<br>\u900f\u904e\u65b9\u6cd51https\u5f9egit-lab\u5c07project\u8f09\u5165\u5230\/root\/git-repos<br><strong># mkdir \/root\/git-repos<br># cd \/root\/git-repos<br># git clone https:\/\/gitlab.com\/raymond0820\/afp2.git<\/strong><br>Cloning into &#8216;afp2&#8217;&#8230;<br>Username for &#8216;https:\/\/gitlab.com&#8217;: raymond0820<br>Password for &#8216;https:\/\/raymond0820@gitlab.com&#8217;:<br>remote: Enumerating objects: 373, done.<br>remote: Counting objects: 100% (373\/373), done.<br>remote: Compressing objects: 100% (314\/314), done.<br>remote: Total 373 (delta 51), reused 373 (delta 51)<br>Receiving objects: 100% (373\/373), 30.38 MiB | 2.57 MiB\/s, done.<br>Resolving deltas: 100% (51\/51), done.<br>Checking connectivity&#8230; done.<\/p>\n\n\n\n<p>ex:<br>\u900f\u904e\u65b9\u6cd52ssh\u5f9egit-hub\u5c07project\u8f09\u5165\u5230\/root\/git-repos<br><strong># mkdir \/root\/git-repos<br># cd \/root\/git-repos<br># git clone -v git@github.com:raymondtestproject\/homework1.git<\/strong><br>Initialized empty Git repository in \/root\/git-repos\/homework1\/.git\/<br>remote: Counting objects: 3, done.<br>remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0<br>Receiving objects: 100% (3\/3), done.<br># ls \/root\/git-repos<\/p>\n\n\n\n<p><br>ps:<br>\u82e5project\u9700\u8981public key\u624d\u53efclone,\u6703\u51fa\u73fe\u4ee5\u4e0b\u8a0a\u606f(<a href=\"https:\/\/systw.net\/note\/af\/sblog\/more.php?id=343\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a>&nbsp;<a href=\"https:\/\/systw.net\/note\/af\/sblog\/more.php?id=343\" target=\"_blank\" rel=\"noreferrer noopener\">\u52a0public key\u7684\u65b9\u6cd5<\/a>&nbsp;&nbsp;)<br><strong># git clone -v git@github.com:raymondtestproject\/homework1.git<\/strong><br>Cloning into &#8216;homework1&#8217;&#8230;<br>The authenticity of host &#8216;github.com (192.30.253.112)&#8217; can&#8217;t be established.<br>RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.<br>Are you sure you want to continue connecting (yes\/no)? yes<br>Warning: Permanently added &#8216;github.com,192.30.253.112&#8217; (RSA) to the list of known hosts.<br>Permission denied (publickey).<br>fatal: Could not read from remote repository.<\/p>\n\n\n\n<p>ps:<br>\u82e5\u5df1\u7d93public key\u653e\u9032git server,\u6210\u529fclone\u7684\u7d50\u679c\u5982\u4e0b<br><strong># git clone -v git@github.com:raymondtestproject\/homework1.git<\/strong><br>Cloning into &#8216;homework1&#8217;&#8230;<br>Enter passphrase for key &#8216;\/root\/.ssh\/id_rsa&#8217;:<br>remote: Counting objects: 1475, done.<br>remote: Total 1475 (delta 0), reused 0 (delta 0), pack-reused 1475<br>Receiving objects: 100% (1475\/1475), 80.38 MiB | 222.00 KiB\/s, done.<br>Resolving deltas: 100% (876\/876), done.<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5f9e\u5916\u90e8git server\u66f4\u65b0\u5230local<\/strong><\/h2>\n\n\n\n<p>git server\u4e0a\u7684project\u82e5\u6709\u66f4\u65b0,\u9700\u8981update\u56delocal<\/p>\n\n\n\n<p><strong>#git pull<\/strong><br>ex:<br><strong>#git pull<\/strong><br>remote: Counting objects: 5, done.<br>remote: Compressing objects: 100% (2\/2), done.<br>remote: Total 5 (delta 3), reused 5 (delta 3), pack-reused 0<br>Unpacking objects: 100% (5\/5), done.<br>From github.com:raymondtestproject\/homework1<br>617bc6a..c9c9938 master -&gt; origin\/master<br>Updating 617bc6a..c9c9938<br>Fast-forward<br>command\/index.php | 79 ++++++++++++++++++++++++++++++++++++++++++<br>integrity\/__init__.pyc | Bin 119 -&gt; 0 bytes<br>integrity\/inc_integrity.pyc | Bin 17265 -&gt; 0 bytes<br>integrity\/lib_typemanage.pyc | Bin 3027 -&gt; 0 bytes<br>lib_detection.pyc | Bin 5354 -&gt; 0 bytes<br>5 files changed, 79 insertions(+), 0 deletions(-)<br>create mode 100644 command\/index.php<br>delete mode 100644 integrity\/__init__.pyc<br>delete mode 100644 integrity\/inc_integrity.pyc<br>delete mode 100644 integrity\/lib_typemanage.pyc<br>delete mode 100644 lib_detection.pyc<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u63d0\u4ea4\u6a94\u6848\u4e26\u5f9elocal\u66f4\u65b0\u5230git server<\/strong><\/h2>\n\n\n\n<p><br>\u5982\u679c\u539f\u672c\u7684\u6a94\u6848\u6709\u4fee\u6539, \u60f3\u66f4\u65b0\u56degit server<\/p>\n\n\n\n<p><strong>#git commit -a \u3000<br>#git push<\/strong><br>ps:<br>git push\u6642\u53ef\u80fd\u6703\u8df3\u51fa\u5bc6\u78bc\u8f38\u5165,\u6b64\u6642\u9700\u8f38\u5165ssh-key\u5efa\u7acb\u6642\u8f38\u5165\u7684passphrase<br>ex:<br><strong>#git commit -a<\/strong><br>writing something<br>#git push<br>Counting objects: 4, done.<br>Delta compression using up to 2 threads.<br>Compressing objects: 100% (2\/2), done.<br>Writing objects: 100% (3\/3), 262 bytes, done.<br>Total 3 (delta 1), reused 0 (delta 0)<br>To ssh:\/\/git@github.com\/Raymond0820\/viewnetflow.git<br>e359453..77156a7 master -&gt; master<\/p>\n\n\n\n<p>ps:<br>\u63d0\u4ea4\u6a94\u6848\u53e6\u4e00\u500b\u65b9\u6cd5<br><strong>#git commit -m &#8220;Add test.rb to test git function&#8221;<\/strong><\/p>\n\n\n\n<p><br>git push\u5e38\u898b\u5931\u6557\u539f\u56e0<br><strong>1.\u51fa\u73fe ! [rejected] master -&gt; master (non-fast forward)\u3000<\/strong><br>\u89e3\u6c7a\u65b9\u5f0f\uff1a<br>\u9019\u4ee3\u8868\u4f60\u7684parent commit\u548c\u9060\u7aef\u7684\u4e0d\u540c\uff0c\u4e5f\u5c31\u662f\u6709\u5206\u5c94\uff0c\u9700\u8981\u5148git pull\u56de\u4f86\uff0c\u8655\u7406\u597dmerge \u624d\u80fdpush\u4e0a\u53bb\u3002<br><strong>2.\u51fa\u73feNo refs in common and none specified; doing nothing. Perhaps you should specify a branch such as &#8216;master&#8217;. fatal: The remote end hung up unexpectedly<\/strong><br>\u89e3\u6c7a\u65b9\u5f0f\uff1a<br>\u57f7\u884cgit push &#8211;set-upstream origin master<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u65b0\u589e\u8981\u8ffd\u8e64\u7684\u6a94\u6848\u66f4\u65b0\u5230git server<\/strong><\/h2>\n\n\n\n<p>\u82e5\u6709\u65b0\u589e\u6a94\u6848\u6642, \u9810\u8a2d\u9019\u6a94\u6848\u6709\u4efb\u4f55\u8b8a\u52d5,\u90fd\u4e0d\u6703\u88abgit\u767c\u73fe,\u56e0\u6b64\u8981\u6307\u4ee4\u6b64\u6a94\u6848\u8981\u88abgit\u8ffd\u8e64, \u8ffd\u8e64\u5f8c\u624d\u53ef\u4ee5\u900f\u904egit push\u66f4\u65b0\u5230git server<\/p>\n\n\n\n<p>\u8981\u8ffd\u8e64\u7684\u6a94\u6848<br><strong>#git add &lt; track file&gt;<\/strong><br>ex:<br>\u589e\u52a0readme\u6a94<br># cd \/root\/git-repos<br>#vim README.md<br><strong>#git add README.md<\/strong><br>ps:<br>\u5982\u679c\u4e00\u6b21\u65b0\u589e\u5f88\u591a\u6a94\u6848\uff0c\u53ef\u4ee5\u8f38\u5165 git add . \u9019\u6703\u5c07\u6240\u6709\u525b\u525b\u65b0\u589e\u52a0\u7684\u6a94\u6848\u4e00\u6b21Add \u9032stage \u72c0\u614b<\/p>\n\n\n\n<p>\u53d6\u6d88\u8ffd\u8e64\u7684\u6a94\u6848<br><strong>#git rm &#8211;cached &lt; filename&gt;<\/strong><br>\u5f9etrack list\u4e2d\u522a\u9664,\u4e0d\u522a\u9664filename<br>ex:<br><strong>#git rm &#8211;cached lib_detection.py<\/strong><br>rm &#8216;lib_detection.pyc&#8217;<\/p>\n\n\n\n<p><br>ps:<br>\u5f9etrack list\u4e2d\u522a\u9664,\u4e26\u5c07filename\u522a\u9664<br><strong>#git rm -f &lt; filename&gt;<\/strong><br>ex:<br><strong>#git rm lib_detection.pyc<\/strong><br>error: &#8216;lib_detection.pyc&#8217; has local modifications<br>(use &#8211;cached to keep the file, or -f to force removal)<\/p>\n\n\n\n<p><br>refer<br>http:\/\/oomusou.io\/git\/git-remove-stage\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5206\u6563\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7d71Git was created by Li &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-develop"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}