{"id":34,"date":"2023-06-03T10:18:14","date_gmt":"2023-06-03T02:18:14","guid":{"rendered":"http:\/\/niuguodong.com\/?p=34"},"modified":"2025-12-19T18:42:37","modified_gmt":"2025-12-19T10:42:37","slug":"git%e5%88%86%e6%94%af","status":"publish","type":"post","link":"https:\/\/niuguodong.com\/index.php\/2023\/06\/03\/git%e5%88%86%e6%94%af\/","title":{"rendered":"Git\u5206\u652f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u5206\u652f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5217\u51fa\u6240\u6709\u5206\u652f\ngit branch\n\n# \u5217\u51fa\u6240\u6709\u5206\u652f\u4ee5\u53ca\u6700\u65b0\u7684\u63d0\u4ea4\ngit branch -v\n\n# \u67e5\u770b\u5206\u652f\u5173\u8054\u5173\u7cfb\uff08\u663e\u793a\u4e0a\u6e38\u8ddf\u8e2a\u4fe1\u606f\uff09\ngit branch -vv\n\n# \u67e5\u770b\u8fdc\u7a0b\u5206\u652f\ngit ls-remote --heads<\/code><\/pre>\n\n\n\n<p>-v\u4e0e-vv<strong>\u8f93\u51fa\u5bf9\u6bd4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># git branch -v\n* main    a1b2c3d Update README.md\n  dev     e5f6g7h Fix login bug\n\n# git branch -vv\n* main    a1b2c3d &#91;origin\/main] Update README.md\n  dev     e5f6g7h &#91;origin\/dev: ahead 1] Fix login bug<\/code><\/pre>\n\n\n\n<p><strong>\u5173\u952e\u5dee\u5f02\u89e3\u6790<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0a\u6e38\u5206\u652f\u4fe1\u606f<\/strong>\uff1a<\/li>\n\n\n\n<li><code>-vv<\/code> \u4f1a\u663e\u793a\u5206\u652f\u662f\u5426\u914d\u7f6e\u4e86\u4e0a\u6e38\uff08\u5982 <code>origin\/main<\/code>\uff09\uff0c\u8fd9\u662f <code>git pull\/push<\/code> \u65e0\u9700\u6307\u5b9a\u8fdc\u7a0b\u548c\u5206\u652f\u7684\u5173\u952e\u524d\u63d0\u3002<\/li>\n\n\n\n<li>\u82e5\u5206\u652f\u672a\u8bbe\u7f6e\u4e0a\u6e38\uff0c<code>-vv<\/code> \u4f1a\u663e\u793a <code>[origin\/main: behind 3]<\/code> \u6216\u7c7b\u4f3c\u63d0\u793a\uff0c\u8868\u660e\u672c\u5730\u5206\u652f\u843d\u540e\u4e8e\u8fdc\u7a0b\u5206\u652f\u3002<\/li>\n\n\n\n<li><strong>\u5206\u652f\u72b6\u6001\u6807\u8bc6<\/strong>\uff1a<\/li>\n\n\n\n<li><code>ahead N<\/code>\uff1a\u672c\u5730\u5206\u652f\u6bd4\u8fdc\u7a0b\u5206\u652f\u591a\u51fa N \u4e2a\u63d0\u4ea4\uff08\u9700\u63a8\u9001\uff09\u3002<\/li>\n\n\n\n<li><code>behind M<\/code>\uff1a\u672c\u5730\u5206\u652f\u6bd4\u8fdc\u7a0b\u5206\u652f\u5c11 M \u4e2a\u63d0\u4ea4\uff08\u9700\u62c9\u53d6\u66f4\u65b0\uff09\u3002<\/li>\n\n\n\n<li><code>diverged<\/code>\uff1a\u672c\u5730\u548c\u8fdc\u7a0b\u5206\u652f\u6709\u5171\u540c\u7956\u5148\u4f46\u5b58\u5728\u5206\u6b67\uff08\u9700\u5408\u5e76\u6216\u53d8\u57fa\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u65b0\u5efa\u5206\u652f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u57fa\u4e8emain\u5206\u652f\uff0c\u65b0\u5efa\u4e00\u4e2afeature\u5206\u652f\ngit checkout -b feature main\n\ngit switch -c feature main<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5220\u9664\u5206\u652f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5220\u9664\u5206\u652f\ngit branch -d bugfix\n\n# \u5f3a\u5236\u5220\u9664\u5206\u652f\ngit branch -D bugfix\n\n# \u5220\u9664\u8fdc\u7a0b\u5206\u652f\ngit push origin --delete bugfix<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bbe\u7f6e\u4e0a\u6e38\u5206\u652f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8bbe\u7f6e\u5f53\u524d\u5206\u652f\u7684\u4e0a\u6e38\u5206\u652f\u4e3aorigin\/dev\ngit branch -u origin\/dev\n\n# \u5220\u9664\u8ffd\u8e2a\u5173\u7cfb\ngit branch --unset-upstream feature-branch\n\n# \u65b0\u5efa\u5206\u652f\u540e\u9996\u6b21\u63a8\u9001\u540c\u65f6\u8bbe\u7f6e\u8ffd\u8e2a\ngit push -u origin feature-branch\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5207\u6362\u5206\u652f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5207\u6362\u5206\u652f\uff0c\u4ee5\u4e0b\u4e24\u4e2a\u547d\u4ee4\u7b49\u4ef7\ngit checkout dev\ngit switch dev\n\n# \u5207\u6362\u5230\u4e0a\u4e00\u4e2a\u5206\u652f\ngit checkout -\ngit switch -\n\n# \u5f3a\u5236\u5207\u6362\ngit checkout -f dev\ngit switch -f dev\n# \u614e\u7528\u4ee5\u4e0a2\u4e2a\u547d\u4ee4\uff0c\u5f3a\u5236\u5207\u6362\u4f1a\u4e22\u5f03\u5f53\u524d\u5de5\u4f5c\u533a\u672a\u63d0\u4ea4\u7684\u66f4\u6539<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u67e5\u770b\u5206\u652f -v\u4e0e-vv\u8f93\u51fa\u5bf9\u6bd4 \u5173\u952e\u5dee\u5f02\u89e3\u6790 \u65b0\u5efa\u5206\u652f \u5220\u9664\u5206\u652f \u8bbe\u7f6e\u4e0a\u6e38\u5206\u652f \u5207\u6362\u5206\u652f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,5],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-git","category-5"],"_links":{"self":[{"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}