{"id":328,"date":"2021-08-11T00:42:17","date_gmt":"2021-08-10T16:42:17","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=328"},"modified":"2021-12-26T22:46:05","modified_gmt":"2021-12-26T14:46:05","slug":"git","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=328","title":{"rendered":"git"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e0c3ab97dc7\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e0c3ab97dc7\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E8%BD%AF%E4%BB%B6\" >\u7248\u672c\u63a7\u5236\u8f6f\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#Git\" >Git<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#Git%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99\" >Git\u5b66\u4e60\u8d44\u6599<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#Git%E6%80%9D%E6%83%B3\" >Git\u601d\u60f3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#Git%E7%BC%BA%E7%82%B9\" >Git\u7f3a\u70b9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#%E8%8E%B7%E5%8F%96Git%E5%B8%AE%E5%8A%A9\" >\u83b7\u53d6Git\u5e2e\u52a9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%93repository\" >\u521b\u5efa\u4ed3\u5e93(repository)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#%E9%85%8D%E7%BD%AEGit\" >\u914d\u7f6eGit<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#Git%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\" >Git\u57fa\u672c\u6982\u5ff5<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=328\/#3%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C\" >3.\u57fa\u672c\u64cd\u4f5c<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E8%BD%AF%E4%BB%B6\"><\/span>\u7248\u672c\u63a7\u5236\u8f6f\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>BitKeeper<\/li><li>CVS<\/li><li>SVN<\/li><li>Git<\/li><li>Mercurial<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Git\"><\/span>Git<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>BitKeeper\u4e0d\u8d5e\u52a9Linux\u56e2\u961f\u540e\uff0cLinus\u5c31\u7740\u624b\u5f00\u53d1\u4e86Git\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Git%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99\"><\/span>Git\u5b66\u4e60\u8d44\u6599<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b98\u7f51: http:\/\/git-scm.com\/<\/li><li>\u53ef\u4ee5\u901a\u8fc7<code>man git<\/code>\u67e5\u770bgit\u6587\u6863\u4ee5\u83b7\u53d6\u5173\u4e8egit\u7684\u8be6\u7ec6\u4ecb\u7ecd\u3002\u4f7f\u7528<code>git --html-path<\/code>\u53ef\u4ee5\u67e5\u770b\u672c\u5730\u7684git\u6587\u6863\u8def\u5f84\u3002<\/li><\/ul>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/progit-en.1084.pdf\">progit-en.1084<\/a><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/progit-en.1084.pdf\" class=\"wp-block-file__button\" download>\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/git_real_slides.pdf\">git_real_slides<\/a><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/git_real_slides.pdf\" class=\"wp-block-file__button\" download>\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/git_real_2_full_deck.pdf\">git_real_2_full_deck<\/a><a href=\"https:\/\/blog.cauchyschwarz.com\/wp-content\/uploads\/2021\/08\/git_real_2_full_deck.pdf\" class=\"wp-block-file__button\" download><\/a><\/div>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Git%E6%80%9D%E6%83%B3\"><\/span>Git\u601d\u60f3<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Git%E7%BC%BA%E7%82%B9\"><\/span>Git\u7f3a\u70b9<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><del>\u4ed3\u5e93\u6bd4\u8f83\u5927\u65f6(1GB)\u6709\u6027\u80fd\u95ee\u9898<\/del>\uff1b<\/li><li>\u5b58\u50a8\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u6bcf\u4e2a\u7248\u672c\uff0c\u800c\u4e0d\u662f\u91c7\u53d6\u8ba1\u7b97\u53d8\u5316\u91cf\u8fd9\u79cd\u7b56\u7565\u3002<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%8E%B7%E5%8F%96Git%E5%B8%AE%E5%8A%A9\"><\/span>\u83b7\u53d6Git\u5e2e\u52a9<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><code>git help<\/code><\/li><li><code>git help command<\/code>\u6216\u8005<code>man git-command<\/code> \u83b7\u53d6\u5173\u4e8e\u67d0\u4e2a\u547d\u4ee4 <em>command<\/em> \u7684\u5e2e\u52a9<\/li><li><code>git help -a\/g<\/code> \u83b7\u53d6\u8f83\u5168\u9762\u7684\u5e2e\u52a9<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%93repository\"><\/span>\u521b\u5efa\u4ed3\u5e93(repository)<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li><code>git init<\/code><\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%85%8D%E7%BD%AEGit\"><\/span>\u914d\u7f6eGit<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p><code>git config<\/code><\/p>\n\n\n\n<p>\u7528\u6cd5\uff1agit config [&lt;\u9009\u9879&gt;]<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9009\u62e9\u8bfb\u914d\u7f6e\u8fd8\u662f\u5199\u914d\u7f6e<br>\u5e26\u6709<code>--get<\/code>\u4e4b\u7c7b\u5b57\u6837\u7684\u663e\u7136\u5c31\u662f\u8bfb\u53d6\u914d\u7f6e\u3002\u4eceManual\u4e2d\u53ef\u4ee5\u770b\u5230\u8fd8\u6709\u589e\u52a0\u3001\u79fb\u9664\u914d\u7f6e\u7b49\u9009\u9879\u3002<\/li><li>\u901a\u8fc7\u6587\u4ef6\u914d\u7f6e\u8fd8\u662f\u547d\u4ee4\u884c\u9009\u9879\u914d\u7f6e<br>\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u9010\u4e2a\u914d\u7f6e\u952e\u503c\u5bf9\uff0c\u6216\u8005<code>git config [&lt;file-option&gt;] -e | --edit<\/code>\u76f4\u63a5\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6\uff0c\u6216\u8005\u968f\u4fbf\u7528\u4e2a\u7f16\u8f91\u5668\u7f16\u8f91\u76f8\u5e94\u7684\u914d\u7f6e\u6587\u4ef6\u5373\u53ef\u3002<\/li><li>\u914d\u7f6e\u7684\u5f62\u5f0f<\/li><li>\u4f8b\u5b50\uff1a<br><code>git config [--global] user.name \"Your name\"<\/code><br><code>git config [--global] user.emal you@email.com<\/code><br><code>git config [--global] color.ui true<\/code><\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>\u914d\u7f6e\u8303\u56f4<br>\u901a\u8fc7<em>file-option<\/em>\u9009\u9879\u6307\u5b9a\u914d\u7f6e\u8303\u56f4\u3002<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>file-option<\/td><td>\u542b\u4e49<\/td><\/tr><tr><td>&#8211;system<\/td><td>\u4ece<em>$(prefix)\/etc\/gitconfig<\/em>\u4e2d\u8bfb\u5199\u914d\u7f6e\u9009\u9879<\/td><\/tr><tr><td>&#8211;global<\/td><td>\u4ece<em>~\/.gitconfig<\/em>\u4e2d\u8bfb\u5199\u914d\u7f6e\u9009\u9879<\/td><\/tr><tr><td>&#8211;local(\u9ed8\u8ba4\u503c)<\/td><td>\u4ece<em>.git\/config<\/em>\u4e2d\u8bfb\u5199\u914d\u7f6e\u9009\u9879<\/td><\/tr><tr><td>&#8211;file<\/td><td>\u4ece<em>filename<\/em>\u4e2d\u8bfb\u5199\u914d\u7f6e\u9009\u9879<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5728\u8fdb\u884c<code>git config<\/code>\u64cd\u4f5c\u65f6\uff0c\u5982\u679c\u662f\u8bfb\u64cd\u4f5c\uff0c\u90a3\u4e48git\u4f9d\u6b21\u4ece\u7cfb\u7edf\u914d\u7f6e(system)\u3001\u5168\u5c40\u914d\u7f6e(global)\u548c\u4ed3\u5e93\u914d\u7f6e(local)\u4e2d\u8bfb\u53d6\u914d\u7f6e\uff0c\u5982\u679c\u6307\u5b9a\u4e86<em>file-option<\/em>\uff0c\u90a3\u4e48git\u53ea\u4ece\u6307\u5b9a\u7684\u4f4d\u7f6e\u8bfb\u53d6\u914d\u7f6e\u3002\u5982\u679c\u662f\u5199\u64cd\u4f5c\uff0c\u90a3\u4e48git\u9ed8\u8ba4\u5199\u5230\u4ed3\u5e93\u914d\u7f6e\u91cc\uff0c\u5982\u679c\u6307\u5b9a\u4e86<em>file-option<\/em>\uff0c\u90a3\u4e48git\u5c31\u5c06\u914d\u7f6e\u5199\u5230<em>file-option<\/em>\u6240\u4ee3\u8868\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Git%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5\"><\/span>Git\u57fa\u672c\u6982\u5ff5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5de5\u4f5c\u533a(working directory)<\/li><li>\u7d22\u5f15(INDEX)<\/li><li>commit<br>A snapshot of your project.<\/li><li>HEAD<br>\u5f53\u524d\u5206\u652f(branch)\u7684\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C\"><\/span>3.\u57fa\u672c\u64cd\u4f5c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9009\u62e9\u8981\u8981\u8ba9git\u8ddf\u8e2a(track)\u7684\u6587\u4ef6<br><code>git add your-file<\/code><br><code>git add .<\/code><br><code>git add --all<\/code><br><code>git add paths<\/code>\u53ef\u4ee5\u4f7f\u7528\u6587\u4ef6\u540d\u7684\u901a\u914d\u7b26\u8868\u8fbe\u5f0f,\u5982\u679c\u8def\u5f84\u88ab\u52a0\u4e0a\u4e86\u53cc\u5f15\u53f7\u8868\u793a\u5728\u6574\u4e2a\u9879\u76ee\u6587\u4ef6\u4e2d\u8fdb\u884c\u5339\u914d\uff0c\u5426\u5219\u53ea\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u8fdb\u884c\u5339\u914d\u3002<br><code>git add *.txt<\/code>\u5f53\u524d\u76ee\u5f55;<code>git add \"*.txt\"<\/code>\u6574\u4e2a\u9879\u76ee\u6587\u4ef6\u5939\u4e2d\u5339\u914d\u3002<\/li><li>\u67e5\u770b\u4fee\u6539<br><code>git status<\/code>\u67e5\u770b\u81ea\u4e0a\u4e00\u6b21\u63d0\u4ea4(commit)\u4ee5\u6765\uff0c\u5728\u5de5\u4f5c\u76ee\u5f55\u6240\u4f5c\u7684\u4fee\u6539\u3002<br><code>git diff<\/code>\u67e5\u770b\u81ea\u4e0a\u6b21\u63d0\u4ea4\u4ee5\u6765\uff0c\u672a\u6682\u5b58(unstaged)\u7684\u4fee\u6539<br><code>git diff --staged<\/code>\u67e5\u770b\u5df2\u6682\u5b58\u7684\u4fee\u6539<\/li><li>\u53d6\u6d88\u6682\u5b58<br><code>git reset HEAD paths<\/code><br><code>git reset HEAD<\/code><\/li><li>\u653e\u5f03\u4fee\u6539<br><code>git checkout -- paths<\/code><\/li><li>\u63d0\u4ea4\u6539\u53d8(commit)<br><code>git commit<\/code><br><code>git commit -m \"This is a commit\"<\/code><br><code>git commit -a<\/code>\u63d0\u4ea4\u5728\u5df2\u8ddf\u8e2a\u6587\u4ef6\u4e0a\u4f5c\u7684\u5168\u90e8\u6539\u52a8<br><code>git commit -am<\/code><\/li><li>\u53d6\u6d88\u63d0\u4ea4(undoing a commit)<br><code>git reset --soft HEAD<\/code>\u5c06\u4e0a\u6b21\u63d0\u4ea4\u7684\u6539\u52a8\u79fb\u5230\u6682\u5b58\u533a\u91cc(reset into staging)<br><code>git reset --soft commit<\/code>\u5c06HEAD\u79fb\u5230commit,commit\u4e4b\u540e\u7684\u63d0\u4ea4\u90fd\u53d6\u6d88\u5e76\u5c06\u8fd9\u4e9b\u63d0\u4ea4\u6240\u505a\u7684\u6539\u52a8\u90fd\u653e\u5230\u6682\u5b58\u533a(staged)\u91cc\u53bb\u3002<br><code>git reset --hard commit<\/code>\u5c06HEAD\u79fb\u5230commit,\u653e\u5f03\u8be5commit\u4e4b\u540e\u6240\u505a\u7684\u6240\u6709\u6539\u53d8\u3002<\/li><li>\u8865\u5145\u63d0\u4ea4(adding to a commit)<br><code>git commit --amend -m \"adding something to this commit\"<\/code><\/li><li>\u67e5\u770b\u65e5\u5fd7(log)<br><code>git log<\/code>\u67e5\u770b\u8fc7\u53bb\u6240\u6709\u7684\u63d0\u4ea4<\/li><li>\u8fdc\u7a0b\u4ed3\u5e93<br><code>git remote add origin(our name for this remote) repo-addr<\/code>\u589e\u52a0\u4e00\u4e2a\u8fdc\u7a0b\u4ed3\u5e93<br><code>git remote -v<\/code>\u663e\u793a\u6240\u6709\u8fdc\u7a0b\u4ed3\u5e93<br><code>git push -u origin master<\/code>\u63a8\u9001\u672c\u5730\u63d0\u4ea4\u5230origin\u7684master\u5206\u652f\u4e0a\u3002<br><code>git pull<\/code>\u83b7\u53d6\u8fdc\u7a0b\u4ed3\u5e93\u4e0a\u7684commit changes\u3002<br><strong>\u5728 <em>push<\/em> \u4e4b\u540e\uff0c\u4e0d\u8981\u518d\u8fdb\u884c\u53d6\u6d88\u63d0\u4ea4\uff0c\u8865\u5145\u63d0\u4ea4\uff0c\u653e\u5f03\u63d0\u4ea4\u7b49\u64cd\u4f5c\u3002<\/strong><br>\u5df2\u7ecfpush\u5230\u8fdc\u7a0b\u4ed3\u5e93\u7684commit\u662f\u4e0d\u4f1a\u88ab\u6539\u53d8\u7684\uff0c\u867d\u7136\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u4ee5\u4fee\u6539\u672c\u5730\u7684\u63d0\u4ea4\u5386\u53f2\uff0c\u4f46\u662f\u5374\u4e0d\u4f1a\u6539\u53d8\u8fdc\u7a0b\u4ed3\u5e93\u5bf9\u5e94\u5206\u652f\u7684\u63d0\u4ea4\u5386\u53f2\u3002<br><code>git clone repo-addr<\/code>\u514b\u9686\u4e00\u4e2a\u8fdc\u7a0b\u4ed3\u5e93<\/li><li>\u5206\u652f<br><code>git branch branch-name<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f,\u4f46\u662f\u521b\u5efa\u8be5\u5206\u652f\u540e\u5e76\u4e0d\u4f1a\u5207\u6362\u5230\u8be5\u5206\u652f\u3002<br><code>git checkout -b branch-name<\/code>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5206\u652f\uff0c\u5e76\u4e14\u5207\u6362\u5230\u8be5\u5206\u652f\u3002<br><code>git branch -r<\/code>\u5217\u51fa\u6240\u6709\u8fdc\u7a0b\u5206\u652f<br><code>git branch<\/code>\u5217\u51fa\u672c\u5730\u5206\u652f<br><code>git remote show origin<\/code>\u663e\u793a\u672c\u5730\u548c\u8fdc\u7a0b\u4ed3\u5e93\u7684\u5206\u652f\u4fe1\u606f\u3002<br><code>git push origin :branch_to_delete<\/code>\u5220\u9664\u8fdc\u7a0b\u5206\u652f<br><code>git branch -d branch_to_delete<\/code>\u5220\u9664\u672c\u5730\u5206\u652f<br><code>git branch -D branch_to_delete<\/code>\u5f3a\u5236\u5220\u9664\u672c\u5730\u5206\u652f<br><code>git remote prune origin<\/code>\u5220\u9664\u8fdc\u7a0b\u4ed3\u5e93origin\u5df2\u7ecf\u5220\u9664\u4f46\u662f\u5728\u672c\u5730\u8fd8\u5b58\u5728\u7684\u5206\u652f<\/li><li>TAG<br>A tag is a reference to a commit(used mostly for release versioning)<br><code>git tag<\/code>\u5217\u51fa\u5df2\u6709tag<br><code>git tag -a v0.0.1<\/code>\u6dfb\u52a0\u4e00\u4e2atag<br><code>git push --tags<\/code>\u63a8\u9001\u65b0\u52a0\u7684tag<\/li><li>REBASE<br>\u4e00\u822c\u60c5\u51b5\u4e0b,\u6211\u4eec\u901a\u8fc7merge\u5f15\u5165\u6765\u6e90\u4e8e\u5176\u4ed6\u5206\u652f\u7684\u6539\u52a8\uff0c\u4f46\u662fmerge\u64cd\u4f5c\u4f1a\u5728\u5f53\u524d\u5206\u652f\u521b\u5efamerge commit\u8282\u70b9(\u800c\u4e14\u8c8c\u4f3c\u4f1a\u8ba9\u65e5\u5fd7\u53d8\u5f97\u6bd4\u8f83\u4e71?)\u3002\u901a\u8fc7rebase\u64cd\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u907f\u514dmerge\u64cd\u4f5c\u3002<\/li><\/ul>\n\n\n\n<ol class=\"wp-block-list\"><li>\u548c\u8fdc\u7a0b\u5206\u652f\u76f8\u5173\u7684rebase:<br>\u5047\u8bbe\u672c\u5730\u5206\u652fmaster\u7684workflow\u4e3aA&#8211;&gt;B&#8211;&gt;C\uff0c\u8fdc\u7a0b\u5206\u652fmaster\u7684workflow\u4e3aA&#8211;&gt;D&#8211;&gt;E\uff0c\u73b0\u5728\u6211\u4eec\u8981\u907f\u514dmerge\u64cd\u4f5c\u800c\u4e14\u5f15\u5165\u8fdc\u7a0b\u5206\u652f\u7684\u6539\u52a8\uff0c\u90a3\u4e48\uff1a<ul><li>\u9996\u5148<code>git fetch<\/code>,\u5c06origin\/master\u7684\u6539\u52a8\u5f15\u5165\u5230\u672c\u5730\u7684origin\/master\u5206\u652f;<\/li><li>\u7136\u540e\u6267\u884c<code>git rebase<\/code>\uff0c\u6b64\u64cd\u4f5c\u4f1a\u5c06\u672c\u5730\u63d0\u4ea4\u79fb\u5230\u4e00\u4e2a\u4e34\u65f6\u533a\u57df\u91cc\uff0c\u7136\u540e\u5f15\u5165\u8fdc\u7a0b\u5206\u652f\u7684\u63d0\u4ea4\uff0c\u7136\u540e\u518d\u9010\u4e2a\u5f15\u5165\u4e34\u65f6\u533a\u57df\u91cc\u7684\u63d0\u4ea4\u3002\u5f15\u5165\u4e34\u65f6\u533a\u57df\u91cc\u7684\u63d0\u4ea4\u65f6\u53ef\u80fd\u4f1a\u4ea7\u751f\u51b2\u7a81(\u6bd4\u5982origin\/master\u91cc\u7684\u63d0\u4ea4\u548c\u672c\u5730\u5206\u652f\u4e0a\u7684\u63d0\u4ea4\u4fee\u6539\u4e86\u540c\u4e00\u4e2a\u6587\u4ef6),\u6b64\u65f6\u9700\u8981\u50cf\u89e3\u51b3merge conflict\u4e00\u6837\u89e3\u51b3\u51b2\u7a81(\u7f16\u8f91\u6709\u51b2\u7a81\u7684\u6587\u4ef6),\u7136\u540e\u6267\u884c<code>git add<\/code>\u548c<code>git rebase --continue<\/code>\u547d\u4ee4\u7ee7\u7eedrebase\u8fc7\u7a0b\u3002<\/li><\/ul><\/li><li>\u548c\u672c\u5730\u5206\u652f\u76f8\u5173\u7684rebase:<br>\u5047\u8bbe\u672c\u5730\u5206\u652fmaster\u7684workflow\u4e3aA&#8211;&gt;B&#8211;&gt;C\uff0c\u672c\u5730\u5206\u652ffeature\u7684workflow\u4e3aA&#8211;&gt;D&#8211;&gt;E\uff0c\u73b0\u5728\u6211\u4eec\u8981\u907f\u514dmerge\u64cd\u4f5c\u800c\u4e14\u5f15\u5165master\u4e0a\u7684\u63d0\u4ea4\uff0c\u90a3\u4e48\u53ef\u4ee5\u76f4\u63a5checkout\u5230feature\u5206\u652f\u4e0a\uff0c\u7136\u540e<code>git rebase master<\/code>\u5373\u53ef\u3002\u4f46\u662f\u6b64\u540emaster\u5206\u652f\u518d\u8981\u5f15\u5165feature\u5206\u652f\u7684\u63d0\u4ea4\u5c31\u53ea\u6709\u7528merge\u64cd\u4f5c\u4e86\u3002<\/li><\/ol>\n\n\n\n<ul class=\"wp-block-list\"><li>DIFF<br><code>git diff<\/code>\u6bd4\u8f83working directory\u4e0e\u6682\u5b58\u533a<br><code>git diff commit<\/code>\u6bd4\u8f83\u5de5\u4f5c\u533a\u4e0ecommit<br><code>git diff \\&lt;commit\\&gt;..\\&lt;commit\\&gt;<\/code>\u6bd4\u8f83\u4e24\u4e2acommit<\/li><li>\u5217\u51faremote\u5206\u652f<br><code>git branch -r<\/code><\/li><li>\u5206\u652f\u91cd\u547d\u540d<br><code>git branch -m &lt;new-branch-name&gt;<\/code><br><code>git branch -m &lt;old-branch-name&gt; &lt;new-branch-name&gt;<\/code><\/li><li>\u63a8\u6307\u5b9acommit<br><code>git push &lt;remote-name&gt; &lt;commit SHA&gt;:&lt;remote-branch-name&gt;<\/code><\/li><li>\u4fee\u6539\u4e0a\u6e38\u5206\u652f<br><code>git branch -u &lt;remote-name&gt;\/&lt;remote-branch-name&gt;<\/code><br><code>git branch ---set-upstream-to=&lt;remote-name&gt;\/&lt;remote-branch-name&gt;<\/code><\/li><li>\u5220\u9664\u8fdc\u7a0b\u5206\u652f<br><code>git push origin :&lt;branch-to-delete&gt;<\/code><\/li><li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6ca1\u6709\u63d0\u4ea4\u5386\u53f2\u7684\u5206\u652f<br><code>git checkout --orphan &lt;branch-name&gt;<\/code><\/li><li>\u8fc1\u79fb\u4ed3\u5e93<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">  git clone --mirror &lt;old-repo-url&gt;\n  cd &lt;cloned-repo&gt;\n  git push --mirror &lt;new-repo-url&gt;<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f&#8217;\u2013mirror&#8217;\u9009\u9879clone\u4e0b\u6765\u7684\u4ed3\u5e93\u91cc\u4e0d\u80fd\u6267\u884c\u5e38\u7528\u7684&#8217;git status&#8217;\u8fd9\u79cd\u547d\u4ee4\uff0c\u4f1a\u62a5\u9519\u201cNot a git repository\u201d\uff0c\u56e0\u4e3a\u8fd9\u6837clone\u4e0b\u6765\u7684\u4ed3\u5e93\u662f\u666e\u901a\u7684git\u4ed3\u5e93\u91cc\u7684&#8217;.git&#8217;\u8fd9\u79cd\u4e1c\u897f\u3002&#8217;git push \u2013mirror&#8217;\u8fd9\u4e2a\u547d\u4ee4\u4e5f\u4e0d\u80fd\u4e71\u7528\uff0c\u8bef\u7528\u4f1a\u7528\u9519\u8bef\u7684\u4e1c\u897f\u8986\u76d6\u670d\u52a1\u5668\u4e0a\u7684\u8fdc\u7a0b\u4ed3\u5e93\u3002<a href=\"http:\/\/blog.plataformatec.com.br\/2013\/05\/how-to-properly-mirror-a-git-repository\/\">Reference<\/a>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u67e5\u770b\u65e5\u5fd7<br><code>git log<\/code><br><code>git config --global color.ui true<\/code>\u4e3alog\u8bbe\u7f6e\u5f69\u8272\u663e\u793a<br><code>git log --pretty=oneline<\/code>\u4e00\u6b21\u63d0\u4ea4\u7528\u4e00\u884c\u663e\u793a<br><code>git log --pretty=format:\"%h %ad %s [%an]\"<\/code>\u4ee5\u6307\u5b9a\u683c\u5f0f\u8f93\u51fa\u65e5\u5fd7<br><code>git log --oneline -p<\/code>\u663e\u793a\u6bcf\u6b21\u63d0\u4ea4\u7684\u5177\u4f53\u53d8\u66f4<br><code>git log --oneline --stat<\/code><br><code>git log --oneline --graph<\/code>\u663e\u793a\u4e00\u4e2a\u53ef\u89c6\u5316\u7684workflow<br><code>git log --until=1.minute.ago<\/code>\u663e\u793a1\u5206\u949f\u4ee5\u524d\u7684\u63d0\u4ea4<br><code>git log --since=1.day.ago<\/code>\u663e\u793a1\u5929\u4e4b\u524d\u5f00\u59cb\u7684\u63d0\u4ea4<br><code>git log --since=1.month.ago --until=2.weeks.ago<\/code><br><code>git log --since=2000-01-01 --until=2012-12-21<\/code><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>placeholder<\/td><td>\u542b\u4e49<\/td><\/tr><tr><td>%ad<\/td><td>author date<\/td><\/tr><tr><td>%an<\/td><td>author name<\/td><\/tr><tr><td>%h<\/td><td>SHA hash<\/td><\/tr><tr><td>%s<\/td><td>subject<\/td><\/tr><tr><td>%d<\/td><td>ref names<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5e94\u7528patch<\/li><\/ul>\n\n\n\n<p>git apply &#8211;whitespace=fix mychanges.patch<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>cherry pick \u591a\u4e2a\u63d0\u4ea4<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git cherry-pick A^..B\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/stackoverflow.com\/questions\/1186535\/how-to-modify-a-specified-commit\">\u4fee\u6539\u6307\u5b9a\u63d0\u4ea4<\/a><br>\u4f7f\u7528<code>git rebase -i<\/code>\u6765\u56de\u9000\u5230\u6307\u5b9acommit\uff0crebase\u9009\u9879\u91cc\u8be5commit\u4f7f\u7528<code>edit<\/code>\u9009\u9879\u800c\u4e0d\u662f<code>pick<\/code>\u9009\u9879\uff0c\u5728\u5bf9\u8be5commit\u8fdb\u884c\u4fee\u6539\u540e\u7528<code>git commit --amend<\/code>\u63d0\u4ea4\uff0c\u7136\u540e\u7ee7\u7eed<code>git rebase --continue<\/code>\u5c31\u53ef\u4ee5\u4e86\u3002<\/li><li>\u5220\u9664\u5206\u652f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git branch -D xxx\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5220\u9664\u8fdc\u7a0b\u5206\u652f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git push origin --delete &lt;remote-branch&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u53eaclone\u90e8\u5206\u6587\u4ef6<\/li><\/ul>\n\n\n\n<p>\u901a\u8fc7<a href=\"https:\/\/unix.stackexchange.com\/a\/233335\/191816\">sparseCheckout<\/a>\u5b9e\u73b0<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8fdc\u7a0bforce update\u4e4b\u540e\u7684\u5904\u7406<\/li><\/ul>\n\n\n\n<p>\u5982\u679c\u62a5\u9519\uff1a<em>error: cannot update the ref &#8216;refs\/remotes\/origin\/majiebo\/fixBug&#8217;: unable to create directory for &#8216;.git\/logs\/refs\/remotes\/origin\/majiebo\/fixBug&#8217;: No such file or directory<\/em>\uff0c\u90a3\u4e48\u53ef\u4ee5\u5c1d\u8bd5<code>git update-ref -d refs\/remotes\/origin\/majiebo<\/code>\uff0c\u53c2\u8003\u94fe\u63a5\uff1a<a href=\"https:\/\/stackoverflow.com\/a\/64561177\/5357784\">https:\/\/stackoverflow.com\/a\/64561177\/5357784<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6587\u4ef6\u6743\u9650\u5904\u7406<\/li><\/ul>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/a\/44836635\/5357784\">https:\/\/stackoverflow.com\/a\/44836635\/5357784<\/a><br><code>git update-index --chmod=+x &lt;file&gt;<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u83b7\u53d6\u77ed\u7684commit id<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git rev-parse HEAD\ngit rev-parse --short HEAD\ngit log --oneline\ngit log --pretty=oneline --abbrev-commit\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u91cd\u547d\u540d\u5206\u652f<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git branch -m &lt;old_branch&gt; &lt;new_branch&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>tag<\/li><\/ul>\n\n\n\n<p>\u5220\u9664\u4e00\u4e2atag<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git tag -d &lt;tag_name&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5220\u9664\u4e00\u4e2aremote tag<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git push --delete origin &lt;tag_name&gt;\n<\/code><\/pre>\n\n\n\n<p>list tag<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git tag -l<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7248\u672c\u63a7\u5236\u8f6f\u4ef6 BitKeeper CVS SVN Git Mercurial Git BitKeeper\u4e0d\u8d5e\u52a9Linux\u56e2\u961f\u540e\uff0cLinus\u5c31\u7740\u624b\u5f00\u53d1\u4e86Git\u3002 Git\u5b66\u4e60\u8d44\u6599 \u5b98\u7f51: http:\/\/g&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[29],"class_list":["post-328","post","type-post","status-publish","format-standard","hentry","category-10","tag-git"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=328"}],"version-history":[{"count":5,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions"}],"predecessor-version":[{"id":1063,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/328\/revisions\/1063"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}