{"id":213,"date":"2017-06-08T00:12:03","date_gmt":"2017-06-07T16:12:03","guid":{"rendered":"http:\/\/www.secondsend.com\/wordpress\/?p=213"},"modified":"2017-06-08T00:12:03","modified_gmt":"2017-06-07T16:12:03","slug":"git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"http:\/\/www.homconnect.cn\/?p=213","title":{"rendered":"Git\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"<h1 class=\"postTitle\">Git\u5e38\u7528\u547d\u4ee4<\/h1>\n<div class=\"clear\"><\/div>\n<div class=\"postBody\">\n<div id=\"cnblogs_post_body\">\n<p><strong>\u67e5\u770b\u3001\u6dfb\u52a0\u3001\u63d0\u4ea4\u3001\u5220\u9664\u3001\u627e\u56de\uff0c\u91cd\u7f6e\u4fee\u6539\u6587\u4ef6<\/strong><\/p>\n<p>git help &lt;command&gt; # \u663e\u793acommand\u7684help<\/p>\n<p>git show # \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9 git show $id<\/p>\n<p>git co &#8212; &lt;file&gt; # \u629b\u5f03\u5de5\u4f5c\u533a\u4fee\u6539<\/p>\n<p>git co . # \u629b\u5f03\u5de5\u4f5c\u533a\u4fee\u6539<\/p>\n<p>git add &lt;file&gt; # \u5c06\u5de5\u4f5c\u6587\u4ef6\u4fee\u6539\u63d0\u4ea4\u5230\u672c\u5730\u6682\u5b58\u533a<\/p>\n<p>git add . # \u5c06\u6240\u6709\u4fee\u6539\u8fc7\u7684\u5de5\u4f5c\u6587\u4ef6\u63d0\u4ea4\u6682\u5b58\u533a<\/p>\n<p>git rm &lt;file&gt; # \u4ece\u7248\u672c\u5e93\u4e2d\u5220\u9664\u6587\u4ef6<\/p>\n<p>git rm &lt;file&gt; &#8211;cached # \u4ece\u7248\u672c\u5e93\u4e2d\u5220\u9664\u6587\u4ef6\uff0c\u4f46\u4e0d\u5220\u9664\u6587\u4ef6<\/p>\n<p>git reset &lt;file&gt; # \u4ece\u6682\u5b58\u533a\u6062\u590d\u5230\u5de5\u4f5c\u6587\u4ef6<\/p>\n<p>git reset &#8212; . # \u4ece\u6682\u5b58\u533a\u6062\u590d\u5230\u5de5\u4f5c\u6587\u4ef6<\/p>\n<p>git reset &#8211;hard # \u6062\u590d\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\u8fc7\u7684\u72b6\u6001\uff0c\u5373\u653e\u5f03\u4e0a\u6b21\u63d0\u4ea4\u540e\u7684\u6240\u6709\u672c\u6b21\u4fee\u6539<\/p>\n<p>git ci &lt;file&gt; git ci . git ci -a # \u5c06git add, git rm\u548cgit ci\u7b49\u64cd\u4f5c\u90fd\u5408\u5e76\u5728\u4e00\u8d77\u505a\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000git ci -am &#8220;some comments&#8221;<\/p>\n<p>git ci &#8211;amend # \u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u8bb0\u5f55<\/p>\n<p>git revert &lt;$id&gt; # \u6062\u590d\u67d0\u6b21\u63d0\u4ea4\u7684\u72b6\u6001\uff0c\u6062\u590d\u52a8\u4f5c\u672c\u8eab\u4e5f\u521b\u5efa\u6b21\u63d0\u4ea4\u5bf9\u8c61<\/p>\n<p>git revert HEAD # \u6062\u590d\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u72b6\u6001<\/p>\n<p><strong>\u67e5\u770b\u6587\u4ef6diff<\/strong><\/p>\n<p>git diff &lt;file&gt; # \u6bd4\u8f83\u5f53\u524d\u6587\u4ef6\u548c\u6682\u5b58\u533a\u6587\u4ef6\u5dee\u5f02 git diff<\/p>\n<p>git diff &lt;<span id=\"MathJax-Element-1-Frame\" class=\"MathJax\" style=\"margin: 0px; padding: 0px; display: inline; font-style: normal; font-weight: normal; line-height: normal; font-size: 14px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;\" tabindex=\"0\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot;&gt;&lt;mi&gt;i&lt;\/mi&gt;&lt;mi&gt;d&lt;\/mi&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo&gt;&amp;gt;&amp;lt;&lt;\/mo&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-1\" class=\"math\"><span id=\"MathJax-Span-2\" class=\"mrow\"><span id=\"MathJax-Span-3\" class=\"mi\">i<\/span><span id=\"MathJax-Span-4\" class=\"mi\">d<\/span><span id=\"MathJax-Span-5\" class=\"mn\">1<\/span><span id=\"MathJax-Span-6\" class=\"mo\">&gt;&lt;<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\">id1&gt;&lt;<\/span><\/span>id2&gt; # \u6bd4\u8f83\u4e24\u6b21\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02<\/p>\n<p>git diff &lt;branch1&gt;..&lt;branch2&gt; # \u5728\u4e24\u4e2a\u5206\u652f\u4e4b\u95f4\u6bd4\u8f83<\/p>\n<p>git diff &#8211;staged # \u6bd4\u8f83\u6682\u5b58\u533a\u548c\u7248\u672c\u5e93\u5dee\u5f02<\/p>\n<p>git diff &#8211;cached # \u6bd4\u8f83\u6682\u5b58\u533a\u548c\u7248\u672c\u5e93\u5dee\u5f02<\/p>\n<p>git diff &#8211;stat # \u4ec5\u4ec5\u6bd4\u8f83\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p><strong>\u67e5\u770b\u63d0\u4ea4\u8bb0\u5f55<\/strong><\/p>\n<p>git log git log &lt;file&gt; # \u67e5\u770b\u8be5\u6587\u4ef6\u6bcf\u6b21\u63d0\u4ea4\u8bb0\u5f55<\/p>\n<p>git log -p &lt;file&gt; # \u67e5\u770b\u6bcf\u6b21\u8be6\u7ec6\u4fee\u6539\u5185\u5bb9\u7684diff<\/p>\n<p>git log -p -2 # \u67e5\u770b\u6700\u8fd1\u4e24\u6b21\u8be6\u7ec6\u4fee\u6539\u5185\u5bb9\u7684diff<\/p>\n<p>git log &#8211;stat #\u67e5\u770b\u63d0\u4ea4\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p><strong>tig<\/strong><\/p>\n<p>Mac\u4e0a\u53ef\u4ee5\u4f7f\u7528tig\u4ee3\u66ffdiff\u548clog\uff0c<code>brew install tig<\/code><\/p>\n<p><strong>Git \u672c\u5730\u5206\u652f\u7ba1\u7406<\/strong><\/p>\n<p><strong>\u67e5\u770b\u3001\u5207\u6362\u3001\u521b\u5efa\u548c\u5220\u9664\u5206\u652f<\/strong><\/p>\n<p>git br -r # \u67e5\u770b\u8fdc\u7a0b\u5206\u652f<\/p>\n<p>git br &lt;new_branch&gt; # \u521b\u5efa\u65b0\u7684\u5206\u652f<\/p>\n<p>git br -v # \u67e5\u770b\u5404\u4e2a\u5206\u652f\u6700\u540e\u63d0\u4ea4\u4fe1\u606f<\/p>\n<p>git br &#8211;merged # \u67e5\u770b\u5df2\u7ecf\u88ab\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u7684\u5206\u652f<\/p>\n<p>git br &#8211;no-merged # \u67e5\u770b\u5c1a\u672a\u88ab\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u7684\u5206\u652f<\/p>\n<p>git co &lt;branch&gt; # \u5207\u6362\u5230\u67d0\u4e2a\u5206\u652f<\/p>\n<p>git co -b &lt;new_branch&gt; # \u521b\u5efa\u65b0\u7684\u5206\u652f\uff0c\u5e76\u4e14\u5207\u6362\u8fc7\u53bb<\/p>\n<p>git co -b &lt;new_branch&gt; &lt;branch&gt; # \u57fa\u4e8ebranch\u521b\u5efa\u65b0\u7684new_branch<\/p>\n<p>git co $id # \u628a\u67d0\u6b21\u5386\u53f2\u63d0\u4ea4\u8bb0\u5f55checkout\u51fa\u6765\uff0c\u4f46\u65e0\u5206\u652f\u4fe1\u606f\uff0c\u5207\u6362\u5230\u5176\u4ed6\u5206\u652f\u4f1a\u81ea\u52a8\u5220\u9664<\/p>\n<p>git co $id -b &lt;new_branch&gt; # \u628a\u67d0\u6b21\u5386\u53f2\u63d0\u4ea4\u8bb0\u5f55checkout\u51fa\u6765\uff0c\u521b\u5efa\u6210\u4e00\u4e2a\u5206\u652f<\/p>\n<p>git br -d &lt;branch&gt; # \u5220\u9664\u67d0\u4e2a\u5206\u652f<\/p>\n<p>git br -D &lt;branch&gt; # \u5f3a\u5236\u5220\u9664\u67d0\u4e2a\u5206\u652f (\u672a\u88ab\u5408\u5e76\u7684\u5206\u652f\u88ab\u5220\u9664\u7684\u65f6\u5019\u9700\u8981\u5f3a\u5236)<\/p>\n<p><strong>\u00a0\u5206\u652f\u5408\u5e76\u548crebase<\/strong><\/p>\n<p>git merge &lt;branch&gt; # \u5c06branch\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f<\/p>\n<p>git merge origin\/master &#8211;no-ff # \u4e0d\u8981Fast-Foward\u5408\u5e76\uff0c\u8fd9\u6837\u53ef\u4ee5\u751f\u6210merge\u63d0\u4ea4<\/p>\n<p>git rebase master &lt;branch&gt; # \u5c06master rebase\u5230branch\uff0c\u76f8\u5f53\u4e8e\uff1a git co &lt;branch&gt; &amp;&amp; git rebase master &amp;&amp; git co master &amp;&amp; git merge &lt;branch&gt;<\/p>\n<p><strong>\u00a0Git\u8865\u4e01\u7ba1\u7406(\u65b9\u4fbf\u5728\u591a\u53f0\u673a\u5668\u4e0a\u5f00\u53d1\u540c\u6b65\u65f6\u7528)<\/strong><\/p>\n<p>git diff &gt; ..\/sync.patch # \u751f\u6210\u8865\u4e01<\/p>\n<p>git apply ..\/sync.patch # \u6253\u8865\u4e01<\/p>\n<p>git apply &#8211;check ..\/sync.patch #\u6d4b\u8bd5\u8865\u4e01\u80fd\u5426\u6210\u529f<\/p>\n<p><strong>\u00a0Git\u6682\u5b58\u7ba1\u7406<\/strong><\/p>\n<p>git stash # \u6682\u5b58<\/p>\n<p>git stash list # \u5217\u6240\u6709stash<\/p>\n<p>git stash apply # \u6062\u590d\u6682\u5b58\u7684\u5185\u5bb9<\/p>\n<p>git stash drop # \u5220\u9664\u6682\u5b58\u533a<\/p>\n<p><strong>Git\u8fdc\u7a0b\u5206\u652f\u7ba1\u7406<\/strong><\/p>\n<p>git pull # \u6293\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u6240\u6709\u5206\u652f\u66f4\u65b0\u5e76\u5408\u5e76\u5230\u672c\u5730<\/p>\n<p>git pull &#8211;no-ff # \u6293\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u6240\u6709\u5206\u652f\u66f4\u65b0\u5e76\u5408\u5e76\u5230\u672c\u5730\uff0c\u4e0d\u8981\u5feb\u8fdb\u5408\u5e76<\/p>\n<p>git fetch origin # \u6293\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u66f4\u65b0<\/p>\n<p>git merge origin\/master # \u5c06\u8fdc\u7a0b\u4e3b\u5206\u652f\u5408\u5e76\u5230\u672c\u5730\u5f53\u524d\u5206\u652f<\/p>\n<p>git co &#8211;track origin\/branch # \u8ddf\u8e2a\u67d0\u4e2a\u8fdc\u7a0b\u5206\u652f\u521b\u5efa\u76f8\u5e94\u7684\u672c\u5730\u5206\u652f<\/p>\n<p>git co -b &lt;local_branch&gt; origin\/&lt;remote_branch&gt; # \u57fa\u4e8e\u8fdc\u7a0b\u5206\u652f\u521b\u5efa\u672c\u5730\u5206\u652f\uff0c\u529f\u80fd\u540c\u4e0a<\/p>\n<p>git push # push\u6240\u6709\u5206\u652f<\/p>\n<p>git push origin master # \u5c06\u672c\u5730\u4e3b\u5206\u652f\u63a8\u5230\u8fdc\u7a0b\u4e3b\u5206\u652f<\/p>\n<p>git push -u origin master # \u5c06\u672c\u5730\u4e3b\u5206\u652f\u63a8\u5230\u8fdc\u7a0b(\u5982\u65e0\u8fdc\u7a0b\u4e3b\u5206\u652f\u5219\u521b\u5efa\uff0c\u7528\u4e8e\u521d\u59cb\u5316\u8fdc\u7a0b\u4ed3\u5e93)<\/p>\n<p>git push origin &lt;local_branch&gt; # \u521b\u5efa\u8fdc\u7a0b\u5206\u652f\uff0c origin\u662f\u8fdc\u7a0b\u4ed3\u5e93\u540d<\/p>\n<p>git push origin &lt;local_branch&gt;:&lt;remote_branch&gt; # \u521b\u5efa\u8fdc\u7a0b\u5206\u652f<\/p>\n<p>git push origin :&lt;remote_branch&gt; #\u5148\u5220\u9664\u672c\u5730\u5206\u652f(git br -d &lt;branch&gt;)\uff0c\u7136\u540e\u518dpush\u5220\u9664\u8fdc\u7a0b\u5206\u652f<\/p>\n<p><strong>Git\u8fdc\u7a0b\u4ed3\u5e93\u7ba1\u7406<\/strong><\/p>\n<p><em><span class=\"wp_keywordlink\">GitHub<\/span><\/em><\/p>\n<p>git remote -v # \u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u5730\u5740\u548c\u4ed3\u5e93\u540d\u79f0<\/p>\n<p>git remote show origin # \u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u4ed3\u5e93\u72b6\u6001<\/p>\n<p>git remote add origin git@ github:robbin\/robbin_site.git # \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740<\/p>\n<p>git remote set-url origin git@ github.com:robbin\/robbin_site.git # \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740(\u7528\u4e8e\u4fee\u6539\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740) git remote rm &lt;repository&gt; # \u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93<\/p>\n<p><strong>\u521b\u5efa\u8fdc\u7a0b\u4ed3\u5e93<\/strong><\/p>\n<p>git clone &#8211;bare robbin_site robbin_site.git # \u7528\u5e26\u7248\u672c\u7684\u9879\u76ee\u521b\u5efa\u7eaf\u7248\u672c\u4ed3\u5e93<\/p>\n<p>scp -r my_project.git git@ git.csdn.net:~ # \u5c06\u7eaf\u4ed3\u5e93\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a<\/p>\n<p>mkdir robbin_site.git &amp;&amp; cd robbin_site.git &amp;&amp; git &#8211;bare init # \u5728\u670d\u52a1\u5668\u521b\u5efa\u7eaf\u4ed3\u5e93<\/p>\n<p>git remote add origin git@ github.com:robbin\/robbin_site.git # \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740<\/p>\n<p>git push -u origin master # \u5ba2\u6237\u7aef\u9996\u6b21\u63d0\u4ea4<\/p>\n<p>git push -u origin develop # \u9996\u6b21\u5c06\u672c\u5730develop\u5206\u652f\u63d0\u4ea4\u5230\u8fdc\u7a0bdevelop\u5206\u652f\uff0c\u5e76\u4e14track<\/p>\n<p>git remote set-head origin master # \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\u7684HEAD\u6307\u5411master\u5206\u652f<\/p>\n<p>\u4e5f\u53ef\u4ee5\u547d\u4ee4\u8bbe\u7f6e\u8ddf\u8e2a\u8fdc\u7a0b\u5e93\u548c\u672c\u5730\u5e93<\/p>\n<p>git branch &#8211;set-upstream master origin\/master<\/p>\n<p>git branch &#8211;set-upstream develop origin\/develop<\/p>\n<\/div>\n<p>via@ http:\/\/www.cnblogs.com\/cspku\/articles\/Git_cmds.html<\/p>\n<\/div>\n<p><!--more--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git\u5e38\u7528\u547d\u4ee4 \u67e5\u770b\u3001\u6dfb\u52a0\u3001\u63d0\u4ea4\u3001\u5220\u9664\u3001\u627e\u56de\uff0c\u91cd\u7f6e\u4fee\u6539\u6587\u4ef6 git help &lt;command&gt;  &hellip; <a href=\"http:\/\/www.homconnect.cn\/?p=213\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cGit\u5e38\u7528\u547d\u4ee4\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2,15],"tags":[],"_links":{"self":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/213"}],"collection":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213"}],"version-history":[{"count":1,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":214,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=\/wp\/v2\/posts\/213\/revisions\/214"}],"wp:attachment":[{"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.homconnect.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}