{"id":57269,"date":"2023-10-17T16:10:53","date_gmt":"2023-10-17T08:10:53","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=57269"},"modified":"2023-10-17T16:10:54","modified_gmt":"2023-10-17T08:10:54","slug":"%e6%b5%85%e6%9e%90mac%e4%b8%8a%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8git","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/57269.html","title":{"rendered":"\u6d45\u6790mac\u4e0a\u5982\u4f55\u4f7f\u7528git"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u200b\u672cGit\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u800cMac\u4e3agit\u63d0\u4f9b\u4e86\u53cb\u597d\u7684\u652f\u6301\u3002\u6587\u5c06\u6307\u5bfc\u60a8\u5728Mac\u4e0a\u6b63\u786e\u5730\u4f7f\u7528git\uff1a1.\u5b89\u88c5\u548c\u914d\u7f6egit\uff1b2.\u521b\u5efa\u548c\u7ba1\u7406\u4ed3\u5e93\uff1b3.\u5e38\u89c1\u7684git\u547d\u4ee4\u548c\u64cd\u4f5c\uff1b4.\u89e3\u51b3git\u4e2d\u7684\u5e38\u89c1\u95ee\u9898\uff1b5.\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u534f\u4f5c\u7684\u6280\u5de7\u3002\u9996\u5148\uff0c\u6211\u4eec\u5c06\u4ece\u5982\u4f55\u5728Mac\u4e0a\u5b89\u88c5\u548c\u914d\u7f6egit\u5f00\u59cb\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u5b89\u88c5\u548c\u914d\u7f6egit<\/h2>\n\n\n\n<p>\u5728Mac\u4e0a\uff0c\u63a8\u8350\u4f7f\u7528Homebrew\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5git\u3002\u9996\u5148\u6253\u5f00\u7ec8\u7aef\u5e76\u8f93\u5165\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install git<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fdb\u884c\u57fa\u7840\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git config --global user.name \"\u60a8\u7684\u7528\u6237\u540d\" git config --global user.email \"\u60a8\u7684\u90ae\u7bb1\u5730\u5740\"<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u521b\u5efa\u548c\u7ba1\u7406\u4ed3\u5e93<\/h2>\n\n\n\n<p>\u8981\u5f00\u59cb\u4f7f\u7528git\uff0c\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4ed3\u5e93\u6216\u514b\u9686\u73b0\u6709\u7684\u4ed3\u5e93\u3002\u521b\u5efa\u65b0\u4ed3\u5e93\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir my_project cd my_project git init<\/code><\/pre>\n\n\n\n<p>\u6216\u514b\u9686\u73b0\u6709\u7684\u4ed3\u5e93\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone &#091;url]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u5e38\u89c1\u7684git\u547d\u4ee4\u548c\u64cd\u4f5c<\/h2>\n\n\n\n<p>\u5728Mac\u4e0a\u4f7f\u7528git\u65f6\uff0c\u4f1a\u9891\u7e41\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n\n\n\n<ul>\n<li><strong>git status<\/strong>\uff1a\u67e5\u770b\u4ed3\u5e93\u72b6\u6001\u3002<\/li>\n\n\n\n<li><strong>git add [file]<\/strong>\uff1a\u8ddf\u8e2a\u65b0\u6587\u4ef6\u6216\u66f4\u6539\u3002<\/li>\n\n\n\n<li><strong>git commit -m &#8220;commit message&#8221;<\/strong>\uff1a\u63d0\u4ea4\u66f4\u6539\u3002<\/li>\n\n\n\n<li><strong>git pull<\/strong>\uff1a\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u62c9\u53d6\u6700\u65b0\u66f4\u6539\u3002<\/li>\n\n\n\n<li><strong>git push<\/strong>\uff1a\u5c06\u66f4\u6539\u63a8\u9001\u5230\u8fdc\u7a0b\u4ed3\u5e93\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u89e3\u51b3git\u4e2d\u7684\u5e38\u89c1\u95ee\u9898<\/h2>\n\n\n\n<p>Git\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u4f46\u6709\u65f6\u53ef\u80fd\u4f1a\u9047\u5230\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u5982\u679c\u53d1\u73b0\u63d0\u4ea4\u4e86\u4e00\u4e2a\u9519\u8bef\u7684\u66f4\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>git revert<\/strong>\u6765\u64a4\u56de\u3002\u6216\u8005\uff0c\u5982\u679c\u9700\u8981\u4fee\u6539\u4e0a\u4e00\u6b21\u7684\u63d0\u4ea4\u6d88\u606f\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>git commit &#8211;amend<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u534f\u4f5c\u7684\u6280\u5de7<\/h2>\n\n\n\n<p>\u5728\u56e2\u961f\u534f\u4f5c\u65f6\uff0c\u7406\u89e3\u5982\u4f55\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u534f\u4f5c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u9996\u5148\uff0c\u9700\u8981\u5c06\u8fdc\u7a0b\u4ed3\u5e93\u6dfb\u52a0\u4e3a<strong>origin<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote add origin &#091;url]<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>git fetch<\/strong>\u548c<strong>git merge<\/strong>\u547d\u4ee4\u6765\u540c\u6b65\u8fdc\u7a0b\u66f4\u6539\u3002\u4e3a\u4e86\u9632\u6b62\u4ee3\u7801\u51b2\u7a81\uff0c\u5efa\u8bae\u7ecf\u5e38\u4ece\u8fdc\u7a0b\u4ed3\u5e93\u62c9\u53d6\u6700\u65b0\u66f4\u6539\u5e76\u5728\u672c\u5730\u8fdb\u884c\u5408\u5e76\u3002<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba<\/strong>:Git\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u800cMac\u4e3agit\u63d0\u4f9b\u4e86\u53cb\u597d\u7684\u652f\u6301\u3002\u901a\u8fc7\u9075\u5faa\u672c\u6587\u7684\u6307\u5bfc\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Mac\u4e0a\u5f00\u59cb\u4f7f\u7528git\uff0c\u5e76\u4e0e\u56e2\u961f\u9ad8\u6548\u5730\u534f\u4f5c\u3002\u8bb0\u4f4f\uff0c\u6700\u597d\u7684\u5b66\u4e60\u65b9\u6cd5\u662f\u5b9e\u8df5\uff0c\u6240\u4ee5\u8bf7\u7ecf\u5e38\u4f7f\u7528git\u6765\u7ba1\u7406\u60a8\u7684\u4ee3\u7801\u548c\u534f\u4f5c\u9879\u76ee\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1280\" height=\"850\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u4e0b\u8f7dgithub\u7684\u6587\u4ef6-2023-10-16T192915.228.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-57270\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u4e0b\u8f7dgithub\u7684\u6587\u4ef6-2023-10-16T192915.228.jpg 1280w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u4e0b\u8f7dgithub\u7684\u6587\u4ef6-2023-10-16T192915.228-768x510.jpg 768w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/figure>\n\n\n\n<p><strong>\u5e38\u89c1\u95ee\u7b54\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u4e3a\u4ec0\u4e48\u63a8\u8350\u5728Mac\u4e0a\u4f7f\u7528\u7ec8\u7aef\u8fdb\u884cGit\u64cd\u4f5c\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1aMac\u7684\u7ec8\u7aef\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u76f4\u63a5\u7684Unix-like\u73af\u5883\uff0c\u8fd9\u4f7f\u5f97\u5728Mac\u4e0a\u4f7f\u7528Git\u547d\u4ee4\u884c\u5de5\u5177\u53d8\u5f97\u66f4\u4e3a\u76f4\u63a5\u548c\u9ad8\u6548\u3002\u4f7f\u7528\u7ec8\u7aef\u53ef\u4ee5\u8fdb\u884c\u66f4\u4e3a\u590d\u6742\u7684\u64cd\u4f5c\u3001\u81ea\u5b9a\u4e49Git\u884c\u4e3a\u548c\u6574\u5408\u5176\u4ed6\u5de5\u5177\uff0c\u540c\u65f6\u8fd8\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u7406\u89e3Git\u7684\u5de5\u4f5c\u539f\u7406\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u5982\u679c\u6211\u4e4b\u524d\u5728Windows\u4e0a\u4f7f\u7528\u4e86GUI\u7684Git\u5de5\u5177\uff0c\u8f6c\u5230Mac\u540e\u8fd8\u9700\u8981\u91cd\u65b0\u5b66\u4e60\u5417\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1a\u867d\u7136\u57fa\u672c\u7684Git\u64cd\u4f5c\u5728\u5404\u5e73\u53f0\u4e0a\u90fd\u662f\u76f8\u4f3c\u7684\uff0c\u4f46\u5728Mac\u4e0a\u4f7f\u7528\u7ec8\u7aef\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u547d\u4ee4\u884c\u57fa\u7840\u3002\u5982\u679c\u4f60\u4e4b\u524d\u4f7f\u7528\u7684\u662fGUI\u5de5\u5177\uff0c\u90a3\u4e48\u5728Mac\u4e0a\u4f7f\u7528\u7ec8\u7aef\u8fdb\u884cGit\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u4e00\u6bb5\u65f6\u95f4\u7684\u9002\u5e94\u3002\u4e0d\u8fc7\uff0c\u638c\u63e1\u547d\u4ee4\u884c\u64cd\u4f5c\u4f1a\u4e3a\u4f60\u5e26\u6765\u66f4\u5927\u7684\u7075\u6d3b\u6027\u548c\u6df1\u5165\u7684Git\u7406\u89e3\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li>\u95ee\uff1a\u6211\u5728Mac\u4e0a\u5b89\u88c5Git\u65f6\u9047\u5230\u4e86\u95ee\u9898\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f<\/li>\n\n\n\n<li>\u7b54\uff1a\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684MacOS\u7cfb\u7edf\u662f\u6700\u65b0\u7684\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Homebrew\u8fd9\u6837\u7684\u5305\u7ba1\u7406\u5de5\u5177\u6765\u5b89\u88c5Git\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u89e3\u51b3\u8bb8\u591a\u5e38\u89c1\u7684\u4f9d\u8d56\u95ee\u9898\u3002\u5982\u679c\u95ee\u9898\u4ecd\u7136\u5b58\u5728\uff0c\u5c1d\u8bd5\u67e5\u627e\u5177\u4f53\u7684\u9519\u8bef\u6d88\u606f\u6216\u8bbf\u95eeGit\u5b98\u65b9\u6587\u6863\u5bfb\u6c42\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u200b\u672cGit\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u800cMac\u4e3agit\u63d0\u4f9b\u4e86\u53cb\u597d\u7684\u652f\u6301\u3002\u6587\u5c06\u6307\u5bfc\u60a8\u5728Mac\u4e0a\u6b63\u786e\u5730\u4f7f\u7528git [&hellip;]","protected":false},"author":7,"featured_media":57271,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[1987,1163],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/57269"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=57269"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/57269\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/57271"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=57269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=57269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=57269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}