{"id":1477,"date":"2015-03-22T12:36:16","date_gmt":"2015-03-22T04:36:16","guid":{"rendered":"https:\/\/cowmanchiang.me\/wp\/?p=1477"},"modified":"2023-10-31T15:43:48","modified_gmt":"2023-10-31T07:43:48","slug":"git-git-command","status":"publish","type":"post","link":"https:\/\/cowmanchiang.me\/wp\/?p=1477","title":{"rendered":"[Git] Git command&#8230;"},"content":{"rendered":"<ul>\n<li>\n<p>git stash: \u66ab\u5b58\u6a5f\u5236<\/p>\n<ul>\n<li>\n<p>git stash: \u66ab\u5b58\u6a5f\u5236\uff0c\u53ef\u4fdd\u7559\u76ee\u524d\u72c0\u614b\uff0c\u91cd\u65b0\u53d6\u56de\u5176\u4ed6\u7248\u672c\u7684code<\/p>\n<\/li>\n<li>\n<p>git stash clear: \u6e05\u9664\u6240\u6709\u66ab\u5b58\u7a7a\u9593<\/p>\n<\/li>\n<li>\n<p>git stash drop {git status name}: \u6e05\u9664\u6307\u5b9a\u7684\u66ab\u5b58\u72c0\u614b\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u522a\u9664\u6700\u8fd1\u7684\u90a3\u4e00\u500b<\/p>\n<\/li>\n<li>\n<p>git stash list: \u67e5\u770b\u76ee\u524d\u66ab\u5b58\u5217\u8868<\/p>\n<\/li>\n<li>\n<p>git stash apply {git stash name}: \u53d6\u56de\u66ab\u5b58\u7684\u72c0\u614b\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u6293\u53d6\u6700\u8fd1\u7684\u7248\u672c<\/p>\n<\/li>\n<li>\n<p>git stash show {git stash name}: \u67e5\u770b\u6307\u5b9a\u7684\u66ab\u5b58\u8207parent\u5dee\u7570\u7684\u90e8\u5206\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u986f\u793a\u6700\u8fd1\u7684\u90a3\u4e00\u500b\u7248\u672c<\/p>\n<\/li>\n<li>\n<p>git stash branch {git stash name}: \u5c07\u6307\u5b9a\u66ab\u5b58\u8f49\u70babranch\uff0c\u540c\u6642\u66ab\u5b58\u7684\u90e8\u5206\u6703\u6d88\u5931\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u8f49\u63db\u6700\u8fd1\u7684\u7248\u672c<\/p>\n<\/li>\n<li>\n<p>git stash save &#8211;keep-index: \u5c07\u7a0b\u5f0f\u7de8\u8f2f\u6642\u53ef\u80fd\u6703\u7522\u751f\u7684\u8207\u9060\u7aef\u4e0d\u76f8\u5bb9\u7684\u6a94\u6848\u5148\u653e\u7f6estash\u66ab\u5b58\u4e2d\uff0c\u4e4b\u5f8c\u518d\u522a\u9664\uff0c\u907f\u514dpush\u81f3\u9060\u7aef<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5ffd\u7565\u6a94\u6848\u8a2d\u5b9a<\/p>\n<p>\u7de8\u8f2f .gitignore\uff0c\u5047\u8a2d\u8981\u4f7fgit\u4e0d\u8ffd\u8e64 .jpg \u6a94\u6848<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">  *.jpg<\/pre>\n<p>\u5047\u8a2d\u8981\u4f7fgit\u4e0d\u8ffd\u8e64 .o \u53ca .a \u7684\u6a94\u6848<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"\">  *.[oa]<\/pre>\n<\/li>\n<li>\n<p>git status: \u67e5\u8a62\u76ee\u524d\u72c0\u614b\uff0c\u4f4d\u65bc\u54ea\u500bbranch\uff0c\u66ab\u5b58\u5340\u7684\u6a94\u6848\u8cc7\u8a0a<\/p>\n<\/li>\n<li>\n<p>git diff: \u986f\u793a\u672a\u9032\u5165\u66ab\u5b58\u5340\u3001commit \u7684\u76ee\u524d\u8a73\u7d30\u72c0\u614b\uff0c\u5305\u542b\u6a94\u6848\u4e2d\u54ea\u4e00\u884c\u65b0\u589e\u3001\u522a\u9664\u3001\u4fee\u6539\u7b49<\/p>\n<ul>\n<li>\n<p>git diff: &#8211;staged \u986f\u793a\u66ab\u5b58\u5340\u57df\u53ca\u6700\u5f8c\u4e00\u6b21commit\u7684\u5dee\u7570<\/p>\n<\/li>\n<li>\n<p>git diff {file_name}: \u67e5\u8a62\u6a94\u6848\u8207\u6240\u5728branch\u4e2d\u7684\u539f\u59cb\u6a94\u6848\u7684\u5dee\u7570\u8cc7\u8a0a<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git commit: \u6a19\u8a3b\u4fee\u6539\u8aaa\u660e<\/p>\n<ul>\n<li>\n<p>git commit -m &#8220;\u8aaa\u660e\u6587\u5b57&#8221;: \u91dd\u5c0d\u5df2\u52a0\u5165\u6e96\u5099push\u7684\u66ab\u5b58\u8cc7\u6599\u9032\u884c\u6a19\u8a3b\u4fee\u6539\u8aaa\u660e<\/p>\n<\/li>\n<li>\n<p>git commit -a: \u540c\u4e0a\uff0c\u6703\u4f7f\u7528\u8a2d\u5b9a\u7684\u9810\u8a2d\u6587\u5b57\u7de8\u8f2f\u5668\u8df3\u51fa\u4fee\u6539\u8aaa\u660e\u586b\u5beb\u756b\u9762<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git add \u5c07\u6a94\u6848\u52a0\u5165\u8ffd\u8e64<\/p>\n<p>Ref: http:\/\/stackoverflow.com\/questions\/572549\/difference-between-git-add-a-and-git-add\/16162511#16162511<\/p>\n<p>version 1.x:<br \/>\ngit add .: \u91dd\u5c0d\u65b0\u589e\u3001\u4fee\u6539\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b\uff0c\u522a\u9664\u7684\u4e0d\u6703\u66f4\u52d5<br \/>\ngit add [-A|&#8211;all]: \u91dd\u5c0d\u65b0\u589e\u3001\u4fee\u6539\u3001\u522a\u9664\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b<br \/>\ngit add -u: \u91dd\u5c0d\u4fee\u6539\u3001\u522a\u9664\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b\uff0c\u65b0\u589e\u7684\u6a94\u6848\u4e0d\u6703\u52a0\u5165\u8ffd\u8e64<\/p>\n<p>version 2.x:<br \/>\ngit add [-A|&#8211;all]: \u91dd\u5c0d\u65b0\u589e\u3001\u4fee\u6539\u3001\u522a\u9664\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b<br \/>\ngit add .: \u91dd\u5c0d\u65b0\u589e\u3001\u4fee\u6539\u3001\u522a\u9664\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b<br \/>\ngit add &#8211;ignore-removal .: \u91dd\u5c0d\u65b0\u589e\u3001\u4fee\u6539\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b\uff0c\u522a\u9664\u7684\u4e0d\u6703\u66f4\u52d5<br \/>\ngit add -u: \u91dd\u5c0d\u4fee\u6539\u3001\u522a\u9664\u7684\u6a94\u6848\u4fee\u6539\u8ffd\u8e64\u72c0\u614b\uff0c\u65b0\u589e\u7684\u6a94\u6848\u4e0d\u6703\u52a0\u5165\u8ffd\u8e64<\/p>\n<\/li>\n<li>\n<p>git log: \u67e5\u8a62 commit log<\/p>\n<\/li>\n<li>\n<p>git blame {file name}: \u67e5\u8a62\u6a94\u6848\u6bcf\u4e00\u884c\u662f\u7531\u8ab0\u4fee\u6539\u7684<\/p>\n<\/li>\n<li>\n<p>git rm {file_name}: \u79fb\u9664git\u4e2d\u7684\u6a94\u6848\uff0c\u540c\u6642\u4e00\u4f75\u522a\u9664\u786c\u789f\u4e2d\u7684\u6a94\u6848<\/p>\n<ul>\n<li>git rm -cached {file_name}: \u79fb\u9664\u5df2\u7d93add\u4f46\u9084\u6c92commit\u7684\u6a94\u6848\uff0c\u5373\u79fb\u9664git index\u4e2d\u7684\u7d00\u9304<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git push: \u5c07\u672c\u5730\u7aef\u7684\u6a94\u6848push\u5230\u9810\u8a2d\u7684remote branch<\/p>\n<ul>\n<li>\n<p>git push origin branch_name: \u5c07\u672c\u5730\u7aef\u7684\u6a94\u6848push\u5230\u9060\u7aeforigin\u4e0a\u7684\u6307\u5b9abranch_name<\/p>\n<\/li>\n<li>\n<p>git push origin :branch_name: \u522a\u9664\u9060\u7aeforigin\u4e0a\u6307\u5b9a\u7684branch<\/p>\n<\/li>\n<li>\n<p>git push origin &#8211;delete branch_name: \u522a\u9664\u9060\u7aeforigin\u4e0a\u6307\u5b9a\u7684branch<\/p>\n<\/li>\n<li>\n<p>git branch -d branch_name: \u522a\u9664\u672c\u5730\u7684branch<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git remote: \u9060\u7aef\u64cd\u4f5c<\/p>\n<ul>\n<li>\n<p>git remote: \u986f\u793a\u76ee\u524d\u4f7f\u7528\u7684\u9060\u7aefgit_url (git:\/\/server_host\/user_name\/git_name)<\/p>\n<\/li>\n<li>\n<p>git remote -v: \u986f\u793a\u6240\u6709\u7684git_url\u8cc7\u8a0a<\/p>\n<\/li>\n<li>\n<p>git remote add remote_name git_url: \u5c07\u9060\u7aefgit_url\u8a2d\u5b9a\u5225\u540d\u6210remote_name<\/p>\n<\/li>\n<li>\n<p>git remote show origin: \u67e5\u770b\u9060\u7aeforigin\u4e0a\u7684\u8cc7\u6599<\/p>\n<\/li>\n<li>\n<p>git remote rename remote_name_old remote_name_new: \u5c07\u9060\u7aefgit server\u7684\u5225\u540d\u9032\u884c\u66f4\u6539<\/p>\n<\/li>\n<li>\n<p>git remote rm remote_name: \u522a\u9664git server\u8cc7\u8a0a<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git pull: \u5c07\u9060\u7aef\u7684\u6a94\u6848\u62c9\u56de<\/p>\n<ul>\n<li>\n<p>git pull: \u81f3\u9810\u8a2d\u7684remote_name\u62c9\u56de\u6a94\u6848\u4e26merge\u9032\u672c\u5730\u7aef\u6b63\u5728\u9032\u884c\u7684branch\u4e2d<\/p>\n<\/li>\n<li>\n<p>git pull local_branch_name remote_name\/remote_branch_name: \u81f3remote_name\u4e2d\u62c9\u56deremote_branch_name\u4e26merge\u81f3\u672c\u5730\u7684local_branch_name\u4e2d<\/p>\n<p>git pull \u52d5\u4f5c\u5b8c\u6210\u5f8c\u8a18\u5f97\u5148\u4f7f\u7528git status\u6aa2\u8996\u662f\u5426\u6709\u885d\u7a81\u767c\u751f\uff0c\u82e5\u6709\uff0c\u5247\u9700\u8981\u5148\u628a\u885d\u7a81\u89e3\u6c7a<\/p>\n<\/li>\n<li>\n<p>git pull &#8211;rebase: \u5148\u628a\u672c\u5730 repo. \u5f9e\u4e0a\u6b21 pull \u4e4b\u5f8c\u7684\u8b8a\u66f4\u66ab\u5b58\u8d77\u4f86\uff0c\u56de\u5fa9\u5230\u4e0a\u6b21 pull \u6642\u7684\u60c5\u6cc1\uff0c\u63a5\u8457\u5957\u7528\u9060\u7aef\u7684\u8b8a\u66f4\uff0c\u6700\u5f8c\u518d\u5957\u7528\u525b\u66ab\u5b58\u4e0b\u4f86\u7684\u672c\u5730\u8b8a\u66f4<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git branch: \u5206\u652f<\/p>\n<ul>\n<li>\n<p>git branch: \u67e5\u770b\u672c\u5730\u7aef\u7684branch\u6e05\u55ae<\/p>\n<\/li>\n<li>\n<p>git branch -r: \u67e5\u770b\u9060\u7aef\u7684branch\u6e05\u55ae<\/p>\n<\/li>\n<li>\n<p>git branch new_local_branch_name: \u5f9emaster\u8907\u88fd\u4e00\u500b\u65b0\u7684\u672c\u5730\u7aefnew_local_branch_name<\/p>\n<\/li>\n<li>\n<p>git branch -d branch_name: \u522a\u9664\u672c\u5730\u7aef\u7684branch_name<\/p>\n<\/li>\n<li>\n<p>git branch &#8211;track local_branch_name remote_branch_name: \u5efa\u7acb\u4e00\u500btracking\u9060\u7aefremote_branch_name\u7684\u672c\u5730\u7aeflocal_branch_name\uff0c\u4e4b\u5f8c\u672c\u5730\u7aef\u7684branch\u9032\u884cpush\u6216pull\u7b49\u52d5\u4f5c\u5c07\u76f4\u63a5\u5c0d\u61c9\u5230\u9060\u7aef\u7684branch<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git checkout: \u5207\u63dbbranch<\/p>\n<ul>\n<li>\n<p>git checkout local_branch_name: \u5207\u63db\u81f3\u672c\u5730\u7aef\u6307\u5b9a\u7684local_branch_name\uff0c\u82e5\u5207\u63db\u4e4b\u524d\u5df2\u6709\u4fee\u6539\u8ffd\u8e64\u7684\u6a94\u6848\uff0c\u52d9\u5fc5\u5148commit<\/p>\n<\/li>\n<li>\n<p>git checkout -b new_local_branch_name: \u4ee5\u7576\u524d\u5206\u652f\u70ba\u6839\u672c\uff0c\u65bc\u672c\u5730\u7aef\u65b0\u5efa\u5206\u652fnew_local_branch_name\uff0c\u4e26\u5207\u63db\u81f3new_local_branch_name (\u610f\u5373\u5148 git branch new_local_branch_name \u518d git checkout new_local_branch_name)<\/p>\n<\/li>\n<li>\n<p>git checkout &#8212; file_name: \u9084\u539f\u6a94\u6848file_name\u81f3\u65bc\u6b64branch\u4e2d\u672a\u4fee\u6539\u7684\u72c0\u614b<\/p>\n<\/li>\n<li>\n<p>git checkout &#8211;: \u5c07\u5168\u90e8\u6a94\u6848\u9084\u539f\u81f3branch\u672a\u4fee\u6539\u7684\u72c0\u614b<\/p>\n<\/li>\n<li>\n<p>git checkout -f: \u5c07\u5168\u90e8\u6a94\u6848\u9084\u539f\u81f3branch\u672a\u4fee\u6539\u7684\u72c0\u614b<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git merge: \u5408\u4f75branch<\/p>\n<p>merge\u6700\u91cd\u8981\u7684\u89c0\u5ff5\u662f\u5207\u63db\u81f3\u4e3b\u8981\u7684branch\uff0c\u518d\u9032\u884cmerge\u52d5\u4f5c\uff0c\u610f\u5373\u5148 git checkout master_branch\uff0c\u518dgit merge fixed_branch<\/p>\n<ul>\n<li>git merge branch_name: \u5c07branch_name\u5957\u7528\u81f3\u76ee\u524dbranch\u4e0a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git reset: \u56de\u5fa9<\/p>\n<\/li>\n<\/ul>\n<p>Ref. http:\/\/blog.miniasp.com\/post\/2013\/08\/19\/Learning-Git-Part-1-Installation-Options-Tool-Usage-on-Local.aspx<\/p>\n<p>Ref. http:\/\/kingofamani.gitbooks.io\/git-teach\/content\/chapter_3_branch\/chapter_3_branchmerge.html<\/p>\n<ul>\n<li>\n<p>git reset &#8211;hard [commit_id]: \u56de\u5fa9\u81f3\u6307\u5b9a\u7684commit_id\u7248\u672c\uff0c\u82e5\u6c92\u6307\u5b9a\uff0c\u9810\u8a2d\u70baHEAD\uff0c\u8868\u793a\u53d6\u6d88\u9019\u6b21\u7684merge\uff0c\u6240\u6709\u672c\u5730\u7aef\u7684\u8b8a\u66f4\u90fd\u6703\u907a\u5931<\/p>\n<ul>\n<li>\n<p>git reset &#8211;hard ORIG_HEAD: \u56de\u5fa9\u5230\u5408\u4f75\u524d\u7684\u4e0a\u4e00\u7248\uff0c\u6240\u6709\u672c\u5730\u7aef\u7684\u8b8a\u66f4\u90fd\u6703\u907a\u5931<\/p>\n<\/li>\n<li>\n<p>git reset &#8211;soft: \u53d6\u6d88commit\uff0c\u6a94\u6848\u9084\u5728<\/p>\n<\/li>\n<li>\n<p>git reset &#8211;mixed: \u53d6\u6d88commit\uff0c\u53d6\u6d88add\u65b0\u589e\u7684\u6a94\u6848 &lt;==\u9810\u8a2d\u52d5\u4f5c<\/p>\n<\/li>\n<li>\n<p>git reset commit_id: \u56de\u5fa9\u81f3\u6307\u5b9a\u7684commit_id\u7248\u672c\uff0c\u4fee\u6539\u7684\u6a94\u6848\u9084\u5728<\/p>\n<\/li>\n<li>\n<p>git reset &#8211;soft HEAD^: \u56de\u5fa9\u81f3\u4e0a\u6b21commit\u5f8c\u7684\u52d5\u4f5c<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>git clean -df: \u6e05\u9664\u66ab\u5b58\u6a94\u6848\uff0c\u5305\u542b\u76ee\u9304<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>git stash: \u66ab\u5b58\u6a5f\u5236 git stash: \u66ab\u5b58\u6a5f\u5236\uff0c\u53ef\u4fdd\u7559\u76ee\u524d\u72c0\u614b\uff0c\u91cd\u65b0\u53d6\u56de\u5176\u4ed6\u7248\u672c\u7684code git stash clear: \u6e05\u9664\u6240\u6709\u66ab\u5b58\u7a7a\u9593 git stash drop {git status name}: \u6e05\u9664\u6307\u5b9a\u7684\u66ab\u5b58\u72c0\u614b\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u522a\u9664\u6700\u8fd1\u7684\u90a3\u4e00\u500b git stash list: \u67e5\u770b\u76ee\u524d\u66ab\u5b58\u5217\u8868 git stash apply {git stash name}: \u53d6\u56de\u66ab\u5b58\u7684\u72c0\u614b\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u6293\u53d6\u6700\u8fd1\u7684\u7248\u672c git stash show {git stash name}: \u67e5\u770b\u6307\u5b9a\u7684\u66ab\u5b58\u8207parent\u5dee\u7570\u7684\u90e8\u5206\uff0c\u5982\u679c\u4e0d\u52a0\u53c3\u6578\uff0c\u5247\u986f\u793a\u6700\u8fd1\u7684\u90a3\u4e00\u500b\u7248\u672c git stash branch {git stash &hellip; <a href=\"https:\/\/cowmanchiang.me\/wp\/?p=1477\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[],"class_list":["post-1477","post","type-post","status-publish","format-standard","hentry","category-git"],"_links":{"self":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1477"}],"version-history":[{"count":1,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1477\/revisions"}],"predecessor-version":[{"id":1921,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=\/wp\/v2\/posts\/1477\/revisions\/1921"}],"wp:attachment":[{"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cowmanchiang.me\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}