{"id":9,"date":"2025-07-23T23:43:22","date_gmt":"2025-07-23T15:43:22","guid":{"rendered":"http:\/\/myws2.seelles.cn\/?p=9"},"modified":"2025-07-23T23:43:22","modified_gmt":"2025-07-23T15:43:22","slug":"git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/myws2.seelles.cn\/index.php\/2025\/07\/23\/git%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4\/","title":{"rendered":"git\u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"\n<p>\u67e5\u770b\u3001\u6dfb\u52a0\u3001\u63d0\u4ea4\u3001\u5220\u9664\u3001\u627e\u56de\uff0c\u91cd\u7f6e\u4fee\u6539\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git help &lt;command> # \u663e\u793acommand\u7684help\ngit show # \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9 git show $id\ngit co -- &lt;file> # \u629b\u5f03\u5de5\u4f5c\u533a\u4fee\u6539\ngit co . # \u629b\u5f03\u5de5\u4f5c\u533a\u4fee\u6539\ngit add &lt;file> # \u5c06\u5de5\u4f5c\u6587\u4ef6\u4fee\u6539\u63d0\u4ea4\u5230\u672c\u5730\u6682\u5b58\u533a\ngit add . # \u5c06\u6240\u6709\u4fee\u6539\u8fc7\u7684\u5de5\u4f5c\u6587\u4ef6\u63d0\u4ea4\u6682\u5b58\u533a\ngit rm &lt;file> # \u4ece\u7248\u672c\u5e93\u4e2d\u5220\u9664\u6587\u4ef6\ngit rm &lt;file> --cached # \u4ece\u7248\u672c\u5e93\u4e2d\u5220\u9664\u6587\u4ef6\uff0c\u4f46\u4e0d\u5220\u9664\u6587\u4ef6\ngit reset &lt;file> # \u4ece\u6682\u5b58\u533a\u6062\u590d\u5230\u5de5\u4f5c\u6587\u4ef6\ngit reset -- . # \u4ece\u6682\u5b58\u533a\u6062\u590d\u5230\u5de5\u4f5c\u6587\u4ef6\ngit reset --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\ngit ci &lt;file> 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 \"some comments\"\ngit ci --amend # \u4fee\u6539\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u8bb0\u5f55\ngit revert &lt;$id> # \u6062\u590d\u67d0\u6b21\u63d0\u4ea4\u7684\u72b6\u6001\uff0c\u6062\u590d\u52a8\u4f5c\u672c\u8eab\u4e5f\u521b\u5efa\u6b21\u63d0\u4ea4\u5bf9\u8c61\ngit revert HEAD # \u6062\u590d\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u72b6\u6001\n\u67e5\u770b\u6587\u4ef6diff\ngit diff &lt;file> # \u6bd4\u8f83\u5f53\u524d\u6587\u4ef6\u548c\u6682\u5b58\u533a\u6587\u4ef6\u5dee\u5f02 git diff\ngit diff &lt;id1>&lt;id1>&lt;id2> # \u6bd4\u8f83\u4e24\u6b21\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02\ngit diff &lt;branch1>..&lt;branch2> # \u5728\u4e24\u4e2a\u5206\u652f\u4e4b\u95f4\u6bd4\u8f83\ngit diff --staged # \u6bd4\u8f83\u6682\u5b58\u533a\u548c\u7248\u672c\u5e93\u5dee\u5f02\ngit diff --cached # \u6bd4\u8f83\u6682\u5b58\u533a\u548c\u7248\u672c\u5e93\u5dee\u5f02\ngit diff --stat # \u4ec5\u4ec5\u6bd4\u8f83\u7edf\u8ba1\u4fe1\u606f\n\u67e5\u770b\u63d0\u4ea4\u8bb0\u5f55\ngit log git log &lt;file> # \u67e5\u770b\u8be5\u6587\u4ef6\u6bcf\u6b21\u63d0\u4ea4\u8bb0\u5f55\ngit log -p &lt;file> # \u67e5\u770b\u6bcf\u6b21\u8be6\u7ec6\u4fee\u6539\u5185\u5bb9\u7684diff\ngit log -p -2 # \u67e5\u770b\u6700\u8fd1\u4e24\u6b21\u8be6\u7ec6\u4fee\u6539\u5185\u5bb9\u7684diff\ngit log --stat #\u67e5\u770b\u63d0\u4ea4\u7edf\u8ba1\u4fe1\u606f\ntig\nMac\u4e0a\u53ef\u4ee5\u4f7f\u7528tig\u4ee3\u66ffdiff\u548clog\uff0cbrew install tig\nGit \u672c\u5730\u5206\u652f\u7ba1\u7406\n\u67e5\u770b\u3001\u5207\u6362\u3001\u521b\u5efa\u548c\u5220\u9664\u5206\u652f\ngit br -r # \u67e5\u770b\u8fdc\u7a0b\u5206\u652f\ngit br &lt;new_branch> # \u521b\u5efa\u65b0\u7684\u5206\u652f\ngit br -v # \u67e5\u770b\u5404\u4e2a\u5206\u652f\u6700\u540e\u63d0\u4ea4\u4fe1\u606f\ngit br --merged # \u67e5\u770b\u5df2\u7ecf\u88ab\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u7684\u5206\u652f\ngit br --no-merged # \u67e5\u770b\u5c1a\u672a\u88ab\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u7684\u5206\u652f\ngit co &lt;branch> # \u5207\u6362\u5230\u67d0\u4e2a\u5206\u652f\ngit co -b &lt;new_branch> # \u521b\u5efa\u65b0\u7684\u5206\u652f\uff0c\u5e76\u4e14\u5207\u6362\u8fc7\u53bb\ngit co -b &lt;new_branch> &lt;branch> # \u57fa\u4e8ebranch\u521b\u5efa\u65b0\u7684new_branch\ngit 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\ngit co $id -b &lt;new_branch> # \u628a\u67d0\u6b21\u5386\u53f2\u63d0\u4ea4\u8bb0\u5f55checkout\u51fa\u6765\uff0c\u521b\u5efa\u6210\u4e00\u4e2a\u5206\u652f\ngit br -d &lt;branch> # \u5220\u9664\u67d0\u4e2a\u5206\u652f\ngit br -D &lt;branch> # \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)\n \u5206\u652f\u5408\u5e76\u548crebase\ngit merge &lt;branch> # \u5c06branch\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\ngit merge origin\/master --no-ff # \u4e0d\u8981Fast-Foward\u5408\u5e76\uff0c\u8fd9\u6837\u53ef\u4ee5\u751f\u6210merge\u63d0\u4ea4\ngit rebase master &lt;branch> # \u5c06master rebase\u5230branch\uff0c\u76f8\u5f53\u4e8e\uff1a git co &lt;branch> &amp;&amp; git rebase master &amp;&amp; git co master &amp;&amp; git merge &lt;branch>\n Git\u8865\u4e01\u7ba1\u7406(\u65b9\u4fbf\u5728\u591a\u53f0\u673a\u5668\u4e0a\u5f00\u53d1\u540c\u6b65\u65f6\u7528)\ngit diff > ..\/sync.patch # \u751f\u6210\u8865\u4e01\ngit apply ..\/sync.patch # \u6253\u8865\u4e01\ngit apply --check ..\/sync.patch #\u6d4b\u8bd5\u8865\u4e01\u80fd\u5426\u6210\u529f\n Git\u6682\u5b58\u7ba1\u7406\ngit stash # \u6682\u5b58\ngit stash list # \u5217\u6240\u6709stash\ngit stash apply # \u6062\u590d\u6682\u5b58\u7684\u5185\u5bb9\ngit stash drop # \u5220\u9664\u6682\u5b58\u533a\nGit\u8fdc\u7a0b\u5206\u652f\u7ba1\u7406\ngit pull # \u6293\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u6240\u6709\u5206\u652f\u66f4\u65b0\u5e76\u5408\u5e76\u5230\u672c\u5730\ngit pull --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\ngit fetch origin # \u6293\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u66f4\u65b0\ngit merge origin\/master # \u5c06\u8fdc\u7a0b\u4e3b\u5206\u652f\u5408\u5e76\u5230\u672c\u5730\u5f53\u524d\u5206\u652f\ngit co --track origin\/branch # \u8ddf\u8e2a\u67d0\u4e2a\u8fdc\u7a0b\u5206\u652f\u521b\u5efa\u76f8\u5e94\u7684\u672c\u5730\u5206\u652f\ngit co -b &lt;local_branch> origin\/&lt;remote_branch> # \u57fa\u4e8e\u8fdc\u7a0b\u5206\u652f\u521b\u5efa\u672c\u5730\u5206\u652f\uff0c\u529f\u80fd\u540c\u4e0a\ngit push # push\u6240\u6709\u5206\u652f\ngit push origin master # \u5c06\u672c\u5730\u4e3b\u5206\u652f\u63a8\u5230\u8fdc\u7a0b\u4e3b\u5206\u652f\ngit 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)\ngit push origin &lt;local_branch> # \u521b\u5efa\u8fdc\u7a0b\u5206\u652f\uff0c origin\u662f\u8fdc\u7a0b\u4ed3\u5e93\u540d\ngit push origin &lt;local_branch>:&lt;remote_branch> # \u521b\u5efa\u8fdc\u7a0b\u5206\u652f\ngit push origin :&lt;remote_branch> #\u5148\u5220\u9664\u672c\u5730\u5206\u652f(git br -d &lt;branch>)\uff0c\u7136\u540e\u518dpush\u5220\u9664\u8fdc\u7a0b\u5206\u652f\nGit\u8fdc\u7a0b\u4ed3\u5e93\u7ba1\u7406\nGitHub\ngit remote -v # \u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u5730\u5740\u548c\u4ed3\u5e93\u540d\u79f0\ngit remote show origin # \u67e5\u770b\u8fdc\u7a0b\u670d\u52a1\u5668\u4ed3\u5e93\u72b6\u6001\ngit remote add origin git@ github:robbin\/robbin_site.git # \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\ngit 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> # \u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93\n\u521b\u5efa\u8fdc\u7a0b\u4ed3\u5e93\ngit clone --bare robbin_site robbin_site.git # \u7528\u5e26\u7248\u672c\u7684\u9879\u76ee\u521b\u5efa\u7eaf\u7248\u672c\u4ed3\u5e93\nscp -r my_project.git git@ git.csdn.net:~ # \u5c06\u7eaf\u4ed3\u5e93\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\nmkdir robbin_site.git &amp;&amp; cd robbin_site.git &amp;&amp; git --bare init # \u5728\u670d\u52a1\u5668\u521b\u5efa\u7eaf\u4ed3\u5e93\ngit remote add origin git@ github.com:robbin\/robbin_site.git # \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\ngit push -u origin master # \u5ba2\u6237\u7aef\u9996\u6b21\u63d0\u4ea4\ngit push -u origin develop # \u9996\u6b21\u5c06\u672c\u5730develop\u5206\u652f\u63d0\u4ea4\u5230\u8fdc\u7a0bdevelop\u5206\u652f\uff0c\u5e76\u4e14track\ngit remote set-head origin master # \u8bbe\u7f6e\u8fdc\u7a0b\u4ed3\u5e93\u7684HEAD\u6307\u5411master\u5206\u652f\n\u4e5f\u53ef\u4ee5\u547d\u4ee4\u8bbe\u7f6e\u8ddf\u8e2a\u8fdc\u7a0b\u5e93\u548c\u672c\u5730\u5e93\ngit branch --set-upstream master origin\/master\ngit branch --set-upstream develop origin\/develop\ngit checkout -b dev origin\/dev # \u521b\u5efa\u672c\u5730\u5206\u652f\u5e76\u8ddf\u8e2a\u8fdc\u7a0b\u5206\u652f<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u67e5\u770b\u3001\u6dfb\u52a0\u3001\u63d0\u4ea4\u3001\u5220\u9664\u3001\u627e\u56de\uff0c\u91cd\u7f6e\u4fee\u6539\u6587\u4ef6<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":1,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":10,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions\/10"}],"wp:attachment":[{"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myws2.seelles.cn\/index.php\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}