{"id":271,"date":"2023-02-22T20:44:51","date_gmt":"2023-02-22T12:44:51","guid":{"rendered":"https:\/\/muchen.fan\/?p=271"},"modified":"2024-03-22T00:14:59","modified_gmt":"2024-03-21T16:14:59","slug":"git-%e5%91%bd%e4%bb%a4%e9%80%9f%e6%9f%a5%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/muchen.fan\/?p=271","title":{"rendered":"Git \u547d\u4ee4\u901f\u67e5\u8868"},"content":{"rendered":"<p>\u7edd\u5927\u90e8\u5206\u4eba\u7ecf\u5e38\u4f7f\u7528\u7684 Git \u547d\u4ee4\u53ea\u6709\u6781\u5c11\u7684\u4e00\u90e8\u5206\uff0c\u4e0d\u5e38\u4f7f\u7528\u7684\u547d\u4ee4\u5bb9\u6613\u9057\u5fd8\uff0c\u6545\u5236\u4f5c\u6b64\u901f\u67e5\u8868\u3002<\/p>\n<h3>\u4ed3\u5e93\u7ba1\u7406<\/h3>\n<ul>\n<li><code>git init<\/code>: \u521d\u59cb\u5316\u4ed3\u5e93\u3002<\/li>\n<li><code>git clone &lt;url&gt;<\/code>: \u514b\u9686\u4ed3\u5e93\u3002<\/li>\n<li><code>git remote add &lt;name&gt; &lt;url&gt;<\/code>: \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/li>\n<li><code>git remote -v<\/code>: \u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/li>\n<li><code>git pull<\/code>: \u62c9\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u66f4\u65b0\u3002<\/li>\n<li><code>git push<\/code>: \u63a8\u9001\u672c\u5730\u63d0\u4ea4\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/li>\n<li><code>git fetch<\/code>: \u4ece\u8fdc\u7a0b\u4ed3\u5e93\u83b7\u53d6\u6700\u65b0\u66f4\u65b0\uff0c\u4f46\u4e0d\u5408\u5e76\u5230\u672c\u5730\u4ed3\u5e93\u3002<\/li>\n<\/ul>\n<h3>\u5206\u652f\u7ba1\u7406<\/h3>\n<ul>\n<li><code>git branch<\/code>: \u67e5\u770b\u5206\u652f\u4fe1\u606f\u3002<\/li>\n<li><code>git checkout &lt;branch&gt;<\/code>: \u5207\u6362\u5230\u6307\u5b9a\u5206\u652f\u3002<\/li>\n<li><code>git merge &lt;branch&gt;<\/code>: \u5c06\u6307\u5b9a\u5206\u652f\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\u3002<\/li>\n<li><code>git tag<\/code>: \u6807\u8bb0\u67d0\u4e2a\u63d0\u4ea4\u70b9\u3002<\/li>\n<\/ul>\n<h3>\u63d0\u4ea4\u7ba1\u7406<\/h3>\n<ul>\n<li><code>git add &lt;file&gt;<\/code>: \u5c06\u6587\u4ef6\u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002<\/li>\n<li><code>git commit -m &quot;&lt;message&gt;&quot;<\/code>: \u63d0\u4ea4\u6682\u5b58\u533a\u4e2d\u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u63d0\u4ea4\u4fe1\u606f\u3002<\/li>\n<li><code>git reset<\/code>: \u6062\u590d\u6587\u4ef6\u5230\u4e0a\u4e00\u4e2a\u63d0\u4ea4\u72b6\u6001\u3002<\/li>\n<li><code>git rm &lt;file&gt;<\/code>: \u5220\u9664\u6587\u4ef6\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u6682\u5b58\u533a\u3002<\/li>\n<li><code>git mv &lt;old-file&gt; &lt;new-file&gt;<\/code>: \u91cd\u547d\u540d\u6216\u79fb\u52a8\u6587\u4ef6\u3002<\/li>\n<li><code>git stash<\/code>: \u5c06\u5f53\u524d\u5de5\u4f5c\u533a\u7684\u4fee\u6539\u4fdd\u5b58\u5230\u4e00\u4e2a\u6808\u4e2d\u3002<\/li>\n<\/ul>\n<h3>\u72b6\u6001\u67e5\u8be2<\/h3>\n<ul>\n<li><code>git status<\/code>: \u67e5\u770b\u5f53\u524d\u4ed3\u5e93\u7684\u72b6\u6001\u3002<br \/>\n<code>git status --short<\/code>: <em>\u6211\u559c\u6b22\u7684\u683c\u5f0f<\/em><\/li>\n<li><code>git log<\/code>: \u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u8bb0\u5f55\u3002<br \/>\n<code>git log --all --graph --oneline<\/code>: <em>\u6211\u559c\u6b22\u7684\u683c\u5f0f<\/em><\/li>\n<li><code>git diff<\/code>: \u67e5\u770b\u5f53\u524d\u5de5\u4f5c\u533a\u4e0e\u6682\u5b58\u533a\u7684\u5dee\u5f02\u3002<\/li>\n<\/ul>\n<h3>\u521d\u59cb\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\">git config --global user.name &quot;\u540d\u5b57&quot;\ngit config --global user.email &quot;\u90ae\u7bb1\u5730\u5740&quot;\ngit config --global init.defaultBranch main #\u4f7f\u7528 main \u4f5c\u4e3a\u9ed8\u8ba4\u5206\u652f<\/code><\/pre>\n<p><strong>\u5982\u679c\u548c\u6211\u4e00\u6837\u559c\u6b22 vscode<\/strong>\uff0c\u5148\u5b89\u88c5 code \u547d\u4ee4\u5de5\u5177\u3002\u6253\u5f00 vscode\uff0c\u7136\u540e\u6309 F1 \u6216 Ctrl+Shift+P\uff0c\u5728\u547d\u4ee4\u9762\u677f\u4e2d\u641c\u7d22 &quot;Shell Command: Install 'code' command in PATH&quot;\u3002\u9009\u62e9\u8be5\u547d\u4ee4\u5e76\u56de\u8f66\uff0c\u5373\u53ef\u5b89\u88c5 code \u547d\u4ee4\u3002\u7136\u540e\uff1a<\/p>\n<pre><code class=\"language-bash\">git config --global core.editor &quot;code --wait&quot;\ngit config --global diff.tool vscode\ngit config --global difftool.vscode.cmd &#039;code --wait --diff $LOCAL $REMOTE&#039;\ngit config --global merge.tool vscode\ngit config --global mergetool.vscode.cmd &#039;code --wait $MERGED&#039;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7edd\u5927\u90e8\u5206\u4eba\u7ecf\u5e38\u4f7f\u7528\u7684 Git \u547d\u4ee4\u53ea\u6709\u6781\u5c11\u7684\u4e00\u90e8\u5206\uff0c\u4e0d\u5e38\u4f7f\u7528\u7684\u547d\u4ee4\u5bb9\u6613\u9057\u5fd8\uff0c\u6545\u5236\u4f5c\u6b64\u901f\u67e5\u8868\u3002 \u4ed3\u5e93\u7ba1\u7406 git init: \u521d\u59cb\u5316\u4ed3\u5e93\u3002 git clone &lt;url&gt;: \u514b\u9686\u4ed3\u5e93\u3002 gi&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":304,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=271"}],"version-history":[{"count":3,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/271\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/posts\/271\/revisions\/303"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=\/wp\/v2\/media\/304"}],"wp:attachment":[{"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/muchen.fan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}