{"id":1394,"date":"2021-07-30T15:47:53","date_gmt":"2021-07-30T07:47:53","guid":{"rendered":"https:\/\/egonlin.com\/?p=1394"},"modified":"2022-04-06T20:48:53","modified_gmt":"2022-04-06T12:48:53","slug":"%e7%ac%ac%e4%b8%89%e8%8a%82%ef%bc%9agit%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=1394","title":{"rendered":"\u7b2c\u4e09\u8282\uff1agit\u57fa\u7840"},"content":{"rendered":"<h1>git\u57fa\u7840\u4f7f\u7528<\/h1>\n<h2>\u4e00\u3001\u4ed3\u5e93<\/h2>\n<pre><code class=\"language-bash\"># \u5728\u5f53\u524d\u76ee\u5f55\u65b0\u5efa\u4e00\u4e2aGit\u4ee3\u7801\u5e93\n$ git init\n\n# \u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55\uff0c\u5c06\u5176\u521d\u59cb\u5316\u4e3aGit\u4ee3\u7801\u5e93\n$ git init \u76ee\u5f55\u540d\n\n# \u4e0b\u8f7d\u4e00\u4e2a\u9879\u76ee\u548c\u5b83\u7684\u6574\u4e2a\u4ee3\u7801\u5386\u53f2\n$ git clone [url]<\/code><\/pre>\n<h2>\u4e8c\u3001\u914d\u7f6e<\/h2>\n<h3>\u547d\u4ee4\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\"># \u663e\u793a\u5f53\u524d\u7684Git\u914d\u7f6e\n$ git config --list\n\n# \u7f16\u8f91Git\u914d\u7f6e\u6587\u4ef6\n$ git config -e [--global]\n\n# \u8bbe\u7f6e\u63d0\u4ea4\u4ee3\u7801\u65f6\u7684\u7528\u6237\u4fe1\u606f\n$ git config [--global] user.name &quot;[name]&quot;\n$ git config [--global] user.email &quot;[email address]&quot;<\/code><\/pre>\n<h2>\u4e09\u3001\u6dfb\u52a0\/\u5220\u9664\u6587\u4ef6<\/h2>\n<pre><code class=\"language-bash\"># \u6dfb\u52a0\u6307\u5b9a\u6587\u4ef6\u5230\u6682\u5b58\u533a\n$ git add [file1] [file2] ...\n\n# \u6dfb\u52a0\u6307\u5b9a\u76ee\u5f55\u5230\u6682\u5b58\u533a\uff0c\u5305\u62ec\u5b50\u76ee\u5f55\n$ git add [dir]\n\n# \u6dfb\u52a0\u5f53\u524d\u76ee\u5f55\u7684\u6240\u6709\u6587\u4ef6\u5230\u6682\u5b58\u533a\n$ git add .\n\n# \u6dfb\u52a0\u6bcf\u4e2a\u53d8\u5316\u524d\uff0c\u90fd\u4f1a\u8981\u6c42\u786e\u8ba4\n# \u5bf9\u4e8e\u540c\u4e00\u4e2a\u6587\u4ef6\u7684\u591a\u5904\u53d8\u5316\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5206\u6b21\u63d0\u4ea4\n$ git add -p\n\n# \u5220\u9664\u5de5\u4f5c\u533a\u6587\u4ef6\uff0c\u5e76\u4e14\u5c06\u8fd9\u6b21\u5220\u9664\u653e\u5165\u6682\u5b58\u533a\n$ git rm [file1] [file2] ...\n\n# \u505c\u6b62\u8ffd\u8e2a\u6307\u5b9a\u6587\u4ef6\uff0c\u4f46\u8be5\u6587\u4ef6\u4f1a\u4fdd\u7559\u5728\u5de5\u4f5c\u533a\n$ git rm --cached [file]\n\n# \u6539\u540d\u6587\u4ef6\uff0c\u5e76\u4e14\u5c06\u8fd9\u4e2a\u6539\u540d\u653e\u5165\u6682\u5b58\u533a\n$ git mv [file-original] [file-renamed]<\/code><\/pre>\n<h2>\u56db\u3001\u4ee3\u7801\u63d0\u4ea4<\/h2>\n<pre><code class=\"language-bash\"># \u63d0\u4ea4\u6682\u5b58\u533a\u5230\u4ed3\u5e93\u533a\n$ git commit -m [message]\n\n# \u63d0\u4ea4\u6682\u5b58\u533a\u7684\u6307\u5b9a\u6587\u4ef6\u5230\u4ed3\u5e93\u533a\n$ git commit [file1] [file2] ... -m [message]\n\n# \u63d0\u4ea4\u5de5\u4f5c\u533a\u81ea\u4e0a\u6b21commit\u4e4b\u540e\u7684\u53d8\u5316\uff0c\u76f4\u63a5\u5230\u4ed3\u5e93\u533a\n$ git commit -a\n\n# \u63d0\u4ea4\u65f6\u663e\u793a\u6240\u6709diff\u4fe1\u606f\n$ git commit -v\n\n# \u4f7f\u7528\u4e00\u6b21\u65b0\u7684commit\uff0c\u66ff\u4ee3\u4e0a\u4e00\u6b21\u63d0\u4ea4\n# \u5982\u679c\u4ee3\u7801\u6ca1\u6709\u4efb\u4f55\u65b0\u53d8\u5316\uff0c\u5219\u7528\u6765\u6539\u5199\u4e0a\u4e00\u6b21commit\u7684\u63d0\u4ea4\u4fe1\u606f\n$ git commit --amend -m [message]\n\n# \u91cd\u505a\u4e0a\u4e00\u6b21commit\uff0c\u5e76\u5305\u62ec\u6307\u5b9a\u6587\u4ef6\u7684\u65b0\u53d8\u5316\n$ git commit --amend [file1] [file2] ...<\/code><\/pre>\n<h2>\u4e94\u3001\u5206\u652f<\/h2>\n<pre><code class=\"language-bash\"># \u5217\u51fa\u6240\u6709\u672c\u5730\u5206\u652f\n$ git branch\n\n# \u5217\u51fa\u6240\u6709\u8fdc\u7a0b\u5206\u652f\n$ git branch -r\n\n# \u5217\u51fa\u6240\u6709\u672c\u5730\u5206\u652f\u548c\u8fdc\u7a0b\u5206\u652f\n$ git branch -a\n\n# \u65b0\u5efa\u4e00\u4e2a\u5206\u652f\uff0c\u4f46\u4f9d\u7136\u505c\u7559\u5728\u5f53\u524d\u5206\u652f\n$ git branch [branch-name]\n\n# \u65b0\u5efa\u4e00\u4e2a\u5206\u652f\uff0c\u5e76\u5207\u6362\u5230\u8be5\u5206\u652f\n$ git checkout -b [branch]\n\n# \u65b0\u5efa\u4e00\u4e2a\u5206\u652f\uff0c\u6307\u5411\u6307\u5b9acommit\n$ git branch [branch] [commit]\n\n# \u65b0\u5efa\u4e00\u4e2a\u5206\u652f\uff0c\u4e0e\u6307\u5b9a\u7684\u8fdc\u7a0b\u5206\u652f\u5efa\u7acb\u8ffd\u8e2a\u5173\u7cfb\n$ git branch --track [branch] [remote-branch]\n\n# \u5207\u6362\u5230\u6307\u5b9a\u5206\u652f\uff0c\u5e76\u66f4\u65b0\u5de5\u4f5c\u533a\n$ git checkout [branch-name]\n\n# \u5207\u6362\u5230\u4e0a\u4e00\u4e2a\u5206\u652f\n$ git checkout -\n\n# \u5efa\u7acb\u8ffd\u8e2a\u5173\u7cfb\uff0c\u5728\u73b0\u6709\u5206\u652f\u4e0e\u6307\u5b9a\u7684\u8fdc\u7a0b\u5206\u652f\u4e4b\u95f4\n$ git branch --set-upstream [branch] [remote-branch]\n\n# \u5408\u5e76\u6307\u5b9a\u5206\u652f\u5230\u5f53\u524d\u5206\u652f\n$ git merge [branch]\n\n# \u9009\u62e9\u4e00\u4e2acommit\uff0c\u5408\u5e76\u8fdb\u5f53\u524d\u5206\u652f\n$ git cherry-pick [commit]\n\n# \u5220\u9664\u5206\u652f\n$ git branch -d [branch-name]\n\n# \u5220\u9664\u8fdc\u7a0b\u5206\u652f\n$ git push origin --delete [branch-name]\n$ git branch -dr [remote\/branch]<\/code><\/pre>\n<h2>\u516d\u3001\u6807\u7b7e<\/h2>\n<pre><code class=\"language-bash\"># \u5217\u51fa\u6240\u6709tag\n$ git tag\n\n# \u65b0\u5efa\u4e00\u4e2atag\u5728\u5f53\u524dcommit\n$ git tag [tag]\n\n# \u65b0\u5efa\u4e00\u4e2atag\u5728\u6307\u5b9acommit\n$ git tag [tag] [commit]\n\n# \u5220\u9664\u672c\u5730tag\n$ git tag -d [tag]\n\n# \u5220\u9664\u8fdc\u7a0btag\n$ git push origin :refs\/tags\/[tagName]\n\n# \u67e5\u770btag\u4fe1\u606f\n$ git show [tag]\n\n# \u63d0\u4ea4\u6307\u5b9atag\n$ git push [remote] [tag]\n\n# \u63d0\u4ea4\u6240\u6709tag\n$ git push [remote] --tags\n\n# \u65b0\u5efa\u4e00\u4e2a\u5206\u652f\uff0c\u6307\u5411\u67d0\u4e2atag\n$ git checkout -b [branch] [tag]<\/code><\/pre>\n<h2>\u4e03\u3001\u67e5\u770b\u4fe1\u606f<\/h2>\n<pre><code class=\"language-bash\"># \u663e\u793a\u6709\u53d8\u66f4\u7684\u6587\u4ef6\n$ git status\n\n# \u663e\u793a\u5f53\u524d\u5206\u652f\u7684\u7248\u672c\u5386\u53f2\n$ git log\n\n# \u663e\u793acommit\u5386\u53f2\uff0c\u4ee5\u53ca\u6bcf\u6b21commit\u53d1\u751f\u53d8\u66f4\u7684\u6587\u4ef6\n$ git log --stat\n\n# \u641c\u7d22\u63d0\u4ea4\u5386\u53f2\uff0c\u6839\u636e\u5173\u952e\u8bcd\n$ git log -S [keyword]\n\n# \u663e\u793a\u67d0\u4e2acommit\u4e4b\u540e\u7684\u6240\u6709\u53d8\u52a8\uff0c\u6bcf\u4e2acommit\u5360\u636e\u4e00\u884c\n$ git log [tag] HEAD --pretty=format:%s\n\n# \u663e\u793a\u67d0\u4e2acommit\u4e4b\u540e\u7684\u6240\u6709\u53d8\u52a8\uff0c\u5176&quot;\u63d0\u4ea4\u8bf4\u660e&quot;\u5fc5\u987b\u7b26\u5408\u641c\u7d22\u6761\u4ef6\n$ git log [tag] HEAD --grep feature\n\n# \u663e\u793a\u67d0\u4e2a\u6587\u4ef6\u7684\u7248\u672c\u5386\u53f2\uff0c\u5305\u62ec\u6587\u4ef6\u6539\u540d\n$ git log --follow [file]\n$ git whatchanged [file]\n\n# \u663e\u793a\u6307\u5b9a\u6587\u4ef6\u76f8\u5173\u7684\u6bcf\u4e00\u6b21diff\n$ git log -p [file]\n\n# \u663e\u793a\u8fc7\u53bb5\u6b21\u63d0\u4ea4\n$ git log -5 --pretty --oneline\n\n# \u663e\u793a\u6240\u6709\u63d0\u4ea4\u8fc7\u7684\u7528\u6237\uff0c\u6309\u63d0\u4ea4\u6b21\u6570\u6392\u5e8f\n$ git shortlog -sn\n\n# \u663e\u793a\u6307\u5b9a\u6587\u4ef6\u662f\u4ec0\u4e48\u4eba\u5728\u4ec0\u4e48\u65f6\u95f4\u4fee\u6539\u8fc7\n$ git blame [file]\n\n# \u663e\u793a\u6682\u5b58\u533a\u548c\u5de5\u4f5c\u533a\u7684\u5dee\u5f02\n$ git diff\n\n# \u663e\u793a\u6682\u5b58\u533a\u548c\u4e0a\u4e00\u4e2acommit\u7684\u5dee\u5f02\n$ git diff --cached [file]\n\n# \u663e\u793a\u5de5\u4f5c\u533a\u4e0e\u5f53\u524d\u5206\u652f\u6700\u65b0commit\u4e4b\u95f4\u7684\u5dee\u5f02\n$ git diff HEAD\n\n# \u663e\u793a\u4e24\u6b21\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02\n$ git diff [first-branch]...[second-branch]\n\n# \u663e\u793a\u4eca\u5929\u4f60\u5199\u4e86\u591a\u5c11\u884c\u4ee3\u7801\n$ git diff --shortstat &quot;@{0 day ago}&quot;\n\n# \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u7684\u5143\u6570\u636e\u548c\u5185\u5bb9\u53d8\u5316\n$ git show [commit]\n\n# \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u53d1\u751f\u53d8\u5316\u7684\u6587\u4ef6\n$ git show --name-only [commit]\n\n# \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u65f6\uff0c\u67d0\u4e2a\u6587\u4ef6\u7684\u5185\u5bb9\n$ git show [commit]:[filename]\n\n# \u663e\u793a\u5f53\u524d\u5206\u652f\u7684\u6700\u8fd1\u51e0\u6b21\u63d0\u4ea4\n$ git reflog<\/code><\/pre>\n<h2>\u516b\u3001\u8fdc\u7a0b\u540c\u6b65<\/h2>\n<h3>1\u3001gitee\u6216github\u65b0\u5efa\u4ed3\u5e93<\/h3>\n<p><\/p><div id=\"rml_readmorelogin_placeholder\" style=\"position:relative;\"><div id=\"rml_fade_content\" style=\"position: absolute;\r\ntop:-10em;\r\nwidth:100%;\r\nheight:10em;\r\nbackground: -webkit-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -moz-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -o-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\r\nbackground-image: -ms-linear-gradient(rgba(255, 255, 255, 0) 0%,#ffffff 100%);\"><\/div><div class=\"wpf-controller aru_rml_from_in_post\" style=\"background-color:#eeeeee;border:5px solid #cce6ff;\" id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><h2 id=\"Header\">\u67e5\u770b\u66f4\u591a<\/h2><div id=\"Message\"><p>\u8054\u7cfb\u7ba1\u7406\u5458\u5fae\u4fe1tutu19192010\uff0c\u6ce8\u518c\u8d26\u53f7<\/p>\n<\/div><div id=\"StatusBarHeader\"><\/div><form id=\"ARU_ReadMoreLogin_ReadMoreLoginController\"><input name=\"post_id\" value=\"1394\" type=\"hidden\"\/><input name=\"_init_callback\" value=\"InitLogin\" type=\"hidden\"\/><input name=\"post_id\" value=\"1394\" type=\"hidden\"\/><input name=\"rt_ype\" value=\"1\" type=\"hidden\"\/><input name=\"nonce\" value=\"ac50a3a859\" type=\"hidden\"\/><input name=\"_wpnonce\" value=\"b0e6d8f8bf\" type=\"hidden\"\/><input name=\"_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_proxy_controller\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginController\" type=\"hidden\"\/><input name=\"_view\" value=\"ARU_ReadMoreLogin\\ReadMoreLoginView\" type=\"hidden\"\/><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\" width=\"400px\"><table class=\"wpf-table-placeholder\"><tbody class=\"wpf-table-placeholder\"><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Username:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"username\" value=\"\" type=\"text\"\/><\/td><\/tr><tr class=\"wpf-table-placeholder\"><th class=\"wpf-table-placeholder-input\"><label class=\"wpf-label\">Password:<\/label><\/th><\/tr><tr class=\"wpf-table-placeholder\"><td class=\"wpf-table-placeholder-input\"><input class=\"regular-text text_input\" name=\"password\" value=\"\" type=\"password\"\/><\/td><\/tr><\/tbody><\/table><p class=\"wpf-table-placeholder submit\"><button class=\"wp_plugin_framework_ajax_button\" type=\"button\" style=\"background-color:#4D90FE;;color:#ffffff;;border:1px solid #3079ed;\" name=\"_event\" value=\"ButtonLogin\">Log in<\/button><\/p><\/td><td class=\"wpf-table-placeholder-input\"><\/td><\/tr><\/tbody><\/table><\/form><div id=\"ButtonStartRegister\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=register\">Register<\/a><\/div><div id=\"Link1\"><a href=\"https:\/\/egonlin.com\/wp-login.php?action=lostpassword\">Forgotten username or password?<\/a><\/div><div id=\"StatusBarFooter\"><\/div><\/div><\/div><div id=aru_remaining_content><\/div>","protected":false},"excerpt":{"rendered":"<p>git\u57fa\u7840\u4f7f\u7528 \u4e00\u3001\u4ed3\u5e93 # \u5728\u5f53\u524d\u76ee\u5f55\u65b0\u5efa\u4e00\u4e2aGit\u4ee3\u7801\u5e93 $ git init # \u65b0\u5efa\u4e00\u4e2a\u76ee\u5f55\uff0c\u5c06\u5176\u521d\u59cb [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1390,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[169],"tags":[21,178,179,181,182,19,22,180,20],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1394"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1394"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/1394\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/1390"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}