{"id":89,"date":"2017-09-01T16:09:12","date_gmt":"2017-09-01T08:09:12","guid":{"rendered":"http:\/\/sgvps.hyh0.com\/?p=89"},"modified":"2020-08-25T23:23:29","modified_gmt":"2020-08-25T15:23:29","slug":"git%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.hyh0.com\/?p=89","title":{"rendered":"Git\u5165\u95e8\u4f7f\u7528"},"content":{"rendered":"<p>\u4eceGit\u7684\u5b89\u88c5\u5230Git\u7684\u57fa\u7840\u7528\u6cd5<\/p>\n<p><!--more--><\/p>\n<h2>\u5b89\u88c5Git<\/h2>\n<p>Debian8:<\/p>\n<p>$ sudo apt-get install git<\/p>\n<h2>\u521d\u59cb\u5316<\/h2>\n<p><span class=\"katex math inline\">git config &#8211;global user.name &#8220;Your Name Comes Here&#8221;<\/span> git config &#8211;global user.email\u00a0 you@yourdomain.example.com<\/p>\n<h2>\u65b0\u5efa\u4ed3\u5e93<\/h2>\n<ol>\n<li>\u7528cd\u6253\u5f00\u5230\u9879\u76ee\u7684\u76ee\u5f55<\/li>\n<li>$ git init #\u521b\u5efa\u4ed3\u5e93\uff0c \u4f1a\u5f97\u5230 Initialized empty Git repository in .git\/<\/li>\n<li>$ git add . #\u5c06\u5f53\u524d\u6240\u6709\u6587\u4ef6\u7ed9git\u7ba1\u7406<\/li>\n<li>$ git commit #\u63d0\u4ea4\u66f4\u6539<\/li>\n<\/ol>\n<h2>\u67e5\u8be2\u72b6\u6001<\/h2>\n<p><span class=\"katex math inline\">git status #\u67e5\u8be2\u5f53\u524d\u7684\u6587\u4ef6\u72b6\u6001\uff08\u7528-s\u53c2\u6570\u663e\u793a\u7b80\u8981\u4fe1\u606f\uff09<\/span> git log #\u663e\u793a\u5386\u53f2\u4fee\u6539\u60c5\u51b5\uff08\u4fee\u6539\u65f6\u95f4\uff0c\u4fee\u6539\u63cf\u8ff0)<\/p>\n<p><span class=\"katex math inline\">git log -p #\u663e\u793a\u8be6\u7ec6\u65e5\u5fd7\uff08\u5305\u62ec\u4fee\u6539\u7684\u90e8\u5206\uff09<\/span> git log &#8211;stat &#8211;summary #\u663e\u793a\u6458\u8981\uff08\u9664\u9ed8\u8ba4\u663e\u793a\u5916\u8fd8\u5305\u62ec\u4fee\u6539\u91cf\uff09<\/p>\n<h2>\u63d0\u4ea4\u4fee\u6539<\/h2>\n<ol>\n<li>$ git add files&#8230; #\u6807\u8bb0\u8981\u63d0\u4ea4\u7684\u6587\u4ef6<\/li>\n<li>$ git diff &#8211;cached(\u4e0estaged\u6548\u679c\u76f8\u540c) #\u663e\u793a\u4fee\u6539\u7684\u5185\u5bb9\uff08\u53ef\u9009\u64cd\u4f5c\uff09<\/li>\n<li>$ git commit #\u63d0\u4ea4\u4fee\u6539\uff08\u53ef\u4ee5\u7528 -m &#8216;MESSGAE&#8217; \u53c2\u6570\u76f4\u63a5\u8f93\u5165\u7248\u672c\u8bf4\u660e\uff09<\/li>\n<\/ol>\n<p>\u4e5f\u53ef\u4ee5<\/p>\n<ol>\n<li>$git commit -a #\u76f4\u63a5\u63d0\u4ea4\u6240\u6709\u4fee\u6539\uff0c\u4e0d\u9700\u8981\u7528-a\u6807\u8bb0<\/li>\n<\/ol>\n<h2>\u5ffd\u7565\u6587\u4ef6<\/h2>\n<p>\u5982\u679c\u4e0d\u5e0c\u671bgit\u6ce8\u610f\u5230\u67d0\u4e9b\u6587\u4ef6\uff08\u751a\u81f3\u4e0d\u663e\u793auntracked\uff09\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a .gitignore\u6587\u4ef6\uff0c\u6587\u4ef6\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# no .a files\r\n*.a\r\n\r\n# but do track lib.a, even though you're ignoring .a files above\r\n!lib.a\r\n\r\n# only ignore the TODO file in the current directory, not subdir\/TODO\r\n\/TODO\r\n\r\n# ignore all files in the build\/ directory\r\nbuild\/\r\n\r\n# ignore doc\/notes.txt, but not doc\/server\/arch.txt\r\ndoc\/*.txt\r\n\r\n# ignore all .pdf files in the doc\/ directory and any of its subdirectories\r\ndoc\/**\/*.pdf\r\n<\/pre>\n<p>\u00a0<\/p>\n<h2>\u5206\u652f\u7ba1\u7406<\/h2>\n<p><span class=\"katex math inline\">git branch #\u663e\u793a\u5206\u652f\u5217\u8868<\/span> git branch\u00a0 NAME #\u521b\u5efa\u5206\u652f<\/p>\n<p><span class=\"katex math inline\">git branch -d NAME #\u5220\u9664\u5206\u652f(\u5c06\u4f1a\u68c0\u67e5\u5206\u652f\u4e2d\u7684\u4ee3\u7801\u662f\u5426\u5408\u5e76)<\/span> git branch -D NAME #\u5220\u9664\u5206\u652f(\u4e0d\u4f1a\u68c0\u67e5\u662f\u5426\u5408\u5e76)<\/p>\n<p><span class=\"katex math inline\">git checkout NAME #\u9009\u62e9\u5206\u652f<\/span> git merge NAME #\u5c06NAME\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f<\/p>\n<p>\u5f53\u51fa\u73b0\u5408\u5e76\u51b2\u7a81\u65f6\uff08\u5982\u5bf9\u540c\u4e00\u4e2a\u4f4d\u7f6e\u8fdb\u884c\u4e86\u4e0d\u540c\u7684\u4fee\u6539\uff09<\/p>\n<p>$ git diff #\u67e5\u770b\u51b2\u7a81\u7684\u4f4d\u7f6e<\/p>\n<p>\u540c\u65f6\u4e5f\u4f1a\u5728\u6587\u4ef6\u4e2d\u6807\u8bb0\u51b2\u7a81\uff0c\u683c\u5f0f\u5982\u4e0b<\/p>\n<p>++&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD<\/p>\n<p>+\u5f53\u524d\u5206\u652f\u7684\u5185\u5bb9<\/p>\n<p>++===========<\/p>\n<p>+\u00a0 \u88ab\u5408\u5e76\u5206\u652f\u7684\u5185\u5bb9<\/p>\n<p>++>>>>>>>>>>>>><\/p>\n<p>\u8fd9\u65f6\u9700\u8981\u7f16\u8f91\u6587\u4ef6\u89e3\u51b3\u51b2\u7a81\u5e76commit\uff08\u4e0d\u9700\u8981\u91cd\u65b0merge\uff09<\/p>\n<h2>\u534f\u4f5c\u7ba1\u7406<\/h2>\n<p><span class=\"katex math inline\">git clone [\u5176\u5b83\u7528\u6237\u7684\u9879\u76ee\u8def\u5f84] [\u4ed3\u5e93\u7684\u540d\u5b57(\u53ef\u9009\uff0c\u5982\u679c\u6ca1\u6709\u5219\u662f\u539f\u6765\u7684\u540d\u5b57)] #\u5c06\u5f53\u524d\u7cfb\u7edf\u4e0b\u5176\u5b83\u7528\u6237\u7684\u5e93\u6b63\u5728\u64cd\u4f5c\u7684\u5206\u652f\u590d\u5236\u5230\u5f53\u524d\u76ee\u5f55\u4e0b<\/span> git pull\u00a0[\u5176\u5b83\u7528\u6237\u7684\u9879\u76ee\u8def\u5f84]\u00a0 [\u5206\u652f\u7684\u540d\u5b57] #\u5c06\u5176\u4ed6\u7528\u6237\u7684\u5206\u652f\u5408\u5e76\u5230\u6307\u5b9a\u7684\u5206\u652f<\/p>\n<p>\u9879\u76ee\u8def\u5f84\u6709\u4ee5\u4e0b\u51e0\u7c7b<\/p>\n<ul>\n<li>\u672c\u5730\u78c1\u76d8\u4e0a\u50a8\u5b58\u7684\u5176\u4ed6\u4ed3\u5e93<\/li>\n<li>ssh\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff0c\u683c\u5f0f\u4e3a\uff1auser@host : [diskPath]<\/li>\n<li>url\u94fe\u63a5\uff0c\u5982\uff1ahttps:\/\/github.com\/libgit2\/libgit2<\/li>\n<\/ul>\n<h2>\u8fdc\u7a0b\u670d\u52a1\u5668<\/h2>\n<p><span class=\"katex math inline\">git remote #\u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u5217\u8868<\/span> git add [shortname] [url] #\u6dfb\u52a0url\u6240\u6307\u7684\u4ed3\u5e93\uff0c\u5e76\u547d\u540d\u4e3ashortname<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eceGit\u7684\u5b89\u88c5\u5230Git\u7684\u57fa\u7840\u7528\u6cd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[6],"_links":{"self":[{"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/posts\/89"}],"collection":[{"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":12,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/www.hyh0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hyh0.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}