{"id":131,"date":"2015-12-19T14:25:21","date_gmt":"2015-12-19T06:25:21","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=131"},"modified":"2017-10-11T10:35:50","modified_gmt":"2017-10-11T02:35:50","slug":"git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4%e5%a4%a7%e5%85%a8","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=131","title":{"rendered":"(\u8f6c)Git\u5e38\u7528\u547d\u4ee4\u5927\u5168"},"content":{"rendered":"<div id=\"blogBody\" class=\"blog-body\">\n<div class=\"BlogContent\">\n<p><a href=\"http:\/\/gitref.org\/index.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Git<\/a>\u00a0\u662f\u4e00\u4e2a\u5f88\u5f3a\u5927\u7684\u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002\u5b83\u4e0d\u4f46\u9002\u7528\u4e8e\u7ba1\u7406\u5927\u578b\u5f00\u6e90\u8f6f\u4ef6\u7684\u6e90\u4ee3\u7801\uff0c\u7ba1\u7406\u79c1\u4eba\u7684\u6587\u6863\u548c\u6e90\u4ee3\u7801\u4e5f\u6709\u5f88\u591a\u4f18\u52bf\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Git\u5e38\u7528\u64cd\u4f5c\u547d\u4ee4\uff1a<\/strong><\/p>\n<p><strong>1)\u00a0\u8fdc\u7a0b\u4ed3\u5e93\u76f8\u5173\u547d\u4ee4<\/strong><\/p>\n<p>\u68c0\u51fa\u4ed3\u5e93\uff1a$ git clone git:\/\/github.com\/jquery\/jquery.git<\/p>\n<p>\u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git remote -v<\/p>\n<p>\u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git remote add [name] [url]<\/p>\n<p>\u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git remote rm [name]<\/p>\n<p>\u4fee\u6539\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git remote set-url &#8211;push\u00a0[name]\u00a0[newUrl]<\/p>\n<p>\u62c9\u53d6\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git pull [remoteName] [localBranchName]<\/p>\n<p>\u63a8\u9001\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git push [remoteName] [localBranchName]<\/p>\n<p>&nbsp;<\/p>\n<p>*\u5982\u679c\u60f3\u628a\u672c\u5730\u7684\u67d0\u4e2a\u5206\u652ftest\u63d0\u4ea4\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff0c\u5e76\u4f5c\u4e3a\u8fdc\u7a0b\u4ed3\u5e93\u7684master\u5206\u652f\uff0c\u6216\u8005\u4f5c\u4e3a\u53e6\u5916\u4e00\u4e2a\u540d\u53ebtest\u7684\u5206\u652f\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>$git push origin test:master \u00a0 \u00a0 \u00a0 \u00a0 \/\/\u00a0\u63d0\u4ea4\u672c\u5730test\u5206\u652f\u4f5c\u4e3a\u8fdc\u7a0b\u7684master\u5206\u652f<\/p>\n<p>$git push origin test:test \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\/\/\u00a0\u63d0\u4ea4\u672c\u5730test\u5206\u652f\u4f5c\u4e3a\u8fdc\u7a0b\u7684test\u5206\u652f<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2\uff09\u5206\u652f(branch)\u64cd\u4f5c\u76f8\u5173\u547d\u4ee4<\/strong><\/p>\n<p>\u67e5\u770b\u672c\u5730\u5206\u652f\uff1a$ git branch<\/p>\n<p>\u67e5\u770b\u8fdc\u7a0b\u5206\u652f\uff1a$ git branch -r<\/p>\n<p>\u521b\u5efa\u672c\u5730\u5206\u652f\uff1a$ git branch [name] &#8212;-\u6ce8\u610f\u65b0\u5206\u652f\u521b\u5efa\u540e\u4e0d\u4f1a\u81ea\u52a8\u5207\u6362\u4e3a\u5f53\u524d\u5206\u652f<\/p>\n<p>\u5207\u6362\u5206\u652f\uff1a$ git checkout [name]<\/p>\n<p>\u521b\u5efa\u65b0\u5206\u652f\u5e76\u7acb\u5373\u5207\u6362\u5230\u65b0\u5206\u652f\uff1a$ git checkout -b [name]<\/p>\n<p>\u5220\u9664\u5206\u652f\uff1a$ git branch -d [name] &#8212;- -d\u9009\u9879\u53ea\u80fd\u5220\u9664\u5df2\u7ecf\u53c2\u4e0e\u4e86\u5408\u5e76\u7684\u5206\u652f\uff0c\u5bf9\u4e8e\u672a\u6709\u5408\u5e76\u7684\u5206\u652f\u662f\u65e0\u6cd5\u5220\u9664\u7684\u3002\u5982\u679c\u60f3\u5f3a\u5236\u5220\u9664\u4e00\u4e2a\u5206\u652f\uff0c\u53ef\u4ee5\u4f7f\u7528-D\u9009\u9879<\/p>\n<p>\u5408\u5e76\u5206\u652f\uff1a$ git merge [name] &#8212;-\u5c06\u540d\u79f0\u4e3a[name]\u7684\u5206\u652f\u4e0e\u5f53\u524d\u5206\u652f\u5408\u5e76<\/p>\n<p>\u521b\u5efa\u8fdc\u7a0b\u5206\u652f(\u672c\u5730\u5206\u652fpush\u5230\u8fdc\u7a0b)\uff1a$ git push origin [name]<\/p>\n<p>\u5220\u9664\u8fdc\u7a0b\u5206\u652f\uff1a$ git push origin :heads\/[name]\u00a0\u6216\u00a0$ gitpush origin :[name]<\/p>\n<p>&nbsp;<\/p>\n<p>*\u521b\u5efa\u7a7a\u7684\u5206\u652f\uff1a(\u6267\u884c\u547d\u4ee4\u4e4b\u524d\u8bb0\u5f97\u5148\u63d0\u4ea4\u4f60\u5f53\u524d\u5206\u652f\u7684\u4fee\u6539\uff0c\u5426\u5219\u4f1a\u88ab\u5f3a\u5236\u5220\u5e72\u51c0\u6ca1\u5f97\u540e\u6094)<\/p>\n<p>$git symbolic-ref HEAD refs\/heads\/[name]<\/p>\n<p>$rm .git\/index<\/p>\n<p>$git clean -fdx<\/p>\n<p>&nbsp;<\/p>\n<p><strong>3\uff09\u7248\u672c(tag)\u64cd\u4f5c\u76f8\u5173\u547d\u4ee4<\/strong><\/p>\n<p>\u67e5\u770b\u7248\u672c\uff1a$ git tag<\/p>\n<p>\u521b\u5efa\u7248\u672c\uff1a$ git tag [name]<\/p>\n<p>\u5220\u9664\u7248\u672c\uff1a$ git tag -d [name]<\/p>\n<p>\u67e5\u770b\u8fdc\u7a0b\u7248\u672c\uff1a$ git tag -r<\/p>\n<p>\u521b\u5efa\u8fdc\u7a0b\u7248\u672c(\u672c\u5730\u7248\u672cpush\u5230\u8fdc\u7a0b)\uff1a$ git push origin [name]<\/p>\n<p>\u5220\u9664\u8fdc\u7a0b\u7248\u672c\uff1a$ git push origin :refs\/tags\/[name]<\/p>\n<p>\u5408\u5e76\u8fdc\u7a0b\u4ed3\u5e93\u7684tag\u5230\u672c\u5730\uff1a$ git pull origin &#8211;tags<\/p>\n<p>\u4e0a\u4f20\u672c\u5730tag\u5230\u8fdc\u7a0b\u4ed3\u5e93\uff1a$ git push origin &#8211;tags<\/p>\n<p>\u521b\u5efa\u5e26\u6ce8\u91ca\u7684tag\uff1a$ git tag -a [name] -m &#8216;yourMessage&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>4)\u00a0\u5b50\u6a21\u5757(submodule)\u76f8\u5173\u64cd\u4f5c\u547d\u4ee4<\/strong><\/p>\n<p>\u6dfb\u52a0\u5b50\u6a21\u5757\uff1a$ git submodule add [url] [path]<\/p>\n<p>\u5982\uff1a$git submodule add git:\/\/github.com\/soberh\/ui-libs.git src\/main\/webapp\/ui-libs<\/p>\n<p>\u521d\u59cb\u5316\u5b50\u6a21\u5757\uff1a$ git submodule init \u00a0&#8212;-\u53ea\u5728\u9996\u6b21\u68c0\u51fa\u4ed3\u5e93\u65f6\u8fd0\u884c\u4e00\u6b21\u5c31\u884c<\/p>\n<p>\u66f4\u65b0\u5b50\u6a21\u5757\uff1a$ git submodule update &#8212;-\u6bcf\u6b21\u66f4\u65b0\u6216\u5207\u6362\u5206\u652f\u540e\u90fd\u9700\u8981\u8fd0\u884c\u4e00\u4e0b<\/p>\n<p>\u5220\u9664\u5b50\u6a21\u5757\uff1a\uff08\u52064\u6b65\u8d70\u54e6\uff09<\/p>\n<p>1)\u00a0$ git rm &#8211;cached [path]<\/p>\n<p>2)\u00a0\u7f16\u8f91\u201c.gitmodules\u201d\u6587\u4ef6\uff0c\u5c06\u5b50\u6a21\u5757\u7684\u76f8\u5173\u914d\u7f6e\u8282\u70b9\u5220\u9664\u6389<\/p>\n<p>3)\u00a0\u7f16\u8f91\u201c\u00a0.git\/config\u201d\u6587\u4ef6\uff0c\u5c06\u5b50\u6a21\u5757\u7684\u76f8\u5173\u914d\u7f6e\u8282\u70b9\u5220\u9664\u6389<\/p>\n<p>4)\u00a0\u624b\u52a8\u5220\u9664\u5b50\u6a21\u5757\u6b8b\u7559\u7684\u76ee\u5f55<\/p>\n<p>&nbsp;<\/p>\n<p><strong>5\uff09\u5ffd\u7565\u4e00\u4e9b\u6587\u4ef6\u3001\u6587\u4ef6\u5939\u4e0d\u63d0\u4ea4<\/strong><\/p>\n<p>\u5728\u4ed3\u5e93\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u79f0\u4e3a\u201c.gitignore\u201d\u7684\u6587\u4ef6\uff0c\u5199\u5165\u4e0d\u9700\u8981\u7684\u6587\u4ef6\u5939\u540d\u6216\u6587\u4ef6\uff0c\u6bcf\u4e2a\u5143\u7d20\u5360\u4e00\u884c\u5373\u53ef\uff0c\u5982<\/p>\n<p>target<\/p>\n<p>bin<\/p>\n<p>*.db<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>=====================<\/p>\n<p><strong>Git \u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n<p>git branch \u67e5\u770b\u672c\u5730\u6240\u6709\u5206\u652f<br \/>\ngit status \u67e5\u770b\u5f53\u524d\u72b6\u6001<br \/>\ngit commit \u63d0\u4ea4<br \/>\ngit branch -a \u67e5\u770b\u6240\u6709\u7684\u5206\u652f<br \/>\ngit branch -r \u67e5\u770b\u672c\u5730\u6240\u6709\u5206\u652f<br \/>\ngit commit -am &#8220;init&#8221; \u63d0\u4ea4\u5e76\u4e14\u52a0\u6ce8\u91ca<br \/>\ngit remote add origin git@192.168.1.119:ndshow<br \/>\ngit push origin master \u5c06\u6587\u4ef6\u7ed9\u63a8\u5230\u670d\u52a1\u5668\u4e0a<br \/>\ngit remote show origin \u663e\u793a\u8fdc\u7a0b\u5e93origin\u91cc\u7684\u8d44\u6e90<br \/>\ngit push origin master:develop<br \/>\ngit push origin master:hb-dev \u5c06\u672c\u5730\u5e93\u4e0e\u670d\u52a1\u5668\u4e0a\u7684\u5e93\u8fdb\u884c\u5173\u8054<br \/>\ngit checkout &#8211;track origin\/dev \u5207\u6362\u5230\u8fdc\u7a0bdev\u5206\u652f<br \/>\ngit branch -D master develop \u5220\u9664\u672c\u5730\u5e93develop<br \/>\ngit checkout -b dev \u5efa\u7acb\u4e00\u4e2a\u65b0\u7684\u672c\u5730\u5206\u652fdev<br \/>\ngit merge origin\/dev \u5c06\u5206\u652fdev\u4e0e\u5f53\u524d\u5206\u652f\u8fdb\u884c\u5408\u5e76<br \/>\ngit checkout dev \u5207\u6362\u5230\u672c\u5730dev\u5206\u652f<br \/>\ngit remote show \u67e5\u770b\u8fdc\u7a0b\u5e93<br \/>\ngit add .<br \/>\ngit rm \u6587\u4ef6\u540d(\u5305\u62ec\u8def\u5f84) \u4ecegit\u4e2d\u5220\u9664\u6307\u5b9a\u6587\u4ef6<br \/>\ngit clone git:\/\/github.com\/schacon\/grit.git \u4ece\u670d\u52a1\u5668\u4e0a\u5c06\u4ee3\u7801\u7ed9\u62c9\u4e0b\u6765<br \/>\ngit config &#8211;list \u770b\u6240\u6709\u7528\u6237<br \/>\ngit ls-files \u770b\u5df2\u7ecf\u88ab\u63d0\u4ea4\u7684<br \/>\ngit rm [file name] \u5220\u9664\u4e00\u4e2a\u6587\u4ef6<br \/>\ngit commit -a \u63d0\u4ea4\u5f53\u524drepos\u7684\u6240\u6709\u7684\u6539\u53d8<br \/>\ngit add [file name] \u6dfb\u52a0\u4e00\u4e2a\u6587\u4ef6\u5230git index<br \/>\ngit commit -v \u5f53\u4f60\u7528\uff0dv\u53c2\u6570\u7684\u65f6\u5019\u53ef\u4ee5\u770bcommit\u7684\u5dee\u5f02<br \/>\ngit commit -m &#8220;This is the message describing the commit&#8221; \u6dfb\u52a0commit\u4fe1\u606f<br \/>\ngit commit -a -a\u662f\u4ee3\u8868add\uff0c\u628a\u6240\u6709\u7684change\u52a0\u5230git index\u91cc\u7136\u540e\u518dcommit<br \/>\ngit commit -a -v \u4e00\u822c\u63d0\u4ea4\u547d\u4ee4<br \/>\ngit log \u770b\u4f60commit\u7684\u65e5\u5fd7<br \/>\ngit diff \u67e5\u770b\u5c1a\u672a\u6682\u5b58\u7684\u66f4\u65b0<br \/>\ngit rm a.a \u79fb\u9664\u6587\u4ef6(\u4ece\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u4e2d\u5220\u9664)<br \/>\ngit rm &#8211;cached a.a \u79fb\u9664\u6587\u4ef6(\u53ea\u4ece\u6682\u5b58\u533a\u4e2d\u5220\u9664)<br \/>\ngit commit -m &#8220;remove&#8221; \u79fb\u9664\u6587\u4ef6(\u4eceGit\u4e2d\u5220\u9664)<br \/>\ngit rm -f a.a \u5f3a\u884c\u79fb\u9664\u4fee\u6539\u540e\u6587\u4ef6(\u4ece\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u4e2d\u5220\u9664)<br \/>\ngit diff &#8211;cached \u6216 $ git diff &#8211;staged \u67e5\u770b\u5c1a\u672a\u63d0\u4ea4\u7684\u66f4\u65b0<br \/>\ngit stash push \u5c06\u6587\u4ef6\u7ed9push\u5230\u4e00\u4e2a\u4e34\u65f6\u7a7a\u95f4\u4e2d<br \/>\ngit stash pop \u5c06\u6587\u4ef6\u4ece\u4e34\u65f6\u7a7a\u95f4pop\u4e0b\u6765<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\ngit remote add origin git@github.com:username\/Hello-World.git<br \/>\ngit push origin master \u5c06\u672c\u5730\u9879\u76ee\u7ed9\u63d0\u4ea4\u5230\u670d\u52a1\u5668\u4e2d<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\ngit pull \u672c\u5730\u4e0e\u670d\u52a1\u5668\u7aef\u540c\u6b65<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\ngit push (\u8fdc\u7a0b\u4ed3\u5e93\u540d) (\u5206\u652f\u540d) \u5c06\u672c\u5730\u5206\u652f\u63a8\u9001\u5230\u670d\u52a1\u5668\u4e0a\u53bb\u3002<br \/>\ngit push origin serverfix:awesomebranch<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\ngit fetch \u76f8\u5f53\u4e8e\u662f\u4ece\u8fdc\u7a0b\u83b7\u53d6\u6700\u65b0\u7248\u672c\u5230\u672c\u5730\uff0c\u4e0d\u4f1a\u81ea\u52a8merge<br \/>\ngit commit -a -m &#8220;log_message&#8221; (-a\u662f\u63d0\u4ea4\u6240\u6709\u6539\u52a8\uff0c-m\u662f\u52a0\u5165log\u4fe1\u606f) \u672c\u5730\u4fee\u6539\u540c\u6b65\u81f3\u670d\u52a1\u5668\u7aef \uff1a<br \/>\ngit branch branch_0.1 master \u4ece\u4e3b\u5206\u652fmaster\u521b\u5efabranch_0.1\u5206\u652f<br \/>\ngit branch -m branch_0.1 branch_1.0 \u5c06branch_0.1\u91cd\u547d\u540d\u4e3abranch_1.0<br \/>\ngit checkout branch_1.0\/master \u5207\u6362\u5230branch_1.0\/master\u5206\u652f<br \/>\ndu -hs<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\nmkdir WebApp<br \/>\ncd WebApp<br \/>\ngit init<br \/>\ntouch README<br \/>\ngit add README<br \/>\ngit commit -m &#8216;first commit&#8217;<br \/>\ngit remote add origin git@github.com:daixu\/WebApp.git<br \/>\ngit push -u origin master<\/p>\n<\/div>\n<\/div>\n<div class=\"blog-opr\">\n<div class=\"blog-copyright\">\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/blog.csdn.net\/dengsilinming\/article\/details\/8000622\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/blog.csdn.net\/dengsilinming\/article\/details\/8000622<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Git\u00a0\u662f\u4e00\u4e2a\u5f88\u5f3a\u5927\u7684\u5206\u5e03\u5f0f\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u3002\u5b83\u4e0d\u4f46\u9002\u7528\u4e8e\u7ba1\u7406\u5927\u578b\u5f00\u6e90\u8f6f\u4ef6\u7684\u6e90\u4ee3\u7801\uff0c\u7ba1\u7406\u79c1\u4eba\u7684\u6587\u6863\u548c\u6e90\u4ee3\u7801\u4e5f\u6709\u5f88\u591a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":165,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[22],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/131"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131"}],"version-history":[{"count":3,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":329,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions\/329"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/165"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}