{"id":697,"date":"2024-07-02T11:30:46","date_gmt":"2024-07-02T03:30:46","guid":{"rendered":"https:\/\/www.madbull.site\/?p=697"},"modified":"2026-03-03T10:46:04","modified_gmt":"2026-03-03T02:46:04","slug":"git%e5%9f%ba%e7%a1%80%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.madbull.site\/?p=697","title":{"rendered":"git\u57fa\u7840\u4f7f\u7528"},"content":{"rendered":"\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u521d\u59cb\u5316\u3001\u63a8\u9001\u3001\u62c9\u53d6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u521d\u59cb\u5316\u4e00\u4e2a\u5e93\ngit init\n\n\u589e\u52a0\u5230\u8fdc\u7a0b\u5e93\ngit remote add origin &#91;\u5730\u5740git@xxx.xxx.xx\/xxx\/xxx.git]\n\n\u62c9\u53d6\u8fdc\u7aef\u7684\u5e93\ngit pull\n\n\u62c9\u53d6\u6307\u5b9a\u4ee3\u7801\ngit clone &#91;git\u5730\u5740]\n\n\u62c9\u53d6\u6307\u5b9atag\u7684\u4ee3\u7801\ngit clone --branch &#91;tags\u6807\u7b7e] &#91;git\u5730\u5740]\n\n\u6dfb\u52a0\u5b50\u6a21\u5757\ngit submodule add -b \u5206\u652f  &#91;\u5730\u5740git@xxx.xxx.xx\/xxx\/xxx.git]\n\n\u62c9\u53d6\u7684\u65f6\u5019\uff0c\u540c\u65f6\u62c9\u53d6\u5b50\u6a21\u5757\ngit clone --recursive &#91;\u5730\u5740git@xxx.xxx.xx\/xxx\/xxx.git]\n\n\u628a\u5f53\u524d\u5f00\u53d1\u5e93\u4f5c\u4e3a\u88f8\u4ed3\u5e93\uff0c\u7ed9\u5176\u4ed6\u5f00\u53d1\u73af\u5883\u66f4\u65b0\u3001\u63a8\u9001\u4f7f\u7528\u3002\ngit config --bool core.bare true\n\n\u628atag\u4e5f\u63a8\u9001\u5230\u8fdc\u7aef\ngit push origin &lt;tag\u540d><\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u6dfb\u52a0\u3001\u64a4\u9500\u3001\u63d0\u4ea4\u3001\u63a8\u52a8\u57fa\u672c\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53d8\u66f4\u6587\u4ef6\u6dfb\u52a0\u5230\u7f13\u5b58\u533a\ngit add xxx.c\n\n\u4ece\u7f13\u5b58\u533a\u64a4\u9500\ngit reset xxx.c\n\n\u63d0\u4ea4\u5230\u672c\u5730\u5e93\ngit commit -m \"description xxxxx\"\n\n\u63a8\u9001\u5230\u8fdc\u7aef\u5e93\ngit push<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u793a\u4f8b\uff1a\u5173\u8054\u8fdc\u7aef\u4ed3\u5e93<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git\u5173\u8054\u8fdc\u7a0b\u4ed3\u5e93\n1\u3001\u5728\u8fdc\u7aef\u5efa\u7acb\u4ed3\u5e93\uff0c\u518dgitlab\u670d\u52a1\u7ba1\u7406\u53f0\u4e0a\u64cd\u4f5c\n\n2\u3001\u5728\u672c\u5730\u76ee\u5f55\u4e0b\u521b\u5efa\u4ed3\u5e93\u5e76\u521d\u59cb\u5316\n\u5728xxx\u76ee\u5f55\u4e0b  \u6267\u884c git init\n\n3\u3001\u5173\u8054\u8fdc\u7aef\u4ed3\u5e93\ngit remote add origin &#91;\u5730\u5740git@xxx.xxx.xx\/xxx\/xxx.git]\n\n4\u3001\u672c\u5730\u7f16\u8f91\u4ee3\u7801\u540e\u63d0\u4ea4\u81f3\u8fdc\u7a0b\u5206\u652f\ngit push -u origin master\n\n5\u3001\u628a\u672c\u5730\u6253\u7684tag\u4e5f\u63d0\u4ea4\u5230\u8fdc\u7aef\ngit push origin --tags<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u5408\u5e76\u5206\u652f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u5c06\u5176\u4ed6\u5206\u652fYYYY\u5408\u5e76\u5230\u5f53\u524d\u5de5\u4f5c\u5206\u652f\u4e0b\ngit merge YYYY\n\n2\u3001\u5220\u9664\u672c\u5730\u5206\u652fYYYY\ngit branch -d YYYY\n\n3\u3001\u5220\u9664\u8fdc\u7aef\u5206\u652fYYYY\ngit push origin --delete YYYY\n\n4\u3001\u83b7\u53d6\u8fdc\u7aefYYYY\u5206\u652f\ngit pull origin YYYY\n&#91;\u5207\u6362\u5230YYYY\u5206\u652f]\ngit checkout YYYY\n<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u5206\u652f\u5bf9\u6bd4\u548c\u65e5\u5fd7\u5bf9\u6bd4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1. \u663e\u793a\u51fabranch1\u548cbranch2\u4e2d\u5dee\u5f02\u7684\u90e8\u5206\ngit diff branch1 branch2 --stat\n\n2. \u663e\u793a\u6307\u5b9a\u6587\u4ef6\u7684\u8be6\u7ec6\u5dee\u5f02\ngit diff branch1 branch2 \u5177\u4f53\u6587\u4ef6\u8def\u5f84\n\n3. \u663e\u793a\u51fa\u6240\u6709\u6709\u5dee\u5f02\u7684\u6587\u4ef6\u7684\u8be6\u7ec6\u5dee\u5f02\ngit diff branch1 branch2\n\n4. \u67e5\u770bbranch1\u5206\u652f\u6709\uff0c\u800cbranch2\u4e2d\u6ca1\u6709\u7684log\ngit log branch1 ^branch2\n\n5. \u67e5\u770bbranch2\u4e2d\u6bd4branch1\u4e2d\u591a\u63d0\u4ea4\u4e86\u54ea\u4e9b\u5185\u5bb9\ngit log branch1..branch2\n\u6ce8\u610f\uff0c\u5217\u51fa\u6765\u7684\u662f\u4e24\u4e2a\u70b9\u540e\u8fb9\u591a\u63d0\u4ea4\u7684\u5185\u5bb9\u3002\n\n6. \u4e0d\u77e5\u9053\u8c01\u63d0\u4ea4\u7684\u591a\u8c01\u63d0\u4ea4\u7684\u5c11\uff0c\u5355\u7eaf\u60f3\u77e5\u9053\u6709\u4ec0\u4e48\u4e0d\u4e00\u6837\ngit log branch1...branch2\n\n7. \u5728\u4e0a\u8ff0\u60c5\u51b5\u4e0b\uff0c\u5728\u663e\u793a\u51fa\u6ca1\u4e2a\u63d0\u4ea4\u662f\u5728\u54ea\u4e2a\u5206\u652f\u4e0a\ngit log --lefg-right branch1...branch2\n\n8. \u5206\u652f\u91cd\u547d\u540d\ngit branch -m feature-branch feature-update<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-layout-flow wp-block-group-is-layout-flow\">\n<p><strong>\u8bbe\u7f6e\u5ffd\u7565\u7684\u6587\u4ef6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.gitignore\n\u7a7a\u683c\u4e0d\u5339\u914d\u4efb\u610f\u6587\u4ef6\uff0c\u53ef\u4f5c\u4e3a\u5206\u9694\u7b26\uff0c\u53ef\u7528\u53cd\u659c\u6760\u8f6c\u4e49\n\u5f00\u5934\u7684\u6587\u4ef6\u6807\u8bc6\u6ce8\u91ca\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cd\u659c\u6760\u8fdb\u884c\u8f6c\u4e49\n! \u5f00\u5934\u7684\u6a21\u5f0f\u6807\u8bc6\u5426\u5b9a\uff0c\u8be5\u6587\u4ef6\u5c06\u4f1a\u518d\u6b21\u88ab\u5305\u542b\uff0c\u5982\u679c\u6392\u9664\u4e86\u8be5\u6587\u4ef6\u7684\u7236\u7ea7\u76ee\u5f55\uff0c\u5219\u4f7f\u7528 ! \u4e5f\u4e0d\u4f1a\u518d\u6b21\u88ab\u5305\u542b\u3002\u53ef\u4ee5\u4f7f\u7528\u53cd\u659c\u6760\u8fdb\u884c\u8f6c\u4e49\n\/ \u7ed3\u675f\u7684\u6a21\u5f0f\u53ea\u5339\u914d\u6587\u4ef6\u5939\u4ee5\u53ca\u5728\u8be5\u6587\u4ef6\u5939\u8def\u5f84\u4e0b\u7684\u5185\u5bb9\uff0c\u4f46\u662f\u4e0d\u5339\u914d\u8be5\u6587\u4ef6\n\/ \u5f00\u59cb\u7684\u6a21\u5f0f\u5339\u914d\u9879\u76ee\u8ddf\u76ee\u5f55\n\u5982\u679c\u4e00\u4e2a\u6a21\u5f0f\u4e0d\u5305\u542b\u659c\u6760\uff0c\u5219\u5b83\u5339\u914d\u76f8\u5bf9\u4e8e\u5f53\u524d .gitignore \u6587\u4ef6\u8def\u5f84\u7684\u5185\u5bb9\uff0c\u5982\u679c\u8be5\u6a21\u5f0f\u4e0d\u5728 .gitignore \u6587\u4ef6\u4e2d\uff0c\u5219\u76f8\u5bf9\u4e8e\u9879\u76ee\u6839\u76ee\u5f55\n** \u5339\u914d\u591a\u7ea7\u76ee\u5f55\uff0c\u53ef\u5728\u5f00\u59cb\uff0c\u4e2d\u95f4\uff0c\u7ed3\u675f\n? \u901a\u7528\u5339\u914d\u5355\u4e2a\u5b57\u7b26\n* \u901a\u7528\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\n&#91;] \u901a\u7528\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u5217\u8868\n\n.gitignore\u53ea\u80fd\u5ffd\u7565\u539f\u6765\u6ca1\u6709track\u7684\u6587\u4ef6\uff0c\u5982\u679c\u5df2\u7ecf\u7eb3\u5165\u4e86\u7248\u672c\u7ba1\u7406\u4e2d\uff0c\u53ea\u4fee\u6539.gitignore\u6587\u4ef6\u662f\u65e0\u6548\u7684\u3002\u9700\u8981\u505a\u4ee5\u4e0b\u5904\u7406\uff0c\u5220\u9664\u672c\u5730\u7f13\u5b58\u6539\u6210\u672atrack\u72b6\u6001\uff0c\u7136\u540e\u63d0\u4ea4\ngit rm -r --cached .\ngit add .gitignore\ngit commit -m 'update .gitignore'\n\u4e5f\u53ef\u4ee5\u5220\u9664\u5355\u4e2a\u6587\u4ef6\u7684\u8ddf\u8e2a\ngit rm --cached xxx.yy<\/code><\/pre>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>git\u57fa\u672c\u4f7f\u7528\uff0c\u521d\u59cb\u5316\u3001\u63a8\u9001\u3001\u62c9\u53d6\uff0c\u5206\u652f\uff0c\u5173\u8054\uff0c\u5206\u652f\u5bf9\u6bd4\u548c\u65e5\u5fd7\u5bf9\u6bd4\uff0c\u8bbe\u7f6e\u5ffd\u7565<\/p>\n","protected":false},"author":1,"featured_media":552,"comment_status":"open","ping_status":"open","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[166,154],"tags":[263,265,271,270,264,272,266,268,273,267,269],"class_list":["post-697","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","category-154","tag-git","tag-gitlab","tag-tag","tag-270","tag-264","tag-272","tag-266","tag-268","tag-273","tag-267","tag-269"],"_links":{"self":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=697"}],"version-history":[{"count":10,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions"}],"predecessor-version":[{"id":2476,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/697\/revisions\/2476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/media\/552"}],"wp:attachment":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}