{"rsdb":{"rid":"152262","subhead":"","postdate":"0","aid":"114577","fid":"55","uid":"1","topic":"1","content":"
\n
\n \n

\u9644\u4ef6\u662fgit\u5b8c\u5168\u56fe\u89e3\u3002\u4e0b\u9762\u662f\u57fa\u672c\u547d\u4ee4\u7684\u89e3\u91ca\uff0c\u4e3b\u8981\u6709\uff1aadd, reset, checkout, pull, push, fetch, clone, init, tag\u7b49\u3002<\/p> \n

Ps:\u5728commit\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4e00\u5b9a\u8981\u52a0-m\u53c2\u6570\uff0c\u5199\u4e0acommit messages\uff0c\u5426\u5219\u4f1a\u6253\u5f00vim\u5f3a\u5236\u4f60\u5199\u4e00\u4e2a\u3002<\/p> \n

\u5173\u4e8egit flow\uff0c\u7f51\u4e0a\u4e5f\u6709\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\uff0c\u6bd4\u5982\uff1a\u5982\u4f55\u6b63\u786e\u4f7f\u7528Git Flow<\/a><\/p> \n

1\u3001Git add \u8be6\u89e3<\/p> \n

add\u5c06\u5f53\u524d\u5de5\u4f5c\u533a\u7684\u6539\u52a8\u4fdd\u5b58\u5230\u6682\u5b58\u533a\u3002<\/p> \n

<\/p> \n

\u5728\u4e00\u6b21commit\u4e4b\u524d\uff0c\u53ef\u4ee5\u8fdb\u884c\u591a\u6b21add\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ef\u4ee5\u53ea\u6539\u52a8\u4e00\u70b9\u5c31add\uff0c\u4e00\u6b21commit\u5373\u53ef\u3002<\/p> \n

<\/p> \n

git add\n <\/pathspec><\/p> \n

pathspec\u53ef\u4ee5\u662f\u4e00\u4e2a\u786e\u5b9a\u7684\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u7528\u7edf\u914d\u7b26\uff0c\u6bd4\u5982 git add *.c\u5c06add\u6240\u6709.c\u540e\u7f00\u7684\u6587\u4ef6\uff1b<\/p> \n

<\/p> \n

git add-AstagesAll<\/p> \n

git add .stagesnew and modified,without deleted<\/p> \n

git add -ustagesmodified and deleted,without new<\/p> \n

<\/p> \n

\u4f7f\u7528\u5b9e\u4f8b\uff1a<\/p> \n

\u5728\u4fee\u6539\u6587\u4ef6\u540e\uff0c\u4f7f\u7528git status\u663e\u793a\uff1a<\/p> \n

<\/p> \n

$ git status<\/p> \n

On branch master<\/p> \n

Changes not staged forcommit:\uff08\u4e0b\u5217\u4fee\u6539\u672a\u52a0\u5165\u6682\u5b58\u533a\uff0c\u4e0d\u4f1a\u88ab\u63d0\u4ea4\uff09<\/p> \n

(use \"gitadd \n \n ...\" to update what will be committed)\uff08\u4f7f\u7528gitadd \n \n \u5c06\u4fee\u6539\u52a0\u5165\u6682\u5b58\u533a\uff09\n <\/file>\n <\/file><\/p> \n

(use \"gitcheckout -- \n \n ...\" to discard changes in working d\uff08\u4f7f\u7528git checkout -- \n \n \u53d6\u6d88\u4ee5\u6587\u4ef6\u7684\u4fee\u6539\uff0c\u6240\u6709\u4fee\u6539\u90fd\u4f1a\u88ab\u6e05\u9664\uff0c\u53ea\u4f1a\u6e05\u9664\u5de5\u4f5c\u533a\u7684\u6587\u4ef6\u4fee\u6539\uff0c\u5df2\u7ecf\u63d0\u4ea4\u5230\u6682\u5b58\u533a\u7684\u4fee\u6539\u4e0d\u53d7\u5f71\u54cd\uff0c\u5373\u5c06\u5de5\u4f5c\u533a\u7684\u76f8\u5173\u6587\u4ef6\u7528\u6682\u5b58\u533a\u7684\u6587\u4ef6\u66ff\u6362\u6389\u3002\uff09\n <\/file>\n <\/file><\/p> \n

<\/p> \n

modified: welcome.txt<\/p> \n

<\/p> \n

no changes added tocommit (use \"git add\" and\/or \"git commit -a\")<\/p> \n

<\/p> \n

\u5728\u4f7f\u7528git add .\u540e\uff0cgit status\u663e\u793a\uff1a<\/p> \n

<\/p> \n

$ git status<\/p> \n

On branch master<\/p> \n

Changes to becommitted:\uff08\u8fd9\u4e9b\u66f4\u6539\u9700\u8981\u88ab\u63d0\u4ea4\uff09<\/p> \n

(use \"gitreset HEAD \n \n ...\" to unstage)\uff08\u5982 \u679c\u540e\u6094\u4e86\uff0c\u53ef\u4ee5\u4f7f\u7528git reset HEAD\n \n \u547d\u4ee4\uff0c\u5c06\u6587\u4ef6\u79fb\u51fa\u6682\u5b58\u533a\uff0c\u6062\u590d\u5230\u5de5\u4f5c\u533a\uff0c\u4e0b\u6b21commit\u65f6\u5c06\u4e0d\u63d0\u4ea4\u8be5\u6587\u4ef6\u3002 git reset HEAD\u547d\u4ee4\u4f1a\u5c06\u6682\u5b58\u533a\u7684\u6587\u4ef6\u6062\u590d\u6210HEAD\u6240\u6307\u5411\u7684\u72b6\u6001\uff0c\u5373\u6062\u590d\u5230\u7248\u672c\u5e93\u91cc\u4fdd\u5b58\u7684\u72b6\u6001\uff0c\u5de5\u4f5c\u533a\u7684\u6587\u4ef6\u4e0d\u53d7\u5f71\u54cd\uff09\n <\/file>\n <\/file><\/p> \n

<\/p> \n

modified: welcome.txt<\/p> \n

<\/p> \n

<\/p> \n

beichen2012@BEICHEN2012-PC\/F\/leargit (master)<\/p> \n

<\/p> \n

\u53e6\uff1a<\/p> \n

git checkout HEAD\n \n \u547d\u4ee4\uff1a\u4f1a\u7528\u7248\u672c\u5e93\u4e2d\u7684\u6587\u4ef6\u66ff\u6362\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u4e2d\u7684\u6587\u4ef6\uff0c\u5de5\u4f5c\u533a\u7684\u4fee\u6539\u4f1a\u88ab\u6e05\u9664\uff0c\u6682\u5b58\u533a\u672a\u63d0\u4ea4\u7684\u4fee\u6539\u4e5f\u4f1a\u88ab\u6e05\u9664\u3002\n <\/file><\/p> \n

<\/p> \n

2\u3001git reset<\/p> \n

git reset\u662f\u91cd\u7f6e\u547d\u4ee4\uff0c\u5176\u9ed8\u8ba4\u503c\u662f\u7528HEAD\u6307\u5411\u7684\u7248\u672c\u5e93\u6765\u91cd\u7f6e\u6682\u5b58\u533a\uff0c\u5f88\u5c11\u76f4\u63a5\u64cd\u4f5c\u5de5\u4f5c\u533a\uff08--hard\u9664\u5916\uff09\uff0c\u6240\u4ee5\u91cd\u7f6e\u4e00\u822c\u662f\u7528\u6765\u91cd\u7f6e\u6682\u5b58\u533a\u7684\u3002<\/p> \n

<\/p> \n

\u547d\u4ee4\u683c\u5f0f\uff1agit reset[\n \n ] [\n \n ]\n <\/commit>\n <\/mode><\/p> \n

<\/p> \n

a\u3001--hard\uff0c\u4f8b\u5982\uff1agit reset --hard \n <\/commit><\/p> \n

\u66ff\u6362\u6307\u9488\u6307\u5411\uff0c\u5f15\u7528\u6307\u5411\u65b0\u7684\u63d0\u4ea4ID<\/p> \n

\u66ff\u6362\u6682\u5b58\u533a\uff0c\u5c06\u5f15\u7528\u6307\u5411\u7684\u65b0\u7684\u7248\u672c\u5e93\u6587\u4ef6\u66ff\u6362\u5230\u6682\u6210\u5b58\u533a\uff0c\u5373\u6682\u5b58\u533a\u6587\u4ef6\u5c06\u4e0e\u65b0\u7684\u7248\u672c\u5e93\u6587\u4ef6\u4fdd\u6301\u4e00\u81f4<\/p> \n

\u66ff\u6362\u5de5\u4f5c\u533a\uff0c\u5de5\u4f5c\u533a\u6587\u4ef6\u5c06\u540c\u65b0\u7684\u7248\u672c\u5e93\u6587\u4ef6\u4fdd\u6301\u4e00\u81f4<\/p> \n

\u4f7f\u7528--hard\u53c2\u6570\uff0c\u5c06\u4f1a\u628a\u5f15\u7528\u6307\u5411\u65b0\u7684\uff08\u5386\u53f2\u7684\uff09\u63d0\u4ea4ID\uff0c\u5e76\u628a\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u6587\u4ef6\u540c\u6b65\u6210\u65b0\u7684\u7248\u672c\u5e93\u6587\u4ef6\uff0c\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u7684\u6240\u6709\u539f\u6587\u4ef6\u5c06\u4e22\u5931 \u3002<\/p> \n

<\/p> \n

b\u3001--soft\uff0c\u5982\uff1agit reset --soft \n <\/commit><\/p> \n

\u6b64\u547d\u4ee4\u53ea\u4f1a\u628a\u7248\u672c\u5e93\u7684\u5f15\u7528\u6307\u5411\u6539\u53d8\uff0c\u4f46\u4e0d\u4f1a\u6539\u53d8\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u3002<\/p> \n

\u4f8b\u5982\uff1agit reset --softHEAD^,\u6b64\u547d\u4ee4\u4f7f\u7528\u540e\uff0c\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u4fdd\u6301\u4e0d\u53d8\uff0c\u4f46\u662f\u5f15\u7528ID\u5411\u524d\u56de\u9000\u4e00\u6b21\uff0c\u5f53\u5bf9\u66f4\u6539\u4e0d\u6ee1\u610f\u65f6\uff0c\u64a4\u9500\u6700\u65b0\u7684\u63d0\u4ea4\u4ee5\u4fbf\u91cd\u65b0\u63d0\u4ea4\u3002\u4e0e\u6b64\u529f\u80fd\u76f8\u540c\u7684\u4e00\u4e2a\u547d\u4ee4\u662f\uff1a git commit --amend ,\u7528\u4e8e\u5bf9\u6700\u65b0\u63d0\u4ea4\u91cd\u65b0\u63d0\u4ea4\u4ee5\u4fee\u8865\u9519\u8bef\u7684\u63d0\u4ea4\u8bf4\u660e\u6216\u9519\u8bef\u7684\u63d0\u4ea4\u6587\u4ef6\u3002<\/p> \n

<\/p> \n

c\u3001--mixed,\u5982\uff1agit reset --mixed \n \n \u6216git reset\n <\/commit>\n <\/commit><\/p> \n

\u6b64\u547d\u4ee4\u4f1a\u6539\u53d8\u5f15\u7528\u7684\u6307\u5411\uff0c\u5e76\u91cd\u7f6e\u6682\u5b58\u533a\uff0c\u4e0d\u5f71\u54cd\u5de5\u4f5c\u533a\u3002<\/p> \n

git reset\u6216 gitreset HEAD:\u4ec5\u7528\u4e8e\u5c06HEAD\u6307\u5411\u7684\u7248\u672c\u5e93\u533a\u5185\u5bb9\u91cd\u7f6e\u5230 \u6682\u5b58\u533a\uff0c\u5de5\u4f5c\u533a\u4e0d\u53d7\u5f71\u54cd\uff0c\u76f8\u5f53\u4e8e\u5c06\u4e4b\u524d git add\u547d\u4ee4stage\u5230\u6682\u5b58\u533a\u7684\u4fee\u6539\u64a4\u51fa\u6682\u5b58\u533a\u3002<\/p> \n

git reset -- filename\u6216gitreset HEAD filename:\u4ec5\u5c06 filename\u6587\u4ef6\u7684\u6539\u52a8\u64a4\u51fa\u6682\u5b58\u533a\uff08\u4ec5\u5c06filename\u6587\u4ef6\u4ece\u7248\u672c\u5e93\u4e2d\u91cd\u7f6e\u5230\u6682\u5b58\u533a\uff09\uff0c\u6682\u5b58\u533a\u4e2d\u7684\u5176\u5b83\u6587\u4ef6\u4e0d\u53d8\u3002\u76f8\u5f53\u4e8e\u5bf9gitadd filename\u7684\u53cd\u64cd\u4f5c\u3002<\/p> \n

<\/p> \n

3\u3001git checkout<\/p> \n

git checkout\u7684\u9ed8\u8ba4\u503c\u662f\u6682\u5b58\u533a\uff08\u8fd9\u70b9\u4e0ereset\u547d\u4ee4\u4e0d\u540c\uff09\uff0c\u6b64\u68c0\u51fa\u547d\u4ee4\u4e3b\u8981\u7528\u6765\u8986\u76d6\u5de5\u4f5c\u533a\uff08\u5982\u679c\u4e0d\u7701\u7565\n \n \u53c2\u6570\uff0c\u4e5f\u4f1a\u8986\u76d6\u6682\u5b58\u533a\u6587\u4ef6\uff09\n <\/commit><\/p> \n

<\/p> \n

a\u3001gitcheckout \n <\/branch><\/p> \n

\u7528\u4e8e\u5207\u6362 \u5206\u652f<\/p> \n

git checkout -b \n <\/branch><\/p> \n

\u65b0\u5efa\u5206\u652f\uff0c\u5e76\u5207\u6362\u5230\u8be5\u5206\u652f<\/p> \n

b\u3001gitcheckout\u6216git checkout HEAD\uff1a<\/p> \n

\u6c47\u603b\u663e\u793a\u5de5\u4f5c\u533a\u3001\u6682\u5b58\u533a\u4e0eHEAD\u7684\u5dee\u5f02
<\/p> \n

c\u3001gitcheckout -- filename<\/p> \n

\u7528\u6682\u5b58\u533a\u7684\u6587\u4ef6\u6765\u8986\u76d6\u5de5\u4f5c\u533a\u7684\u6587\u4ef6<\/p> \n

git checkout -- . \u6216 git checkout . :\u7528\u6682\u5b58\u533a\u7684\u6587\u4ef6\u8986\u76d6\u6240\u6709\u5de5\u4f5c\u533a\u7684\u6587\u4ef6\uff0c\u76f8\u5f53\u5371\u9669\u3002<\/p> \n

<\/p> \n

d\u3001git checkout HEAD^(\u6216\u662f\u5176\u4ed6\u7684commit id\uff09<\/p> \n

\u7528HEAD^\uff08\u6216\u662f\u5176\u4ed6\u7684commit id\uff09\u6307\u5411\u7684\u7248\u672c\u5e93\u4e2d\u7684\u6587\u4ef6\uff0c\u66ff\u6362\u5f53\u524d\u5de5\u4f5c\u533a\u7684\u6587\u4ef6\uff0c\u5f53\u524d\u7684\u5de5\u4f5c\u533a\u5904\u4e8e\u4e00\u4e2adetached HEAD\uff08\u6e38\u79bbHEAD\uff09\uff0c\u6b64\u547d\u4ee4\u53ef\u7528\u4e8e\u67e5\u770b\u7248\u672c\u5e93\u7684\u67d0\u4e00\u5386\u53f2\u6587\u4ef6\uff1b\u5982\u679c\u4fee\u6539\u4e86\u6587\u4ef6\uff0c\u4e5f\u4e0d\u4f1a\u88ab\u4fdd\u5b58\uff0c\u5982\u679c\u60f3\u8981\u4fdd\u5b58 \uff0c\u4f7f\u7528\uff1agit checkout -b new_branch_name\uff0c\u521b\u5efa\u57fa\u4e8e\u5f53\u524d\u6e38\u79bbHEAD\u7684\u5206\u652f \u3002<\/p> \n

4\u3001git init,remote, clone, pull, push, fetch<\/p> \n

a\u3001\u5728\u672c\u5730\u5efa\u7acb\u670d\u52a1\u5668\u4ed3\u5e93\uff08\u8fdc\u7aef\u4ed3\u5e93\uff09<\/p> \n

mkdir xx.git<\/p> \n

cd xx.git<\/p> \n

git init --bare<\/p> \n

--bare\u53c2\u6570\u8868\u660e\u521b\u5efa\u4e00\u4e2a\u201c\u88f8\u201d\u4ed3\u5e93\uff0c\u8be5\u4ed3\u5e93\u4e0d\u5305\u542b\u5de5\u4f5c\u76ee\u5f55\uff0c\u4ec5\u5305\u542bgit\u7684\u4e00\u7cfb\u5217\u7248\u672c\u5386\u53f2\u8bb0\u5f55\u6587\u4ef6\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e0d\u80fd\u5728\u6b64\u76ee\u5f55\u4e0b\u5de5\u4f5c\uff08\u4e0d\u80fd\u4f7f\u7528git status\u67e5\u770b\u72b6\u6001\u7b49\uff0c\u4f46\u662f\u53ef\u4ee5\u7528gitk\u67e5\u770b\u5386\u53f2\uff09\u3002\u76ee\u7684\u662f\u4e3a\u4e86\u9632\u6b62\u670d\u52a1\u5668\u4ed3\u5e93\u6709\u4eba\u5728\u64cd\u4f5c\u67d0\u4e00\u5206\u652f\uff0c\u5ba2\u6237\u7aef\u6709\u4eba\u5411\u540c\u6837\u7684\u5206\u652f\u63d0\u4ea4\u800c\u9020\u6210\u63d0\u4ea4\u5931\u8d25\u7b49\u4e00\u51b2\u7a81\u95ee\u9898\u3002<\/p> \n

<\/p> \n

b\u3001clone\u547d\u4ee4<\/p> \n

\u683c\u5f0f\uff1agit clone \n \n <\u672c\u5730\u76ee\u5f55\u540d>\n <\/xxxx.git><\/p> \n

\u672c\u5730\u76ee\u5f55\u53ef\u4ee5\u7701\u7565\uff0c\u5219clone\u5230\u5f53\u524d\u76ee\u5f55<\/p> \n

b.1\uff09\u53eaclone\u67d0\u4e00\u5206\u652f<\/p> \n

git clone\u2013b \n \n xxxx.git\n <\/branch><\/p> \n

\u9ed8\u8ba4\u5219clone\u6240\u6709\u5206\u652f\uff0c\u4f46\u662f\u53ea\u663e\u793amaster\u5206\u652f\uff1b<\/p> \n

b.2\uff09clone\u6240\u6709\u5206\u652f<\/p> \n

git clone xx.git<\/p> \n

git branch\u2013a \/\/\u663e\u793a\u6240\u6709\u7684\u5206\u652f\uff08\u5305\u62ec\u9690\u85cf\u7684\u5206\u652f\uff09<\/p> \n

git checkout\u2013b \n \n remote\/origin\/\n \n \/\/\u57fa\u4e8e\u8fdc\u7a0b\u7684branch\u5206\u652f\u521b\u5efa\u672c\u5730branch\u5206\u652f\u5e76\u5207\u6362\u5230branch\u5206\u652f\n <\/branch>\n <\/branch><\/p> \n

<\/p> \n

c\u3001remote<\/p> \n

\u4e3a\u4e86\u4fbf\u4e8e\u7ba1\u7406\uff0cGit\u8981\u6c42\u6bcf\u4e2a\u8fdc\u7a0b\u4e3b\u673a\u90fd\u5fc5","orderid":"0","title":"\u5173\u4e8eGIT VCS\u7684\u4f7f\u7528\uff08\u516c\u53f8\u8d44\u6599\uff09(\u4e00)","smalltitle":"","mid":"0","fname":"windows\u7f16\u7a0b\u57fa\u7840","special_id":"0","bak_id":"0","info":"0","hits":"778","pages":"3","comments":"0","posttime":"2016-04-23 17:39:05","list":"1461404345","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"http:\/\/www.cppentry.com\/upload_files\/article\/55\/1_mnodp__.png","ispic":"1","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"\u5173\u4e8e<\/A> GIT<\/A> VCS<\/A> \u4f7f\u7528<\/A> \u516c\u53f8<\/A> \u8d44\u6599<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"14.17.22.31","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u5173\u4e8eGIT VCS\u7684\u4f7f\u7528\uff08\u516c\u53f8\u8d44\u6599\uff09","lastview":"1490460614","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}