{"id":847,"date":"2025-07-15T08:32:13","date_gmt":"2025-07-15T08:32:13","guid":{"rendered":"https:\/\/ouyangminwei.com\/?p=847"},"modified":"2025-07-15T08:37:20","modified_gmt":"2025-07-15T08:37:20","slug":"my-git-book","status":"publish","type":"post","link":"https:\/\/ouyangminwei.com\/index.php\/2025\/07\/15\/my-git-book\/","title":{"rendered":"Git \u7591\u96e3\u96dc\u75c7\u624b\u518a"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"zh-Hant\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <title>Git \u7591\u96e3\u96dc\u75c7\u624b\u518a<\/title>\n    <script src=\"https:\/\/cdn.tailwindcss.com\"><\/script>\n    <link href=\"https:\/\/fonts.googleapis.com\/css2?family=Inter:wght@400;500;600;700&#038;family=Noto+Sans+TC:wght@400;500;700&#038;display=swap\" rel=\"stylesheet\">\n    <style>\n        body {\n            font-family: 'Inter', 'Noto Sans TC', sans-serif;\n            background-color: #f8fafc;\n        }\n        .content-section {\n            display: none;\n        }\n        .content-section.active {\n            display: block;\n        }\n        .code-block {\n            background-color: #1e293b;\n            color: #e2e8f0;\n            padding: 1rem;\n            border-radius: 0.5rem;\n            position: relative;\n            font-family: 'Courier New', Courier, monospace;\n            white-space: pre-wrap;\n            word-break: break-all;\n        }\n        .copy-btn {\n            position: absolute;\n            top: 0.5rem;\n            right: 0.5rem;\n            background-color: #334155;\n            color: #94a3b8;\n            border: none;\n            padding: 0.25rem 0.5rem;\n            border-radius: 0.25rem;\n            cursor: pointer;\n            font-size: 0.8rem;\n        }\n        .copy-btn:hover {\n            background-color: #475569;\n        }\n        .nav-link {\n            cursor: pointer;\n            padding: 0.5rem 1rem;\n            border-radius: 0.375rem;\n            transition: all 0.2s ease-in-out;\n        }\n        .nav-link.active {\n            background-color: #3b82f6;\n            color: white;\n            font-weight: 500;\n        }\n        .nav-link:not(.active):hover {\n            background-color: #f3f4f6;\n        }\n        h2 {\n            \/* Sizes are now controlled by Tailwind classes *\/\n            font-weight: 700;\n            border-bottom: 2px solid #e5e7eb;\n            padding-bottom: 0.5rem;\n            margin-bottom: 1.5rem;\n            color: #111827;\n        }\n        h3 {\n            \/* Sizes are now controlled by Tailwind classes *\/\n            font-weight: 600;\n            margin-top: 2rem;\n            margin-bottom: 1rem;\n            color: #1f2937;\n        }\n        p, li {\n            color: #374151;\n            line-height: 1.7;\n        }\n        strong {\n            color: #dc2626;\n        }\n    <\/style>\n<\/head>\n<body class=\"antialiased\">\n\n    <div class=\"container mx-auto p-4 md:p-8\">\n        <header class=\"text-center mb-8\">\n            <h1 class=\"text-3xl sm:text-4xl md:text-5xl font-bold text-gray-800\">Git \u7591\u96e3\u96dc\u75c7\u624b\u518a<\/h1>\n            <p class=\"text-gray-600 mt-2\">\u60a8\u5728\u7248\u672c\u63a7\u5236\u8def\u4e0a\u7684\u5feb\u901f\u6551\u63f4\u6307\u5357<\/p>\n        <\/header>\n\n        <div class=\"flex flex-col md:flex-row gap-6 md:gap-8\">\n            <!-- Sidebar Navigation -->\n            <aside class=\"w-full md:w-1\/4\">\n                <div class=\"sticky top-8 bg-white p-4 rounded-lg shadow-sm\">\n                    <input type=\"text\" id=\"searchInput\" placeholder=\"\u5feb\u901f\u641c\u5c0b...\" class=\"w-full p-2 border rounded-md mb-4 focus:ring-2 focus:ring-blue-500 focus:outline-none\">\n                    <nav id=\"navigation\" class=\"flex flex-col space-y-1\">\n                        <a data-target=\"setup\" class=\"nav-link active\">\u57fa\u672c\u8a2d\u5b9a<\/a>\n                        <a data-target=\"daily\" class=\"nav-link\">\u65e5\u5e38\u64cd\u4f5c<\/a>\n                        <a data-target=\"undo\" class=\"nav-link\">\u9084\u539f\u8207\u91cd\u8a2d<\/a>\n                        <a data-target=\"branch\" class=\"nav-link\">\u5206\u652f\u7ba1\u7406<\/a>\n                        <a data-target=\"emergency\" class=\"nav-link\">\ud83d\udea8 \u7dca\u6025\u6551\u63f4<\/a>\n                        <a data-target=\"advanced\" class=\"nav-link\">\u9032\u968e\u6280\u5de7<\/a>\n                    <\/nav>\n                <\/div>\n            <\/aside>\n\n            <!-- Main Content -->\n            <main class=\"w-full md:w-3\/4 bg-white p-6 rounded-lg shadow-sm\">\n                <section id=\"setup\" class=\"content-section active\">\n                    <h2 class=\"text-2xl md:text-3xl\">\u57fa\u672c\u8a2d\u5b9a<\/h2>\n                    <p>\u5728\u958b\u59cb\u4f7f\u7528 Git \u524d\uff0c\u6700\u91cd\u8981\u7684\u4e00\u6b65\u662f\u8a2d\u5b9a\u60a8\u7684\u4f7f\u7528\u8005\u540d\u7a31\u548c Email\uff0c\u9019\u6703\u88ab\u8a18\u9304\u5728\u6bcf\u4e00\u6b21\u7684 commit \u4e2d\u3002<\/p>\n                    \n                    <h3 class=\"text-xl md:text-2xl\">\u8a2d\u5b9a\u4f7f\u7528\u8005\u540d\u7a31\u8207 Email<\/h3>\n                    <p>\u9019\u6703\u8a2d\u5b9a\u5168\u57df\u7684\u4f7f\u7528\u8005\u8cc7\u8a0a\uff0c\u60a8\u6240\u6709\u7684 Git \u5c08\u6848\u90fd\u6703\u4f7f\u7528\u9019\u500b\u8a2d\u5b9a\u3002<\/p>\n                    <div class=\"code-block\">git config &#8211;global user.name &#8220;\u60a8\u7684\u540d\u5b57&#8221;\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <div class=\"code-block mt-2\">git config &#8211;global user.email &#8220;your.email@example.com&#8221;\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u6aa2\u67e5\u60a8\u7684\u8a2d\u5b9a<\/h3>\n                    <p>\u60a8\u53ef\u4ee5\u6aa2\u67e5\u76ee\u524d\u7684\u8a2d\u5b9a\u8cc7\u8a0a\u3002<\/p>\n                    <div class=\"code-block\">git config &#8211;list\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                <\/section>\n\n                <section id=\"daily\" class=\"content-section\">\n                    <h2 class=\"text-2xl md:text-3xl\">\u65e5\u5e38\u64cd\u4f5c<\/h2>\n                    <p>\u9019\u4e9b\u662f\u60a8\u6bcf\u5929\u90fd\u6703\u7528\u5230\u7684\u57fa\u672c\u6307\u4ee4\u3002<\/p>\n                    \n                    <h3 class=\"text-xl md:text-2xl\">\u5efa\u7acb\u65b0\u5132\u5b58\u5eab<\/h3>\n                    <div class=\"code-block\">git init\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    \n                    <h3 class=\"text-xl md:text-2xl\">\u8907\u88fd\u73fe\u6709\u5132\u5b58\u5eab<\/h3>\n                    <div class=\"code-block\">git clone [url]\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u67e5\u770b\u72c0\u614b<\/h3>\n                    <p>\u6aa2\u67e5\u5de5\u4f5c\u76ee\u9304\u548c\u66ab\u5b58\u5340\u7684\u72c0\u614b\u3002<\/p>\n                    <div class=\"code-block\">git status\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u65b0\u589e\u6a94\u6848\u5230\u66ab\u5b58\u5340<\/h3>\n                    <p>\u65b0\u589e\u55ae\u4e00\u6a94\u6848\uff1a<\/p>\n                    <div class=\"code-block\">git add <\u6a94\u6848\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u65b0\u589e\u6240\u6709\u8b8a\u66f4\u7684\u6a94\u6848\uff1a<\/p>\n                    <div class=\"code-block\">git add .\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u63d0\u4ea4\u8b8a\u66f4<\/h3>\n                    <p>\u5c07\u66ab\u5b58\u5340\u7684\u5167\u5bb9\u63d0\u4ea4\u5230\u5132\u5b58\u5eab\u3002<\/p>\n                    <div class=\"code-block\">git commit -m &#8220;\u60a8\u7684\u63d0\u4ea4\u8a0a\u606f&#8221;\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u63a8\u9001\u5230\u9060\u7aef\u5132\u5b58\u5eab<\/h3>\n                    <div class=\"code-block\">git push origin <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u62c9\u53d6\u9060\u7aef\u8b8a\u66f4<\/h3>\n                    <div class=\"code-block\">git pull origin <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u67e5\u770b\u63d0\u4ea4\u6b77\u53f2<\/h3>\n                    <p>\u57fa\u672c\u7684\u6b77\u53f2\u7d00\u9304\uff1a<\/p>\n                    <div class=\"code-block\">git log\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u5716\u5f62\u5316\u986f\u793a\u7684\u6b77\u53f2\u7d00\u9304\uff1a<\/p>\n                    <div class=\"code-block\">git log &#8211;graph &#8211;oneline &#8211;decorate &#8211;all\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                <\/section>\n\n                <section id=\"undo\" class=\"content-section\">\n                    <h2 class=\"text-2xl md:text-3xl\">\u9084\u539f\u8207\u91cd\u8a2d<\/h2>\n                    <p>\u7576\u4e8b\u60c5\u51fa\u932f\u6642\uff0c\u77e5\u9053\u5982\u4f55\u5b89\u5168\u5730\u56de\u5230\u4e0a\u4e00\u6b65\u975e\u5e38\u91cd\u8981\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u72c0\u6cc1\u4e00\uff1a\u6a94\u6848\u9084\u6c92 `git add`<\/h3>\n                    <p>\u60a8\u4fee\u6539\u4e86\u4e00\u500b\u6a94\u6848\uff0c\u4f46\u60f3\u653e\u68c4\u9019\u4e9b\u4fee\u6539\uff0c\u56de\u5230\u4e0a\u6b21 commit \u7684\u72c0\u614b\u3002<\/p>\n                    <div class=\"code-block\">git restore <\u6a94\u6848\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u72c0\u6cc1\u4e8c\uff1a\u6a94\u6848\u5df2\u7d93 `git add`\uff0c\u4f46\u60f3\u53d6\u6d88\u66ab\u5b58<\/h3>\n                    <p>\u60a8\u4e0d\u5c0f\u5fc3\u628a\u4e00\u500b\u6a94\u6848\u52a0\u5230\u66ab\u5b58\u5340\u4e86\uff0c\u60f3\u628a\u5b83\u79fb\u51fa\u66ab\u5b58\u5340\uff0c\u4f46\u4fdd\u7559\u6a94\u6848\u7684\u4fee\u6539\u3002<\/p>\n                    <div class=\"code-block\">git restore &#8211;staged <\u6a94\u6848\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u72c0\u6cc1\u4e09\uff1a\u4fee\u6539\u6700\u5f8c\u4e00\u6b21\u7684 commit<\/h3>\n                    <p>\u525b\u624d\u7684 commit \u8a0a\u606f\u5beb\u932f\u4e86\uff0c\u6216\u662f\u6f0f\u52a0\u4e86\u4e00\u500b\u6a94\u6848\u3002<\/p>\n                    <p class=\"mt-2\">1. \u5982\u679c\u6709\u6f0f\u52a0\u7684\u6a94\u6848\uff0c\u5148 `git add <\u6a94\u6848\u540d\u7a31>`<\/p>\n                    <p class=\"mt-2\">2. \u4f7f\u7528 `&#8211;amend` \u4f86\u4fee\u6539 commit<\/p>\n                    <div class=\"code-block\">git commit &#8211;amend &#8211;no-edit  # \u4e0d\u4fee\u6539\u8a0a\u606f\uff0c\u50c5\u52a0\u5165\u65b0\u6a94\u6848\ngit commit &#8211;amend             # \u6703\u958b\u555f\u7de8\u8f2f\u5668\u8b93\u60a8\u4fee\u6539\u8a0a\u606f\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\"><strong>\u8b66\u544a\uff1a<\/strong>\u5982\u679c\u9019\u500b commit \u5df2\u7d93\u63a8\u9001\u5230\u9060\u7aef\uff0c\u4fee\u6539\u5f8c\u9700\u8981\u5f37\u5236\u63a8\u9001 (`git push &#8211;force`)\uff0c\u9019\u53ef\u80fd\u6703\u5f71\u97ff\u5176\u4ed6\u5354\u4f5c\u8005\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u72c0\u6cc1\u56db\uff1a\u60f3\u5b8c\u5168\u64a4\u92b7\u67d0\u6b21 commit<\/h3>\n                    <p>\u9019\u500b commit \u6839\u672c\u5c31\u4e0d\u8a72\u5b58\u5728\uff0c\u6211\u60f3\u8b93\u5b83\u6d88\u5931\u3002<\/p>\n                    <p class=\"mt-2\"><strong>\u60c5\u5883 A\uff1a\u9084\u6c92\u63a8\u9001\u5230\u9060\u7aef<\/strong> (\u6bd4\u8f03\u5b89\u5168)<\/p>\n                    <p>\u9019\u6703\u79fb\u9664\u6700\u5f8c\u4e00\u6b21 commit\uff0c\u4e26\u5c07\u8b8a\u66f4\u4fdd\u7559\u5728\u60a8\u7684\u5de5\u4f5c\u76ee\u9304\u3002<\/p>\n                    <div class=\"code-block\">git reset &#8211;soft HEAD~1\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u9019\u6703<strong>\u5fb9\u5e95\u522a\u9664<\/strong>\u6700\u5f8c\u4e00\u6b21 commit \u548c\u6240\u6709\u76f8\u95dc\u7684\u6a94\u6848\u8b8a\u66f4\u3002<strong>\u8acb\u5c0f\u5fc3\u4f7f\u7528\uff01<\/strong><\/p>\n                    <div class=\"code-block\">git reset &#8211;hard HEAD~1\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    \n                    <p class=\"mt-4\"><strong>\u60c5\u5883 B\uff1a\u5df2\u7d93\u63a8\u9001\u5230\u9060\u7aef<\/strong> (\u5efa\u8b70\u4f7f\u7528 revert)<\/p>\n                    <p>\u5728\u5171\u4eab\u7684\u5132\u5b58\u5eab\u4e2d\uff0c`reset` \u662f\u5371\u96aa\u7684\u3002`revert` \u6703\u5efa\u7acb\u4e00\u500b\u65b0\u7684 commit \u4f86\u300c\u53cd\u8f49\u300d\u6307\u5b9a\u7684 commit\uff0c\u9019\u662f\u4e00\u500b\u66f4\u5b89\u5168\u7684\u64cd\u4f5c\u3002<\/p>\n                    <div class=\"code-block\">git revert <\u8981\u64a4\u92b7\u7684 commit hash>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u63a5\u8457\u6b63\u5e38 `git push` \u5373\u53ef\u3002<\/p>\n                <\/section>\n\n                <section id=\"branch\" class=\"content-section\">\n                    <h2 class=\"text-2xl md:text-3xl\">\u5206\u652f\u7ba1\u7406<\/h2>\n                    <p>\u5206\u652f\u662f Git \u6700\u5f37\u5927\u7684\u529f\u80fd\u4e4b\u4e00\uff0c\u8b93\u60a8\u53ef\u4ee5\u5e73\u884c\u958b\u767c\u591a\u500b\u529f\u80fd\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u67e5\u770b\u6240\u6709\u5206\u652f<\/h3>\n                    <div class=\"code-block\">git branch\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u5efa\u7acb\u65b0\u5206\u652f<\/h3>\n                    <div class=\"code-block\">git branch <\u65b0\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u5207\u63db\u5206\u652f<\/h3>\n                    <p>\u4f7f\u7528 `switch` (\u5efa\u8b70\uff0c\u8f03\u65b0) \u6216 `checkout`\u3002<\/p>\n                    <div class=\"code-block\">git switch <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u5efa\u7acb\u4e26\u76f4\u63a5\u5207\u63db\u5230\u65b0\u5206\u652f<\/h3>\n                    <div class=\"code-block\">git switch -c <\u65b0\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u5408\u4f75\u5206\u652f<\/h3>\n                    <p>\u5c07 `feature-branch` \u5408\u4f75\u5230\u60a8\u76ee\u524d\u6240\u5728\u7684\u5206\u652f (\u4f8b\u5982 `main`)\u3002<\/p>\n                    <p>1. \u9996\u5148\uff0c\u5207\u63db\u5230\u8981\u63a5\u6536\u5408\u4f75\u7684\u5206\u652f\uff1a<\/p>\n                    <div class=\"code-block\">git switch main\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">2. \u57f7\u884c\u5408\u4f75\uff1a<\/p>\n                    <div class=\"code-block\">git merge feature-branch\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u522a\u9664\u5206\u652f<\/h3>\n                    <p>\u522a\u9664\u5df2\u7d93\u5408\u4f75\u7684\u672c\u5730\u5206\u652f\uff1a<\/p>\n                    <div class=\"code-block\">git branch -d <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u5f37\u5236\u522a\u9664\u5c1a\u672a\u5408\u4f75\u7684\u672c\u5730\u5206\u652f\uff1a<\/p>\n                    <div class=\"code-block\">git branch -D <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u522a\u9664\u9060\u7aef\u5206\u652f\uff1a<\/p>\n                    <div class=\"code-block\">git push origin &#8211;delete <\u5206\u652f\u540d\u7a31>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                <\/section>\n\n                <section id=\"emergency\" class=\"content-section\">\n                    <h2 class=\"text-2xl md:text-3xl text-red-600\">\ud83d\udea8 \u7dca\u6025\u6551\u63f4<\/h2>\n                    <p>\u7576\u767c\u751f\u56b4\u91cd\u932f\u8aa4\u6642\uff0c\u8acb\u4fdd\u6301\u51b7\u975c\uff0c\u9019\u88e1\u6709\u60a8\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl text-red-500\">\u72c0\u6cc1\u4e00\uff1a\u4e0d\u5c0f\u5fc3\u628a `.env` \u6216\u6a5f\u5bc6\u6a94\u6848 commit \u4e26 push \u4e86\uff01<\/h3>\n                    <p>\u9019\u662f<strong>\u975e\u5e38\u56b4\u91cd<\/strong>\u7684\u60c5\u6cc1\u3002\u50c5\u50c5\u662f\u522a\u9664\u6a94\u6848\u518d commit \u4e00\u6b21\u662f\u4e0d\u5920\u7684\uff0c\u56e0\u70ba\u6a94\u6848\u9084\u5b58\u5728\u65bc Git \u7684\u6b77\u53f2\u7d00\u9304\u4e2d\u3002\u60a8\u5fc5\u9808\u5f9e\u6b77\u53f2\u7d00\u9304\u4e2d\u5fb9\u5e95\u79fb\u9664\u5b83\u3002<\/p>\n                    <p class=\"mt-2\"><strong>\u7b2c\u4e00\u6b65\uff1a\u7acb\u5373\u5728\u670d\u52d9\u7aef\u8b93\u91d1\u9470\u5931\u6548\uff01<\/strong><\/p>\n                    <p>\u4e0d\u8ad6\u60a8\u591a\u5feb\u4fee\u5fa9 Git\uff0c\u90fd\u5fc5\u9808\u5047\u8a2d\u91d1\u9470\u5df2\u7d93\u5916\u6d29\u3002\u8acb\u7acb\u523b\u5230 AWS, Google Cloud, GitHub \u7b49\u5e73\u53f0\uff0c\u505c\u7528\u6216\u66f4\u63db\u5916\u6d29\u7684 API Key\u3001\u5bc6\u78bc\u6216\u6191\u8b49\u3002<\/p>\n                    <p class=\"mt-4\"><strong>\u7b2c\u4e8c\u6b65\uff1a\u5f9e\u6240\u6709\u6b77\u53f2\u7d00\u9304\u4e2d\u79fb\u9664\u6a94\u6848<\/strong><\/p>\n                    <p>\u6211\u5011\u4f7f\u7528 `git filter-branch` \u6307\u4ee4\u3002\u9019\u500b\u6307\u4ee4\u6703\u91cd\u5beb\u60a8\u7684\u5132\u5b58\u5eab\u6b77\u53f2\u3002<strong>\u64cd\u4f5c\u524d\u8acb\u5148\u5099\u4efd\u60a8\u7684\u5c08\u6848\uff01<\/strong><\/p>\n                    <div class=\"code-block\">git filter-branch &#8211;force &#8211;index-filter \\\n&#8216;git rm &#8211;cached &#8211;ignore-unmatch \u8def\u5f91\/\u5230\/\u60a8\u7684\/\u6a5f\u5bc6\u6a94\u6848&#8217; \\\n&#8211;prune-empty &#8211;tag-name-filter cat &#8212; &#8211;all\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u8acb\u5c07 `\u8def\u5f91\/\u5230\/\u60a8\u7684\/\u6a5f\u5bc6\u6a94\u6848` \u63db\u6210\u5be6\u969b\u7684\u6a94\u6848\u8def\u5f91\uff0c\u4f8b\u5982 `config\/database.yml` \u6216 `.env`\u3002<\/p>\n                    \n                    <p class=\"mt-4\"><strong>\u7b2c\u4e09\u6b65\uff1a\u5c07\u6a94\u6848\u52a0\u5165 `.gitignore`<\/strong><\/p>\n                    <p>\u5efa\u7acb\u6216\u4fee\u6539 `.gitignore` \u6a94\u6848\uff0c\u78ba\u4fdd\u672a\u4f86\u4e0d\u6703\u518d\u610f\u5916\u52a0\u5165\u6b64\u6a94\u6848\u3002<\/p>\n                    <div class=\"code-block\">echo &#8220;\u8def\u5f91\/\u5230\/\u60a8\u7684\/\u6a5f\u5bc6\u6a94\u6848&#8221; >> .gitignore\ngit add .gitignore\ngit commit -m &#8220;Add sensitive file to .gitignore&#8221;\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <p class=\"mt-4\"><strong>\u7b2c\u56db\u6b65\uff1a\u5f37\u5236\u63a8\u9001\u5230\u9060\u7aef<\/strong><\/p>\n                    <p>\u56e0\u70ba\u60a8\u91cd\u5beb\u4e86\u6b77\u53f2\uff0c\u6240\u4ee5\u9700\u8981\u5f37\u5236\u63a8\u9001\u3002\u9019\u6703\u8986\u84cb\u9060\u7aef\u7684\u6b77\u53f2\u7d00\u9304\u3002<\/p>\n                    <p><strong>\u8b66\u544a\uff1a<\/strong>\u9019\u6703\u5c0d\u6240\u6709\u5354\u4f5c\u8005\u9020\u6210\u5f71\u97ff\u3002\u8acb\u52d9\u5fc5\u901a\u77e5\u6240\u6709\u5718\u968a\u6210\u54e1\uff0c\u8acb\u4ed6\u5011\u91cd\u65b0 clone \u6216\u4f7f\u7528 `git pull &#8211;rebase` \u4f86\u540c\u6b65\u3002<\/p>\n                    <div class=\"code-block\">git push origin &#8211;force &#8211;all\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl text-red-500 mt-8\">\u72c0\u6cc1\u4e8c\uff1aCommit \u5230\u932f\u8aa4\u7684\u5206\u652f<\/h3>\n                    <p>\u5047\u8a2d\u60a8\u5728 `main` \u5206\u652f\u4e0a\u505a\u4e86\u4e00\u500b commit\uff0c\u4f46\u5b83\u5176\u5be6\u61c9\u8a72\u5c6c\u65bc `feature` \u5206\u652f\u3002<\/p>\n                    <p>1. \u78ba\u8a8d\u60a8\u5728\u932f\u8aa4\u7684\u5206\u652f\u4e0a (`main`)\u3002<\/p>\n                    <p>2. \u5efa\u7acb\/\u5207\u63db\u5230\u6b63\u78ba\u7684\u5206\u652f (`feature`)\uff0c\u6b64\u6642 `feature` \u5206\u652f\u4e5f\u6703\u5305\u542b\u90a3\u500b\u932f\u8aa4\u7684 commit\u3002<\/p>\n                    <div class=\"code-block\">git switch -c feature  # \u5982\u679c feature \u4e0d\u5b58\u5728\n# \u6216\ngit switch feature       # \u5982\u679c feature \u5df2\u5b58\u5728\ngit merge main           # \u5c07 main \u7684\u9032\u5ea6(\u5305\u542b\u932f\u8aa4\u7684commit)\u540c\u6b65\u904e\u4f86\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">3. \u5207\u63db\u56de\u932f\u8aa4\u7684\u5206\u652f (`main`)\uff0c\u4e26\u79fb\u9664\u90a3\u500b commit\u3002<\/p>\n                    <div class=\"code-block\">git switch main\ngit reset &#8211;hard HEAD~1\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u73fe\u5728\uff0c\u8a72 commit \u53ea\u5b58\u5728\u65bc `feature` \u5206\u652f\uff0c`main` \u5206\u652f\u5247\u6062\u5fa9\u539f\u72c0\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl text-red-500 mt-8\">\u72c0\u6cc1\u4e09\uff1a\u4e0d\u5c0f\u5fc3\u522a\u9664\u4e86\u5206\u652f<\/h3>\n                    <p>\u5225\u64d4\u5fc3\uff0cGit \u901a\u5e38\u6703\u4fdd\u7559\u9019\u4e9b\u7d00\u9304\u4e00\u6bb5\u6642\u9593\u3002`reflog` \u662f\u60a8\u7684\u597d\u670b\u53cb\u3002<\/p>\n                    <p>1. \u4f7f\u7528 `reflog` \u627e\u51fa\u60a8\u522a\u9664\u5206\u652f\u524d\u7684\u6700\u5f8c\u4e00\u500b commit\u3002<\/p>\n                    <div class=\"code-block\">git reflog\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">2. \u5728\u5217\u8868\u4e2d\u627e\u5230\u985e\u4f3c `commit: (some hash) &#8230;` \u7684\u7d00\u9304\uff0c\u9019\u5c31\u662f\u60a8\u8981\u627e\u7684\u3002\u8907\u88fd\u90a3\u500b commit hash\u3002<\/p>\n                    <p>3. \u5f9e\u90a3\u500b commit \u91cd\u65b0\u5efa\u7acb\u5206\u652f\u3002<\/p>\n                    <div class=\"code-block\">git branch <\u820a\u5206\u652f\u540d\u7a31> <commit-hash>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                <\/section>\n\n                <section id=\"advanced\" class=\"content-section\">\n                    <h2 class=\"text-2xl md:text-3xl\">\u9032\u968e\u6280\u5de7<\/h2>\n                    <p>\u638c\u63e1\u9019\u4e9b\u6280\u5de7\uff0c\u8b93\u60a8\u7684 Git \u64cd\u4f5c\u66f4\u52a0\u5f97\u5fc3\u61c9\u624b\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u66ab\u5b58\u5de5\u4f5c\u9032\u5ea6 (Stash)<\/h3>\n                    <p>\u7576\u60a8\u6b63\u5728\u4e00\u500b\u5206\u652f\u4e0a\u5de5\u4f5c\uff0c\u4f46\u9700\u8981\u7dca\u6025\u5207\u63db\u5230\u53e6\u4e00\u500b\u5206\u652f\u4fee\u5fa9 bug \u6642\uff0c`stash` \u53ef\u4ee5\u66ab\u6642\u5132\u5b58\u60a8\u5c1a\u672a commit \u7684\u4fee\u6539\u3002<\/p>\n                    <p>1. \u5132\u5b58\u76ee\u524d\u7684\u4fee\u6539\uff1a<\/p>\n                    <div class=\"code-block\">git stash\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">2. (\u5207\u63db\u5230\u5176\u4ed6\u5206\u652f\u505a\u5b8c\u4e8b\u5f8c&#8230;) \u5207\u63db\u56de\u4f86\uff0c\u4e26\u9084\u539f\u5132\u5b58\u7684\u4fee\u6539\uff1a<\/p>\n                    <div class=\"code-block\">git stash pop\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">`pop` \u6703\u5957\u7528\u4e26\u522a\u9664\u6700\u8fd1\u4e00\u6b21\u7684 stash\u3002\u5982\u679c\u53ea\u60f3\u5957\u7528\u4e0d\u522a\u9664\uff0c\u7528 `git stash apply`\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u6311\u63c0 Commit (Cherry-pick)<\/h3>\n                    <p>\u60f3\u5c07\u67d0\u500b\u5206\u652f\u7684\u7279\u5b9a\u4e00\u500b commit \u8907\u88fd\u5230\u76ee\u524d\u7684\u5206\u652f\u4e0a\u3002<\/p>\n                    <div class=\"code-block\">git cherry-pick <commit-hash>\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u4e92\u52d5\u5f0f Rebase (Interactive Rebase)<\/h3>\n                    <p>\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u8b93\u60a8\u4fee\u6539\u3001\u5408\u4f75\u3001\u91cd\u65b0\u6392\u5e8f\u591a\u500b commit\u3002\u4f8b\u5982\uff0c\u5408\u4f75\u6700\u8fd1 3 \u500b commit\uff1a<\/p>\n                    <div class=\"code-block\">git rebase -i HEAD~3\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u57f7\u884c\u5f8c\u6703\u9032\u5165\u4e00\u500b\u7de8\u8f2f\u5668\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u6307\u793a\u64cd\u4f5c (\u4f8b\u5982\u5c07 `pick` \u6539\u6210 `squash` \u6216 `s` \u4f86\u5408\u4f75 commit)\u3002<\/p>\n                    <p class=\"mt-2\"><strong>\u8b66\u544a\uff1a<\/strong>\u540c\u6a23\u5730\uff0c\u4e0d\u8981\u5c0d\u5df2\u7d93\u63a8\u9001\u5230\u5171\u4eab\u5132\u5b58\u5eab\u7684 commit \u9032\u884c rebase\u3002<\/p>\n\n                    <h3 class=\"text-xl md:text-2xl\">\u6a19\u7c64 (Tag)<\/h3>\n                    <p>\u5e38\u7528\u65bc\u6a19\u8a18\u7248\u672c\u865f\u3002<\/p>\n                    <p>\u5efa\u7acb\u4e00\u500b\u8f15\u91cf\u6a19\u7c64\uff1a<\/p>\n                    <div class=\"code-block\">git tag v1.0.0\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                    <p class=\"mt-2\">\u63a8\u9001\u6240\u6709\u6a19\u7c64\u5230\u9060\u7aef\uff1a<\/p>\n                    <div class=\"code-block\">git push &#8211;tags\n<button class=\"copy-btn\">\u8907\u88fd<\/button><\/div>\n                <\/section>\n            <\/main>\n        <\/div>\n    <\/div>\n\n    <script>\n        document.addEventListener('DOMContentLoaded', function () {\n            const navLinks = document.querySelectorAll('.nav-link');\n            const sections = document.querySelectorAll('.content-section');\n            const searchInput = document.getElementById('searchInput');\n            const navigation = document.getElementById('navigation');\n\n            \/\/ --- Navigation Logic ---\n            navLinks.forEach(link => {\n                link.addEventListener('click', () => {\n                    const targetId = link.getAttribute('data-target');\n\n                    \/\/ Update active link\n                    navLinks.forEach(l => l.classList.remove('active'));\n                    link.classList.add('active');\n\n                    \/\/ Show target section\n                    sections.forEach(section => {\n                        if (section.id === targetId) {\n                            section.classList.add('active');\n                        } else {\n                            section.classList.remove('active');\n                        }\n                    });\n                    \n                    \/\/ Clear search input when navigating\n                    searchInput.value = '';\n                    filterContent('');\n                });\n            });\n\n            \/\/ --- Copy Button Logic ---\n            document.querySelectorAll('.copy-btn').forEach(button => {\n                button.addEventListener('click', () => {\n                    const codeBlock = button.parentElement;\n                    const codeToCopy = codeBlock.innerText.replace('\u8907\u88fd', '').trim();\n                    \n                    \/\/ A bit of a hack to copy to clipboard\n                    const textarea = document.createElement('textarea');\n                    textarea.value = codeToCopy;\n                    document.body.appendChild(textarea);\n                    textarea.select();\n                    try {\n                        document.execCommand('copy');\n                        button.innerText = '\u5df2\u8907\u88fd!';\n                        setTimeout(() => {\n                            button.innerText = '\u8907\u88fd';\n                        }, 2000);\n                    } catch (err) {\n                        console.error('Fallback: Oops, unable to copy', err);\n                        button.innerText = '\u5931\u6557';\n                    }\n                    document.body.removeChild(textarea);\n                });\n            });\n\n            \/\/ --- Search\/Filter Logic ---\n            function filterContent(query) {\n                const lowerCaseQuery = query.toLowerCase().trim();\n\n                if (!lowerCaseQuery) {\n                    \/\/ If search is cleared, show the active section\n                    const activeLink = document.querySelector('.nav-link.active');\n                    if(activeLink) {\n                        const targetId = activeLink.getAttribute('data-target');\n                        sections.forEach(s => {\n                           s.classList.remove('active');\n                           if (s.id === targetId) {\n                               s.classList.add('active');\n                           }\n                        });\n                    }\n                    navigation.style.display = 'flex'; \/\/ Show nav\n                    return;\n                }\n                \n                \/\/ If searching, hide nav and show all sections to search within them\n                navigation.style.display = 'none';\n                sections.forEach(s => {\n                    const sectionText = s.innerText.toLowerCase();\n                    if (sectionText.includes(lowerCaseQuery)) {\n                        s.classList.add('active');\n                    } else {\n                        s.classList.remove('active');\n                    }\n                });\n            }\n            \n            searchInput.addEventListener('input', (e) => {\n                filterContent(e.target.value);\n            });\n            \n            \/\/ Initial setup to show the first section\n            document.querySelector('.content-section').classList.add('active');\n        });\n    <\/script>\n\n<\/body>\n<\/html>\n\n","protected":false},"excerpt":{"rendered":"<p>Git \u7591\u96e3\u96dc\u75c7\u624b\u518a Git \u7591\u96e3\u96dc\u75c7\u624b\u518a \u60a8\u5728\u7248\u672c\u63a7\u5236\u8def\u4e0a\u7684\u5feb\u901f\u6551\u63f4\u6307\u5357 \u57fa\u672c &hellip; <a href=\"https:\/\/ouyangminwei.com\/index.php\/2025\/07\/15\/my-git-book\/\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"post_format":[],"class_list":["post-847","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_edit_lock":"1752829506:1","_edit_last":"1","_aioseo_title":"#post_title #separator_sa #site_title","_aioseo_description":"#post_excerpt","_aioseo_keywords":"","_aioseo_og_title":"","_aioseo_og_description":"","_aioseo_og_article_section":"","_aioseo_og_article_tags":"","_aioseo_twitter_title":"","_aioseo_twitter_description":"","_oembed_2544c1d0cb3503ab4c4d558c3b3c8873":"","_oembed_time_2544c1d0cb3503ab4c4d558c3b3c8873":"","_oembed_99481806ecbe6ce4ee46f8588d320993":"","_oembed_db663acf973e82e6d9d80df71945dfb8":"","_oembed_16cdfab488f57db73586f4286af2704f":"","_wp_old_slug":"git-%e7%96%91%e9%9b%a3%e9%9b%9c%e7%97%87%e6%89%8b%e5%86%8a","_links":{"self":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/comments?post=847"}],"version-history":[{"count":2,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/847\/revisions"}],"predecessor-version":[{"id":851,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/posts\/847\/revisions\/851"}],"wp:attachment":[{"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/media?parent=847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/categories?post=847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/tags?post=847"},{"taxonomy":"post_format","embeddable":true,"href":"https:\/\/ouyangminwei.com\/index.php\/wp-json\/wp\/v2\/post_format?post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}