{"id":56906,"date":"2023-10-15T23:37:24","date_gmt":"2023-10-15T15:37:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=56906"},"modified":"2023-10-15T23:37:30","modified_gmt":"2023-10-15T15:37:30","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8git%e6%9d%a5%e6%9f%a5%e7%9c%8b%e6%94%b9%e5%8a%a8%e7%9a%84%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/56906.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528GIT\u6765\u67e5\u770b\u6539\u52a8\u7684\u6587\u4ef6"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u4f7f\u7528GIT\u6765\u67e5\u770b\u6539\u52a8\u7684\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a1. \u7406\u89e3Git\u7684\u5de5\u4f5c\u6d41\u7a0b\uff1b2. \u5229\u7528git diff \u67e5\u770b\u6539\u52a8\uff1b3. \u4f7f\u7528git log \u67e5\u770b\u63d0\u4ea4\u5386\u53f2\uff1b4. \u56de\u6eda\u548c\u64a4\u9500\u66f4\u6539\uff1b5. \u67e5\u770b\u5355\u6587\u4ef6\u7684\u5386\u53f2\uff1b6. \u56fe\u5f62\u5316\u5de5\u5177\u7684\u8f85\u52a9\u3002\u5728\u4f7f\u7528Git\u8fdb\u884c\u9879\u76ee\u7248\u672c\u63a7\u5236\u65f6\uff0c\u7406\u89e3\u5982\u4f55\u67e5\u770b\u6587\u4ef6\u7684\u6539\u52a8\uff0c\u662f\u4fdd\u969c\u4ee3\u7801\u8d28\u91cf\u548c\u56e2\u961f\u534f\u4f5c\u6d41\u7545\u7684\u5fc5\u8981\u6280\u80fd\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">1. \u7406\u89e3Git\u7684\u5de5\u4f5c\u6d41\u7a0b<\/h2>\n\n\n\n<p>\u8981\u6709\u6548\u67e5\u770b\u6587\u4ef6\u7684\u6539\u52a8\uff0c\u9996\u5148\u7406\u89e3Git\u7684\u5de5\u4f5c\u6d41\u7a0b\u662f\u5fc5\u8981\u7684\u3002\u5728Git\u4e2d\uff0c\u5de5\u4f5c\u533a(Working Directory)\u3001\u6682\u5b58\u533a(Staging Area)\u548c\u4ed3\u5e93(Repository)\u4e09\u8005\u4e4b\u95f4\u7684\u5173\u7cfb\u548c\u6570\u636e\u4ea4\u6362\uff0c\u6784\u6210\u4e86\u6838\u5fc3\u7684\u5de5\u4f5c\u6846\u67b6\u3002\u60a8\u6240\u505a\u7684\u4efb\u4f55\u6539\u52a8\u9996\u5148\u5f71\u54cd\u5230\u5de5\u4f5c\u533a\uff0c\u901a\u8fc7\u6682\u5b58\u64cd\u4f5c\u5c06\u6539\u52a8\u63a8\u5230\u6682\u5b58\u533a\uff0c\u6700\u7ec8\u901a\u8fc7\u63d0\u4ea4\u5c06\u5176\u6c38\u4e45\u5b58\u50a8\u5230\u4ed3\u5e93\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u5229\u7528git diff \u67e5\u770b\u6539\u52a8<\/h2>\n\n\n\n<p><strong>git diff<\/strong>\u662f\u4e00\u79cd\u975e\u5e38\u6709\u7528\u7684\u547d\u4ee4\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u60a8\u67e5\u770b\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u901a\u8fc7\u5404\u79cd\u53c2\u6570\u7684\u5de7\u5999\u4f7f\u7528\uff0c\u5982<strong>git diff<\/strong>\u3001<strong>git diff &#8211;staged<\/strong>\u3001<strong>git diff commit1 commit2<\/strong>\u7b49\uff0c\u60a8\u53ef\u4ee5\u89c2\u5bdf\u4e0d\u540c\u63d0\u4ea4\u72b6\u6001\u4e4b\u95f4\u4ee3\u7801\u7684\u53d8\u5316\u3001\u627e\u5230\u53ef\u80fd\u7684\u95ee\u9898\u5e76\u5728\u63d0\u4ea4\u524d\u786e\u4fdd\u4e00\u5207\u90fd\u662f\u60a8\u6240\u671f\u671b\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u4f7f\u7528git log \u67e5\u770b\u63d0\u4ea4\u5386\u53f2<\/h2>\n\n\n\n<p>\u63a2\u67e5\u9879\u76ee\u7684\u53d1\u5c55\u8f68\u8ff9\uff0c\u4f7f\u7528<strong>git log<\/strong>\u547d\u4ee4\u67e5\u770b\u63d0\u4ea4\u5386\u53f2\u81f3\u5173\u91cd\u8981\u3002\u800c<strong>git log<\/strong>\u7684\u7075\u6d3b\u6027\u4e5f\u8868\u73b0\u5728\u5b83\u7684\u591a\u79cd\u53c2\u6570\u4f7f\u7528\u4e0a\uff0c\u4f8b\u5982<strong>git log -p<\/strong>\u5c06\u663e\u793a\u6bcf\u6b21\u63d0\u4ea4\u7684\u5dee\u5f02\uff0c<strong>git log &#8211;stat<\/strong>\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u66f4\u591a\u53c2\u6570\u7684\u5408\u7406\u642d\u914d\uff0c\u8ba9\u60a8\u80fd\u5feb\u901f\u5b9a\u4f4d\u5230\u611f\u5174\u8da3\u7684\u4fe1\u606f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u56de\u6eda\u548c\u64a4\u9500\u66f4\u6539<\/h2>\n\n\n\n<p>\u7406\u89e3\u5982\u4f55\u56de\u6eda\u548c\u64a4\u9500\u66f4\u6539\uff0c\u80fd\u5e2e\u52a9\u60a8\u7ea0\u6b63\u53ef\u80fd\u7684\u9519\u8bef\u3002<strong>git checkout<\/strong>\u3001<strong>git reset<\/strong>\u548c<strong>git revert<\/strong>\u7b49\u547d\u4ee4\u5728\u4e0d\u540c\u7684\u573a\u666f\u548c\u5c42\u6b21\u4e0a\u63d0\u4f9b\u4e86\u66f4\u6539\u64a4\u9500\u7684\u53ef\u80fd\u6027\uff0c\u4e86\u89e3\u5b83\u4eec\u7684\u4f7f\u7528\u573a\u666f\u548c\u98ce\u9669\uff0c\u5c06\u4f7f\u60a8\u80fd\u591f\u66f4\u81ea\u5982\u5730\u5728\u7248\u672c\u5386\u53f2\u4e2d\u7a7f\u68ad\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u67e5\u770b\u5355\u6587\u4ef6\u7684\u5386\u53f2<\/h2>\n\n\n\n<p>\u5728\u591a\u4eba\u534f\u4f5c\u7684\u9879\u76ee\u4e2d\uff0c\u5355\u6587\u4ef6\u7684\u5386\u53f2\u67e5\u770b\u5c24\u4e3a\u91cd\u8981\u3002\u4f7f\u7528<strong>git blame<\/strong>\u547d\u4ee4\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u6587\u4ef6\u7684\u6bcf\u4e00\u884c\u662f\u7531\u8c01\u5728\u4ec0\u4e48\u65f6\u5019\u4fee\u6539\u7684\u3002\u8fd9\u6709\u52a9\u4e8e\u7406\u89e3\u4ee3\u7801\u7684\u6f14\u8fdb\u8fc7\u7a0b\u548c\u5feb\u901f\u627e\u5230\u4fee\u6539\u7684\u6765\u6e90\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. \u56fe\u5f62\u5316\u5de5\u5177\u7684\u8f85\u52a9<\/h2>\n\n\n\n<p>\u9664\u4e86\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u56fe\u5f62\u5316\u7684Git\u5de5\u5177\uff0c\u5982SourceTree\u6216GitKraken\uff0c\u4e5f\u80fd\u4e3a\u60a8\u63d0\u4f9b\u76f4\u89c2\u7684\u7248\u672c\u63a7\u5236\u4f53\u9a8c\u3002\u901a\u8fc7\u56fe\u5f62\u754c\u9762\uff0c\u60a8\u53ef\u4ee5\u66f4\u52a0\u76f4\u89c2\u5730\u67e5\u770b\u6539\u52a8\uff0c\u6bd4\u8f83\u4e0d\u540c\u63d0\u4ea4\u95f4\u6216\u5206\u652f\u95f4\u7684\u5dee\u5f02\uff0c\u5e76\u5728\u5fc5\u8981\u65f6\u8fdb\u884c\u5feb\u901f\u7684\u4ee3\u7801\u5408\u5e76\u6216\u51b2\u7a81\u89e3\u51b3\u3002<\/p>\n\n\n\n<p><strong>\u7ed3\u8bba\uff1a<\/strong>Git\u4f5c\u4e3a\u4e00\u79cd\u5f3a\u5927\u7684\u7248\u672c\u63a7\u5236\u5de5\u5177\uff0c\u5728\u65e5\u5e38\u7684\u4ee3\u7801\u7ba1\u7406\u4e2d\u8d77\u7740\u4e0d\u53ef\u6216\u7f3a\u7684\u4f5c\u7528\u3002\u5b66\u4e60\u5e76\u638c\u63e1\u67e5\u770b\u6587\u4ef6\u6539\u52a8\u7684\u65b9\u6cd5\uff0c\u5c06\u6709\u52a9\u4e8e\u60a8\u548c\u60a8\u7684\u56e2\u961f\u66f4\u52a0\u9ad8\u6548\u3001\u51c6\u786e\u5730\u8fdb\u884c\u9879\u76ee\u5f00\u53d1\u3002\u8bb0\u5f97\uff0c\u5728\u6bcf\u6b21\u67e5\u770b\u6539\u52a8\u65f6\uff0c\u90fd\u8981\u6709\u76ee\u7684\u548c<strong><\/strong><\/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-60.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-56910\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u4e0b\u8f7dgithub\u7684\u6587\u4ef6-60.jpg 1280w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/10\/\u5982\u4f55\u4e0b\u8f7dgithub\u7684\u6587\u4ef6-60-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><strong>\u95ee<\/strong>\uff1a\u5982\u4f55\u4f7f\u7528Git\u67e5\u770b\u6211\u7684\u672c\u5730\u6587\u4ef6\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u4e2d\u7684\u6587\u4ef6\u6709\u4f55\u5dee\u5f02\uff1f<\/li>\n\n\n\n<li><strong>\u7b54<\/strong>\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528<strong>git diff<\/strong>\u547d\u4ee4\u6765\u67e5\u770b\u672c\u5730\u672a\u63d0\u4ea4\u7684\u6587\u4ef6\u4e0e\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u6587\u4ef6\u7684\u5dee\u5f02\u3002\u82e5\u8981\u67e5\u770b\u672c\u5730\u4e0e\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5dee\u5f02\uff0c\u4f60\u53ef\u4ee5\u9996\u5148\u4f7f\u7528<strong>git fetch origin<\/strong>\uff08\u5047\u8bbe\u4f60\u7684\u8fdc\u7a0b\u4ed3\u5e93\u522b\u540d\u662forigin\uff09\u6765\u83b7\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u7684\u6700\u65b0\u72b6\u6001\uff0c\u7136\u540e\u4f7f\u7528<strong>git diff HEAD..origin\/master<\/strong>\uff08\u5982\u679c\u4f60\u60f3\u8981\u6bd4\u8f83\u7684\u662fmaster\u5206\u652f\uff09\u6765\u67e5\u770b\u5dee\u5f02\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee<\/strong>\uff1a\u6211\u5982\u4f55\u67e5\u770b\u67d0\u4e00\u4e2a\u6587\u4ef6\u5728\u4e0d\u540c\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02\uff1f<\/li>\n\n\n\n<li><strong>\u7b54<\/strong>\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528<strong>git diff<\/strong>\u547d\u4ee4\u5e76\u6307\u5b9a\u8981\u6bd4\u8f83\u7684\u4e24\u4e2a\u63d0\u4ea4\u7684\u54c8\u5e0c\u503c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u8981\u67e5\u770b\u6587\u4ef6<strong>example.txt<\/strong>\u5728\u4e24\u4e2a\u7279\u5b9a\u63d0\u4ea4\u4e4b\u95f4\u7684\u5dee\u5f02\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<strong>git diff [first_commit_hash] [second_commit_hash] &#8212; example.txt<\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<ul>\n<li><strong>\u95ee<\/strong>\uff1a\u6211\u600e\u6837\u53ef\u4ee5\u67e5\u770b\u6211\u6700\u8fd1\u7684\u4fee\u6539\uff0c\u5373\u4f7f\u6211\u8fd8\u6ca1\u6709\u8fdb\u884c\u63d0\u4ea4\uff1f<\/li>\n\n\n\n<li><strong>\u7b54<\/strong>\uff1a\u8981\u67e5\u770b\u5c1a\u672a\u63d0\u4ea4\u7684\u66f4\u6539\uff0c\u4f60\u53ef\u4ee5\u53ea\u4f7f\u7528<strong>git diff<\/strong>\u547d\u4ee4\u3002\u8fd9\u5c06\u5c55\u793a\u5de5\u4f5c\u76ee\u5f55\u548c\u7d22\u5f15\uff08\u5373\uff0c\u4f60\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684\u5185\u5bb9\uff09\u4e4b\u95f4\u7684\u5dee\u5f02\u3002\u5982\u679c\u4f60\u60f3\u67e5\u770b\u5df2\u6682\u5b58\u4f46\u672a\u63d0\u4ea4\u7684\u66f4\u6539\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>git diff &#8211;cached<\/strong>\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528GIT\u6765\u67e5\u770b\u6539\u52a8\u7684\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a1. \u7406\u89e3Git\u7684\u5de5\u4f5c\u6d41\u7a0b\uff1b2. \u5229\u7528git diff \u67e5\u770b\u6539\u52a8\uff1b3. \u4f7f\u7528 [&hellip;]","protected":false},"author":7,"featured_media":56911,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[2734,1163],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/56906"}],"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=56906"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/56906\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/56911"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=56906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=56906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=56906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}