{"id":439,"date":"2023-06-03T13:38:56","date_gmt":"2023-06-03T05:38:56","guid":{"rendered":"https:\/\/niuguodong.com\/?p=439"},"modified":"2025-12-06T12:25:20","modified_gmt":"2025-12-06T04:25:20","slug":"git%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/niuguodong.com\/index.php\/2023\/06\/03\/git%e5%90%8c%e6%ad%a5\/","title":{"rendered":"Git\u540c\u6b65"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u63a8\u9001<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u63a8\u9001\ngit push origin main # \u5411origin\u8fd9\u4e2a\u8fdc\u7a0b\u4ed3\u5e93\u63a8\u9001main\u5206\u652f\n\n# \u63a8\u9001main\u5206\u652f\u5230origin\u7684main\u5206\u652f\ngit push origin main:main\n\n\u8bbe\u7f6e\u672c\u5730\u5206\u652f\u4e0ecodeup\u8fdc\u7a0b\u5206\u652f\u7684\u8ddf\u8e2a\u5173\u7cfb\ngit branch --set-upstream-to=codeup\/main main\n\n# \u540e\u7eed\u76f4\u63a5\u4f7f\u7528\ngit push codeup<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6743\u9650\u4e0e\u51b2\u7a81<\/strong>\uff1a\u9700\u786e\u4fdd\u6709\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5199\u5165\u6743\u9650\uff0c\u4e14\u672c\u5730\u63d0\u4ea4\u4e0d\u4e0e\u8fdc\u7a0b\u5206\u652f\u51b2\u7a81\u3002<\/li>\n\n\n\n<li><strong>\u5f3a\u5236\u63a8\u9001<\/strong>\uff1a\u614e\u7528 <code>git push -f<\/code>\uff08\u5f3a\u5236\u63a8\u9001\uff09\uff0c\u53ef\u80fd\u5bfc\u81f4\u4ed6\u4eba\u4ee3\u7801\u88ab\u8986\u76d6\uff0c\u4ec5\u5728\u660e\u786e\u540e\u679c\u65f6\u4f7f\u7528\u3002<\/li>\n\n\n\n<li><strong>\u5206\u652f\u7ba1\u7406<\/strong>\uff1a\u9996\u6b21\u63a8\u9001\u9700\u6307\u5b9a\u8fdc\u7a0b\u5206\u652f\uff08\u5982 <code>git push -u origin main<\/code>\uff09\uff0c\u540e\u7eed\u53ef\u76f4\u63a5 <code>git push<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u7a7a\u63a8\u9001<\/strong>\uff1a\u82e5\u672c\u5730\u65e0\u65b0\u63d0\u4ea4\uff0c\u63a8\u9001\u4e0d\u4f1a\u8986\u76d6\u8fdc\u7a0b\u4ee3\u7801\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u62c9\u53d6<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e0b\u8f7d\u6700\u65b0\u53d8\u66f4\uff08\u5982\u5206\u652f\u3001\u6807\u7b7e\u3001\u63d0\u4ea4\u7b49\uff09\uff0c\u4f46\u4e0d\u5408\u5e76\u5230\u5f53\u524d\u5de5\u4f5c\u5206\u652f\ngit fetch &#91;remote] &#91;branch]<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/p>\n\n\n\n<p>git fetch\u7684\u9ed8\u8ba4\u884c\u4e3a\u662f\u66f4\u65b0\u6240\u6709\u8fdc\u7a0b\u5206\u652f\u7684\u672c\u5730\u526f\u672c\uff0c\u4f46\u5e76\u4e0d\u4f1a\u81ea\u52a8\u5408\u5e76\uff0c\u9700\u8981\u624b\u52a8\u6267\u884cgit merge\u6216git rebase\u6765\u5408\u5e76\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4ece\u8fdc\u7a0b\u4ed3\u5e93\u4e0b\u8f7d\u6700\u65b0\u53d8\u66f4\uff0c\u5e76\u5408\u5e76\u5230\u5f53\u524d\u5206\u652f\ngit pull &#91;remote] &#91;branch]\n# \u7b49\u4ef7\u4e8egit fetch + git merge\uff08\u9ed8\u8ba4\uff09<\/code><\/pre>\n\n\n\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5408\u5e76\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u672c\u5730\u4fee\u6539\u4e0e\u8fdc\u7a0b\u63d0\u4ea4\u51b2\u7a81\uff0c\u9700\u624b\u52a8\u89e3\u51b3\u51b2\u7a81\u540e\u6267\u884c <code>git add<\/code> \u548c <code>git commit<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u5408\u5e76\u7b56\u7565<\/strong>\uff1a\u53ef\u901a\u8fc7 <code>--rebase<\/code> \u53c2\u6570\u6539\u4e3a\u53d8\u57fa\uff08<code>git pull --rebase<\/code>\uff09\uff0c\u907f\u514d\u5197\u4f59\u5408\u5e76\u63d0\u4ea4\u3002<\/li>\n\n\n\n<li><strong>\u98ce\u9669<\/strong>\uff1a\u76f4\u63a5\u62c9\u53d6\u53ef\u80fd\u8986\u76d6\u672c\u5730\u672a\u63d0\u4ea4\u7684\u66f4\u6539\uff0c\u5efa\u8bae\u5148 <code>git stash<\/code> \u4fdd\u5b58\u4e34\u65f6\u4fee\u6539\u3002<\/li>\n\n\n\n<li><strong>\u5206\u652f\u5bf9\u5e94<\/strong>\uff1a\u786e\u4fdd\u672c\u5730\u5206\u652f\u4e0e\u8fdc\u7a0b\u5206\u652f\u6b63\u786e\u5173\u8054\uff08\u5982 <code>git branch -u origin\/main<\/code>\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5173\u952e\u5bf9\u6bd4\u4e0e\u6700\u4f73\u5b9e\u8df5<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/niuguodong.com\/wp-content\/uploads\/2023\/06\/image.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"669\" height=\"215\" data-original=\"https:\/\/niuguodong.com\/wp-content\/uploads\/2023\/06\/image.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-445\"  sizes=\"auto, (max-width: 669px) 100vw, 669px\" \/><\/div><\/figure>\n\n\n\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b9a\u671f\u540c\u6b65<\/strong>\uff1a\u5148\u7528 <code>git fetch<\/code> \u67e5\u770b\u8fdc\u7a0b\u53d8\u66f4\uff0c\u518d\u51b3\u5b9a\u662f\u5426\u5408\u5e76\u3002<\/li>\n\n\n\n<li><strong>\u907f\u514d\u76f4\u63a5 Pull<\/strong>\uff1a\u5728\u91cd\u8981\u64cd\u4f5c\u524d\uff08\u5982\u5408\u5e76\uff09\uff0c\u5148 <code>git stash<\/code> \u4fdd\u5b58\u672c\u5730\u672a\u63d0\u4ea4\u7684\u4fee\u6539\u3002<\/li>\n\n\n\n<li><strong>\u5206\u652f\u7b56\u7565<\/strong>\uff1a<\/li>\n\n\n\n<li>\u5f00\u53d1\u5206\u652f\uff08\u5982 <code>dev<\/code>\uff09\u9891\u7e41 <code>pull<\/code>\uff0c\u4e3b\u5206\u652f\uff08\u5982 <code>main<\/code>\uff09\u8c28\u614e <code>push<\/code>\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>git pull --rebase<\/code> \u4fdd\u6301\u63d0\u4ea4\u5386\u53f2\u7ebf\u6027\u3002<\/li>\n\n\n\n<li><strong>\u51b2\u7a81\u5904\u7406<\/strong>\uff1a<\/li>\n\n\n\n<li>\u51b2\u7a81\u65f6\u624b\u52a8\u7f16\u8f91\u6587\u4ef6\uff0c\u6807\u8bb0\u5df2\u89e3\u51b3\uff08<code>git add<\/code>\uff09\uff0c\u518d\u63d0\u4ea4\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528 <code>git merge --abort<\/code> \u6216 <code>git rebase --abort<\/code> \u7ec8\u6b62\u672a\u5b8c\u6210\u7684\u5408\u5e76\/\u53d8\u57fa\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u5e38\u89c1\u95ee\u9898<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Q<\/strong>: <code>git pull<\/code> \u63d0\u793a \"Already up to date\" \u4f46\u5b9e\u9645\u6709\u66f4\u65b0\uff1f<\/li>\n<\/ul>\n\n\n\n<p><strong>A<\/strong>: \u672c\u5730\u5206\u652f\u53ef\u80fd\u672a\u8ddf\u8e2a\u8fdc\u7a0b\u5206\u652f\uff0c\u6267\u884c <code>git branch -vv<\/code> \u68c0\u67e5\u5173\u8054\u5173\u7cfb\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Q<\/strong>: \u5982\u4f55\u64a4\u9500\u9519\u8bef\u7684 <code>git pull<\/code>\uff1f<\/li>\n<\/ul>\n\n\n\n<p><strong>A<\/strong>: \u4f7f\u7528 <code>git reflog<\/code> \u67e5\u627e\u4e4b\u524d\u7684\u63d0\u4ea4\uff0c\u518d\u901a\u8fc7 <code>git reset --hard [commit]<\/code> \u56de\u9000\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Q<\/strong>: \u63a8\u9001\u65f6\u63d0\u793a \"non-fast-forward\" \u9519\u8bef\uff1f<\/li>\n<\/ul>\n\n\n\n<p><strong>A<\/strong>: \u8fdc\u7a0b\u5206\u652f\u6709\u65b0\u63d0\u4ea4\uff0c\u9700\u5148 <code>git pull<\/code> \u5408\u5e76\u540e\u518d\u63a8\u9001\uff0c\u6216\u4f7f\u7528 <code>git push -f<\/code>\uff08\u8c28\u614e\uff09\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a8\u9001 \u6ce8\u610f\u4e8b\u9879\uff1a \u62c9\u53d6 \u6ce8\u610f\u4e8b\u9879\uff1a git fetch\u7684\u9ed8\u8ba4\u884c\u4e3a\u662f\u66f4\u65b0\u6240\u6709\u8fdc\u7a0b\u5206\u652f\u7684\u672c\u5730\u526f\u672c\uff0c\u4f46\u5e76\u4e0d\u4f1a\u81ea\u52a8\u5408\u5e76 [&hellip;]<\/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-439","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\/439","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=439"}],"version-history":[{"count":0,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/posts\/439\/revisions"}],"wp:attachment":[{"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/media?parent=439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/categories?post=439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/niuguodong.com\/index.php\/wp-json\/wp\/v2\/tags?post=439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}