{"id":543,"date":"2024-07-24T17:28:00","date_gmt":"2024-07-24T09:28:00","guid":{"rendered":"https:\/\/blogqian.com\/?p=543"},"modified":"2025-06-25T09:10:44","modified_gmt":"2025-06-25T01:10:44","slug":"git-%e5%91%bd%e4%bb%a4%e8%a1%8c%e6%95%b4%e7%90%86","status":"publish","type":"post","link":"https:\/\/blogqian.com\/index.php\/2024\/07\/24\/git-%e5%91%bd%e4%bb%a4%e8%a1%8c%e6%95%b4%e7%90%86\/","title":{"rendered":"Git \u547d\u4ee4\u884c\u6574\u7406"},"content":{"rendered":"\n<p>\u5199\u4e00\u4e2a\u653e\u7740\u81ea\u5df1\u770b\u4e0b\uff0c\u7b28\u4eba\u603b\u662f\u5fd8\u8bb0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b89\u88c5<\/h2>\n\n\n\n<p><a href=\"https:\/\/git-scm.com\/\" data-type=\"link\" data-id=\"https:\/\/git-scm.com\/\">\u70b9\u8fd9\u91cc\u8fdb\u5165Git\u5b98\u7f51<\/a>\u8fdb\u884c\u5b89\u88c5\uff0c\u4e4b\u540e\u7528\u4e0b\u9762\u547d\u4ee4\u884c\u67e5\u770b\u7248\u672c\u53f7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git --version<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u914d\u7f6e\u7528\u6237\u540d<\/h2>\n\n\n\n<p>\u8fd9\u4e2a\u662f\u5f88\u591a\u6559\u7a0b\u5ffd\u7565\u7684\uff0c\u4e00\u822c\u6765\u8bf4\u4f60\u5230\u4e00\u4e2a\u65b0\u73af\u5883\uff0c\u6bd4\u5982\u4f60\u5bfc\u5e08\u7ed9\u4f60\u5f00\u4e86\u4e2a\u65b0\u7684\u53f7\uff0c\u6216\u8005\u8bf4\u4f60\u65b0\u5b89\u88c5\u4e86Git\uff0c\u90fd\u9700\u8981\u914d\u7f6e\u8fd9\u4e2a\u540d\u79f0\u548c\u90ae\u7bb1\u53f7\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --global user.name \"Alice\"\ngit config --global user.email \"alice@example.com\"<\/code><\/pre>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u7528list\u67e5\u770b\u6240\u6709\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --list<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\u4e0d\u540c\u7684\u53c2\u6570\u6709\u4e0d\u540c\u7684\u6548\u679c\uff0c\u4f46\u662f\u4e00\u822c\u90fd\u662f\u7528global\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --system --list   # \u7cfb\u7edf\u7ea7\uff08\u9700\u7ba1\u7406\u5458\u6743\u9650\uff09\ngit config --global --list   # \u5f53\u524d\u7528\u6237\u5168\u5c40\ngit config --local --list    # \u5f53\u524d\u9879\u76ee\u4ed3\u5e93\uff08\u9ed8\u8ba4\uff09<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u521b\u5efa\u4f60\u7684\u9879\u76ee<\/h2>\n\n\n\n<p>\u4e00\u822c\u6765\u8bf4\u4e24\u79cd<\/p>\n\n\n\n<p>\u4e00\u79cd\u662f\u4f60\u81ea\u5df1\u4ece\u96f6\u521b\u5efa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir testrepo\ncd testrepo\ngit init<\/code><\/pre>\n\n\n\n<p>\u53e6\u5916\u4e00\u79cd\u662f\u4f60\u7528\u522b\u4eba\u7684repo<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/test\/test.git<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u67e5\u770b\u9879\u76ee\u57fa\u672c\u4fe1\u606f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>git status #\u67e5\u770b\u4fe1\u606f\ngit log #\u67e5\u770b\u5386\u53f2\u8bb0\u5f55\ngit log --oneline #\u67e5\u770b\u7b80\u7565\u4fe1\u606f\ngit log --stat #\u663e\u793a\u6bcf\u6b21\u63d0\u4ea4\u4fee\u6539\u7684\u6587\u4ef6\u53ca\u884c\u6570\u7edf\u8ba1\ngit log --graph #\u4ee5 ASCII \u56fe\u663e\u793a\u5206\u652f\u3001\u5408\u5e76\u5386\u53f2\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u63d0\u4ea4<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 \u6dfb\u52a0\u5230Staging Area<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git add main.cpp        # \u6dfb\u52a0\u4e00\u4e2a\u6587\u4ef6\ngit add .               # \u6dfb\u52a0\u6240\u6709\u5df2\u4fee\u6539\u6587\u4ef6<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 \u6dfb\u52a0\u5230\u672c\u5730\u4ed3\u5e93<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git commit -m \"\u4fee\u590d\u767b\u5f55\u6a21\u5757\u7684\u5185\u5b58\u6cc4\u6f0f\"<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3 \u6dfb\u52a0\u5230\u8fdc\u7a0b\u4ed3\u5e93<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git push -u origin main #\u7b2c\u4e00\u6b21 -u \u7528\u4e8e\u5173\u8054\u8fdc\u7a0b\u548c\u672c\u5730\ngit push origin main #\u4ee5\u540e\u7684\u63d0\u4ea4\u7528\u8fd9\u4e2a\n#git\u4f1a\u9ed8\u8ba4push\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\u8fdc\u7a0b\u540d\u5b57 \u7b2c\u4e8c\u4e2a\u4e3amain<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5206\u652f\u7ba1\u7406<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u521b\u5efa\/\u5220\u9664\u5206\u652f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git branch dev\ngit branch -d dev #\u5220\u9664\u672c\u5730\u5206\u652f\ngit branch -D dev #\u5f3a\u5236\u5220\u9664\ngit push origin --delete dev #\u5220\u9664\u8fdc\u7a0b\u5206\u652f<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5207\u6362\u5206\u652f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout dev\ngit checkout -b dev #\u8fd9\u662f\u5148\u521b\u5efa\u518d\u5207\u6362\u5206\u652f<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u67e5\u770b\u4fe1\u606f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git branch          # \u67e5\u770b\u672c\u5730\u6240\u6709\u5206\u652f\ngit branch -a       # \u67e5\u770b\u672c\u5730 + \u8fdc\u7a0b\u5206\u652f\ngit branch -vv      # \u67e5\u770b\u5206\u652f + \u8ddf\u8e2a\u4fe1\u606f<\/code><\/pre>\n\n\n\n<p>\u8fdc\u7aef\u90a3\u4e2a\u5206\u652f\u53eb\u505a\u4e0a\u6e38\uff0c\u4f60\u672c\u5730\u7684\u53eb\u505a\u4e0b\u6e38\uff0c\u8ddf\u8e2a\u5c31\u662f\u8ba9\u672c\u5730\u7684\u4e0b\u6e38\u548c\u8fdc\u7aef\u7684\u4e0a\u6e38\u5efa\u7acb\u8054\u7cfb\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u62c9\u53d6\u8fdc\u7aef\u5206\u652f<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git fetch origin \ngit checkout -b dev origin\/dev<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u7684\u7b2c\u4e8c\u884c\u5e72\u4e86\u4e24\u4e2a\u4e8b\u60c5\uff0c\u4e00\u4e2a\u662f\u4ee5\u8fdc\u7aefdev\u4e3a\u84dd\u672c\u5efa\u7acb\u4e00\u4e2a\u672c\u5730\u7684dev\u5206\u652f\uff0c\u5e76\u5efa\u7acb\u4e8c\u8005\u7684\u8ddf\u8e2a\u5173\u7cfb\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git pull\n#\u8fd9\u4e2a\u7b49\u4e8e\u662f\u5e72\u4e86\u4e24\u4e2a\u4e0d\u540c\u7684\u4e8b\u60c5\uff0c\u9996\u5148\u628a\u8fdc\u7aefmain\u5206\u652ffetch\u8fc7\u6765\uff0c\u7136\u540e\u5e76\u5165\u81ea\u5df1\u672c\u5730\u7684\u5206\u652f\u91cc\u9762\u3002<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Merge\u64cd\u4f5c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout main\ngit merge dev<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Rebase vs Merge<\/h3>\n\n\n\n<p>Rebase\u662f\u5408\u5e76\u6210\u4e00\u6761\u7ebf<\/p>\n\n\n\n<p>Merge\u5219\u662f\u5e76\u5165\u8fdb\u6765\uff0c\u4e5f\u5c31\u662f\u4fdd\u6301\u4e00\u4e2a\u539f\u59cb\u7684\u5206\u652f\u7ed3\u6784\uff0c\u4f46\u662f\u5e76\u5165\u8fdb\u6765\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Git\u8001\u662f\u5fd8\uff0c\u653e\u4e2a\u81ea\u5df1\u770b\u4e0b<\/p>\n","protected":false},"author":1,"featured_media":546,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[32],"class_list":["post-543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","tag-git"],"_links":{"self":[{"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/posts\/543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/comments?post=543"}],"version-history":[{"count":4,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/posts\/543\/revisions"}],"predecessor-version":[{"id":551,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/posts\/543\/revisions\/551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/media\/546"}],"wp:attachment":[{"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/media?parent=543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/categories?post=543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogqian.com\/index.php\/wp-json\/wp\/v2\/tags?post=543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}