{"id":262,"date":"2026-06-11T18:51:02","date_gmt":"2026-06-11T10:51:02","guid":{"rendered":"https:\/\/blog.mumudlin.com\/?p=262"},"modified":"2026-06-11T19:18:56","modified_gmt":"2026-06-11T11:18:56","slug":"git-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4","status":"publish","type":"post","link":"https:\/\/blog.mumudlin.com\/index.php\/git-%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4\/","title":{"rendered":"Git \u5e38\u7528\u547d\u4ee4"},"content":{"rendered":"<h1>Git \u5e38\u7528\u547d\u4ee4<\/h1>\n<blockquote>\n<p>\u4e00\u4efd\u9762\u5411\u521d\u5b66\u8005\u7684 Git \u547d\u4ee4\u901f\u67e5\u4e0e\u6559\u7a0b\uff0c\u6db5\u76d6\u914d\u7f6e\u3001\u57fa\u672c\u64cd\u4f5c\u3001\u5206\u652f\u7ba1\u7406\u3001\u8fdc\u7a0b\u534f\u4f5c\u3001\u64a4\u9500\u4fee\u6539\u7b49\u65e5\u5e38\u5f00\u53d1\u573a\u666f\u3002<\/p>\n<\/blockquote>\n<ul>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#1-\u914d\u7f6e\">1. \u914d\u7f6e<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#2-\u57fa\u672c\u64cd\u4f5c\">2. \u57fa\u672c\u64cd\u4f5c<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#3-\u5206\u652f\u7ba1\u7406\">3. \u5206\u652f\u7ba1\u7406<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#4-\u8fdc\u7a0b\u534f\u4f5c\">4. \u8fdc\u7a0b\u534f\u4f5c<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#5-\u67e5\u770b\u5386\u53f2\u4e0e\u72b6\u6001\">5. \u67e5\u770b\u5386\u53f2\u4e0e\u72b6\u6001<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#6-\u64a4\u9500\u4e0e\u56de\u9000\">6. \u64a4\u9500\u4e0e\u56de\u9000<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#7-\u6682\u5b58\u4e0e\u50a8\u85cf\">7. \u6682\u5b58\u4e0e\u50a8\u85cf<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#8-\u6807\u7b7e\u7ba1\u7406\">8. \u6807\u7b7e\u7ba1\u7406<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#9-\u5408\u5e76\u4e0e\u53d8\u57fa\">9. \u5408\u5e76\u4e0e\u53d8\u57fa<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#10-\u9ad8\u7ea7\u6280\u5de7\">10. \u9ad8\u7ea7\u6280\u5de7<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#11-\u5e38\u89c1\u5de5\u4f5c\u6d41\">11. \u5e38\u89c1\u5de5\u4f5c\u6d41<\/a><\/li>\n<li><a target=\"_blank\" rel=\"noopener\" href=\"#\u9644\u914d\u7f6e\u901f\u67e5\u8868\">\u9644\uff1a\u914d\u7f6e\u901f\u67e5\u8868<\/a><\/li>\n<\/ul>\n<hr \/>\n<h2>1. \u914d\u7f6e<\/h2>\n<p>Git \u7684\u914d\u7f6e\u5206\u4e3a\u4e09\u4e2a\u5c42\u7ea7\uff0c\u4f18\u5148\u7ea7\u4ece\u9ad8\u5230\u4f4e\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5c42\u7ea7<\/th>\n<th>\u547d\u4ee4<\/th>\n<th>\u751f\u6548\u8303\u56f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4ed3\u5e93\u7ea7<\/td>\n<td><code>git config --local<\/code><\/td>\n<td>\u5f53\u524d\u4ed3\u5e93<\/td>\n<\/tr>\n<tr>\n<td>\u7528\u6237\u7ea7<\/td>\n<td><code>git config --global<\/code><\/td>\n<td>\u5f53\u524d\u7528\u6237<\/td>\n<\/tr>\n<tr>\n<td>\u7cfb\u7edf\u7ea7<\/td>\n<td><code>git config --system<\/code><\/td>\n<td>\u6574\u53f0\u673a\u5668<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u8bbe\u7f6e\u7528\u6237\u540d\u4e0e\u90ae\u7bb1\uff08\u5b89\u88c5\u540e\u5fc5\u505a\uff09<\/h3>\n<pre><code class=\"language-bash\">git config --global user.name &quot;\u4f60\u7684\u540d\u5b57&quot;\ngit config --global user.email &quot;your.email@example.com&quot;<\/code><\/pre>\n<h3>\u5e38\u7528\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\">git config --global core.editor &quot;code --wait&quot;     # \u9ed8\u8ba4\u7f16\u8f91\u5668\u8bbe\u4e3a VS Code\ngit config --global core.autocrlf true             # Windows \u4e0b\u81ea\u52a8\u8f6c\u6362\u6362\u884c\u7b26\ngit config --global color.ui auto                  # \u542f\u7528\u989c\u8272\u8f93\u51fa\ngit config --global init.defaultBranch main        # \u9ed8\u8ba4\u5206\u652f\u540d\u8bbe\u4e3a main\ngit config --global alias.co checkout              # \u8bbe\u7f6e\u522b\u540d\uff08\u89c1\u4e0b\u6587\uff09<\/code><\/pre>\n<h3>\u67e5\u770b\u914d\u7f6e<\/h3>\n<pre><code class=\"language-bash\">git config --list             # \u5217\u51fa\u6240\u6709\u914d\u7f6e\ngit config --global --list    # \u5217\u51fa\u7528\u6237\u7ea7\u914d\u7f6e\ngit config user.name          # \u67e5\u770b\u5355\u9879\u914d\u7f6e<\/code><\/pre>\n<h3>\u8bbe\u7f6e\u522b\u540d\uff08Alias\uff09<\/h3>\n<pre><code class=\"language-bash\">git config --global alias.st status\ngit config --global alias.ci commit\ngit config --global alias.br branch\ngit config --global alias.co checkout\ngit config --global alias.lg &quot;log --oneline --graph --all --decorate&quot;\n\n# \u4e4b\u540e\u5c31\u53ef\u4ee5\u7528\ngit st    # \u4ee3\u66ff git status\ngit lg    # \u67e5\u770b\u6f02\u4eae\u7684\u63d0\u4ea4\u5386\u53f2\u56fe<\/code><\/pre>\n<hr \/>\n<h2>2. \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>\u521d\u59cb\u5316\u4e0e\u514b\u9686<\/h3>\n<pre><code class=\"language-bash\">git init                    # \u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u4ed3\u5e93\ngit init my-project         # \u521b\u5efa\u76ee\u5f55\u5e76\u521d\u59cb\u5316\ngit clone &lt;url&gt;             # \u514b\u9686\u8fdc\u7a0b\u4ed3\u5e93\ngit clone &lt;url&gt; my-folder   # \u514b\u9686\u5230\u6307\u5b9a\u76ee\u5f55\ngit clone --depth=1 &lt;url&gt;   # \u6d45\u514b\u9686\uff08\u53ea\u62c9\u53d6\u6700\u65b0\u7248\u672c\uff0c\u901f\u5ea6\u66f4\u5feb\uff09<\/code><\/pre>\n<h3>\u6587\u4ef6\u7684\u56db\u4e2a\u72b6\u6001<\/h3>\n<pre><code>\u5de5\u4f5c\u533a  \u2500\u2500git add\u2500\u2500\u25b6  \u6682\u5b58\u533a  \u2500\u2500git commit\u2500\u2500\u25b6  \u672c\u5730\u4ed3\u5e93  \u2500\u2500git push\u2500\u2500\u25b6  \u8fdc\u7a0b\u4ed3\u5e93\n                              \u25b2\n                              \u2514\u2500\u2500 \u65b0\u6587\u4ef6\/\u4fee\u6539\u540e\u6587\u4ef6<\/code><\/pre>\n<h3>\u6dfb\u52a0\u4e0e\u63d0\u4ea4<\/h3>\n<pre><code class=\"language-bash\">git add file.txt              # \u6dfb\u52a0\u5355\u4e2a\u6587\u4ef6\u5230\u6682\u5b58\u533a\ngit add .                     # \u6dfb\u52a0\u6240\u6709\u53d8\u66f4\uff08\u5f53\u524d\u76ee\u5f55\u53ca\u5b50\u76ee\u5f55\uff09\ngit add -A                    # \u6dfb\u52a0\u6240\u6709\u53d8\u66f4\uff08\u5168\u4ed3\u5e93\uff09\ngit add -p                    # \u4ea4\u4e92\u5f0f\u5206\u6bb5\u6dfb\u52a0\uff08\u5927\u6539\u65f6\u63a8\u8350\uff09\n\ngit commit -m &quot;feat: \u6dfb\u52a0\u7528\u6237\u767b\u5f55\u529f\u80fd&quot;     # \u76f4\u63a5\u63d0\u4ea4\ngit commit -a -m &quot;fix: \u4fee\u590d\u5d29\u6e83\u95ee\u9898&quot;      # \u8df3\u8fc7\u6682\u5b58\u533a\uff0c\u76f4\u63a5\u63d0\u4ea4\u5df2\u8ddf\u8e2a\u6587\u4ef6\ngit commit --amend -m &quot;\u65b0\u63d0\u4ea4\u4fe1\u606f&quot;        # \u4fee\u6539\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\u7684\u4fe1\u606f\ngit commit --amend --no-edit             # \u4e0d\u4fee\u6539\u4fe1\u606f\uff0c\u628a\u6682\u5b58\u533a\u5185\u5bb9\u5408\u5e76\u5230\u4e0a\u4e00\u6b21\u63d0\u4ea4<\/code><\/pre>\n<h3>\u63d0\u4ea4\u4fe1\u606f\u89c4\u8303\uff08Conventional Commits\uff09<\/h3>\n<pre><code class=\"language-bash\">&lt;\u7c7b\u578b&gt;(&lt;\u8303\u56f4&gt;): &lt;\u7b80\u77ed\u63cf\u8ff0&gt;\n\n# \u5e38\u7528\u7c7b\u578b\nfeat:      # \u65b0\u529f\u80fd\nfix:       # \u4fee\u590d bug\ndocs:      # \u6587\u6863\u66f4\u65b0\nstyle:     # \u4ee3\u7801\u683c\u5f0f\uff08\u4e0d\u5f71\u54cd\u529f\u80fd\uff09\nrefactor:  # \u91cd\u6784\uff08\u65e2\u4e0d\u662f\u4fee\u590d\u4e5f\u4e0d\u662f\u65b0\u529f\u80fd\uff09\nperf:      # \u6027\u80fd\u4f18\u5316\ntest:      # \u6d4b\u8bd5\u76f8\u5173\nchore:     # \u6784\u5efa\u3001CI \u7b49\u6742\u9879\nci:        # CI \u914d\u7f6e\u53d8\u66f4<\/code><\/pre>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-bash\">git commit -m &quot;feat(auth): \u6dfb\u52a0 OAuth 2.0 \u767b\u5f55\u652f\u6301&quot;\ngit commit -m &quot;fix(parser): \u4fee\u590d\u7a7a\u8f93\u5165\u65f6\u7684\u7a7a\u6307\u9488\u5f02\u5e38&quot;<\/code><\/pre>\n<hr \/>\n<h2>3. \u5206\u652f\u7ba1\u7406<\/h2>\n<h3>\u521b\u5efa\u4e0e\u5207\u6362<\/h3>\n<pre><code class=\"language-bash\">git branch                    # \u67e5\u770b\u672c\u5730\u5206\u652f\u5217\u8868\uff08*\u6807\u8bb0\u5f53\u524d\u5206\u652f\uff09\ngit branch -a                 # \u67e5\u770b\u6240\u6709\u5206\u652f\uff08\u542b\u8fdc\u7a0b\uff09\ngit branch -r                 # \u53ea\u67e5\u770b\u8fdc\u7a0b\u5206\u652f\n\ngit branch feature-login      # \u521b\u5efa\u65b0\u5206\u652f\uff08\u4e0d\u5207\u6362\uff09\ngit checkout feature-login    # \u5207\u6362\u5230\u5df2\u6709\u5206\u652f\ngit switch feature-login      # \u65b0\u7248 Git \u63a8\u8350\u7684\u65b9\u5f0f\n\ngit checkout -b feature-login # \u521b\u5efa\u5e76\u5207\u6362\u5230\u65b0\u5206\u652f\uff08\u5e38\u7528\uff09\ngit switch -c feature-login   # \u65b0\u7248\u7b49\u4ef7\u5199\u6cd5\n\ngit branch -m old-name new-name   # \u91cd\u547d\u540d\u5206\u652f\ngit branch -d feature-login       # \u5220\u9664\u5df2\u5408\u5e76\u7684\u5206\u652f\ngit branch -D feature-login       # \u5f3a\u5236\u5220\u9664\uff08\u672a\u5408\u5e76\u4e5f\u80fd\u5220\uff09<\/code><\/pre>\n<h3>\u5206\u652f\u547d\u540d\u5efa\u8bae<\/h3>\n<pre><code class=\"language-bash\">feature\/xxx        # \u65b0\u529f\u80fd\nbugfix\/xxx         # \u4fee\u590d bug\nhotfix\/xxx         # \u7d27\u6025\u4fee\u590d\nrelease\/xxx        # \u53d1\u5e03\u7248\u672c<\/code><\/pre>\n<hr \/>\n<h2>4. \u8fdc\u7a0b\u534f\u4f5c<\/h2>\n<h3>\u8fdc\u7a0b\u4ed3\u5e93\u7ba1\u7406<\/h3>\n<pre><code class=\"language-bash\">git remote -v                    # \u67e5\u770b\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\ngit remote add origin &lt;url&gt;      # \u6dfb\u52a0\u8fdc\u7a0b\u4ed3\u5e93\ngit remote remove origin         # \u79fb\u9664\u8fdc\u7a0b\u4ed3\u5e93\ngit remote set-url origin &lt;url&gt;  # \u4fee\u6539\u8fdc\u7a0b\u4ed3\u5e93\u5730\u5740\ngit remote rename origin upstream # \u91cd\u547d\u540d\u8fdc\u7a0b\u4ed3\u5e93<\/code><\/pre>\n<h3>\u62c9\u53d6\u4e0e\u63a8\u9001<\/h3>\n<pre><code class=\"language-bash\">git push                          # \u63a8\u9001\u5230\u9ed8\u8ba4\u8fdc\u7a0b\uff08origin\uff09\ngit push origin main              # \u63a8\u9001\u5230\u6307\u5b9a\u5206\u652f\ngit push -u origin feature-xxx    # \u63a8\u9001\u5e76\u5efa\u7acb\u4e0a\u6e38\u5173\u8054\uff08\u9996\u6b21\u63a8\u9001\u5e38\u7528\uff09\ngit push --force                  # \u5f3a\u5236\u63a8\u9001\uff08\u614e\u7528\uff01\uff09\ngit push --force-with-lease       # \u5b89\u5168\u5f3a\u5236\u63a8\u9001\uff08\u68c0\u67e5\u8fdc\u7a0b\u662f\u5426\u6709\u65b0\u63d0\u4ea4\uff09\n\ngit pull                          # \u62c9\u53d6\u5e76\u5408\u5e76\uff08\u76f8\u5f53\u4e8e git fetch + git merge\uff09\ngit pull --rebase                 # \u62c9\u53d6\u5e76\u53d8\u57fa\uff08\u63a8\u8350\uff0c\u4fdd\u6301\u5386\u53f2\u7ebf\u6027\uff09\n\ngit fetch                         # \u83b7\u53d6\u8fdc\u7a0b\u66f4\u65b0\u4f46\u4e0d\u5408\u5e76\ngit fetch origin                  # \u83b7\u53d6\u6307\u5b9a\u8fdc\u7a0b\u7684\u66f4\u65b0\ngit fetch --prune                 # \u83b7\u53d6\u66f4\u65b0\u5e76\u6e05\u7406\u5df2\u5220\u9664\u7684\u8fdc\u7a0b\u5206\u652f<\/code><\/pre>\n<h3>\u5e38\u89c1\u63a8\u9001\u95ee\u9898\u89e3\u51b3<\/h3>\n<pre><code class=\"language-bash\"># \u63a8\u9001\u88ab\u62d2\u7edd\uff08\u8fdc\u7a0b\u6709\u672c\u5730\u6ca1\u6709\u7684\u63d0\u4ea4\uff09\ngit pull --rebase      # \u5148\u53d8\u57fa\u62c9\u53d6\ngit push               # \u518d\u63a8\u9001\n\n# \u6216\ngit fetch\ngit rebase origin\/main\ngit push<\/code><\/pre>\n<hr \/>\n<h2>5. \u67e5\u770b\u5386\u53f2\u4e0e\u72b6\u6001<\/h2>\n<pre><code class=\"language-bash\">git status                    # \u67e5\u770b\u5de5\u4f5c\u533a\u72b6\u6001\ngit status -s                 # \u7b80\u6d01\u6a21\u5f0f\uff08-s = short\uff09\n\ngit log                       # \u67e5\u770b\u63d0\u4ea4\u5386\u53f2\ngit log --oneline             # \u4e00\u884c\u663e\u793a\ngit log --graph               # \u4ee5\u56fe\u5f62\u663e\u793a\u5206\u652f\ngit log --oneline --graph --all  # \u6700\u5e38\u7528\u7ec4\u5408\ngit log -5                    # \u53ea\u770b\u6700\u8fd1 5 \u6761\ngit log --author=&quot;\u5f20\u4e09&quot;       # \u6309\u4f5c\u8005\u8fc7\u6ee4\ngit log --since=&quot;2024-01-01&quot;  # \u6309\u65f6\u95f4\u8fc7\u6ee4\ngit log --grep=&quot;fix&quot;          # \u6309\u63d0\u4ea4\u4fe1\u606f\u641c\u7d22\n\ngit log -p                    # \u663e\u793a\u6bcf\u6b21\u63d0\u4ea4\u7684 diff\ngit log --stat                # \u663e\u793a\u53d8\u66f4\u6587\u4ef6\u7edf\u8ba1\n\ngit show                      # \u663e\u793a\u6700\u65b0\u63d0\u4ea4\u8be6\u60c5\ngit show &lt;commit-hash&gt;        # \u663e\u793a\u67d0\u6b21\u63d0\u4ea4\u8be6\u60c5\ngit show HEAD                 # \u663e\u793a\u5f53\u524d\u6700\u65b0\u63d0\u4ea4<\/code><\/pre>\n<h3>\u67e5\u770b\u6587\u4ef6\u5dee\u5f02<\/h3>\n<pre><code class=\"language-bash\">git diff                      # \u5de5\u4f5c\u533a vs \u6682\u5b58\u533a\uff08\u672a\u6682\u5b58\u7684\u53d8\u66f4\uff09\ngit diff --staged             # \u6682\u5b58\u533a vs \u6700\u8fd1\u63d0\u4ea4\uff08\u5df2\u6682\u5b58\u7684\u53d8\u66f4\uff09\ngit diff HEAD                 # \u5de5\u4f5c\u533a vs \u6700\u8fd1\u63d0\u4ea4\ngit diff main..feature        # \u4e24\u4e2a\u5206\u652f\u5bf9\u6bd4\ngit diff &lt;commit1&gt; &lt;commit2&gt;  # \u4e24\u6b21\u63d0\u4ea4\u5bf9\u6bd4\ngit diff --name-only          # \u53ea\u663e\u793a\u53d8\u66f4\u6587\u4ef6\u540d<\/code><\/pre>\n<hr \/>\n<h2>6. \u64a4\u9500\u4e0e\u56de\u9000<\/h2>\n<h3>\u5de5\u4f5c\u533a\u64a4\u9500<\/h3>\n<pre><code class=\"language-bash\">git restore file.txt              # \u64a4\u9500\u5de5\u4f5c\u533a\u7684\u4fee\u6539\uff08\u65b0\u7248\uff09\ngit checkout -- file.txt          # \u540c\u4e0a\uff08\u65e7\u7248\u5199\u6cd5\uff09\n\ngit restore .                     # \u64a4\u9500\u6240\u6709\u672a\u6682\u5b58\u7684\u4fee\u6539<\/code><\/pre>\n<h3>\u6682\u5b58\u533a\u64a4\u9500<\/h3>\n<pre><code class=\"language-bash\">git restore --staged file.txt     # \u53d6\u6d88\u6682\u5b58\uff08\u4ece\u6682\u5b58\u533a\u79fb\u56de\u5de5\u4f5c\u533a\uff09\ngit reset HEAD file.txt           # \u540c\u4e0a\uff08\u65e7\u7248\u5199\u6cd5\uff09<\/code><\/pre>\n<h3>\u63d0\u4ea4\u64a4\u9500<\/h3>\n<pre><code class=\"language-bash\">git reset --soft HEAD~1           # \u64a4\u9500\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u5185\u5bb9\ngit reset --mixed HEAD~1          # \u64a4\u9500\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\uff0c\u4fdd\u7559\u5de5\u4f5c\u533a\uff0c\u6e05\u7a7a\u6682\u5b58\u533a\uff08\u9ed8\u8ba4\uff09\ngit reset --hard HEAD~1           # \u64a4\u9500\u6700\u8fd1\u4e00\u6b21\u63d0\u4ea4\uff0c\u5de5\u4f5c\u533a\u548c\u6682\u5b58\u533a\u5168\u90e8\u4e22\u5f03\uff08\u26a0\ufe0f \u614e\u7528\uff01\uff09\n\ngit reset --hard &lt;commit-hash&gt;    # \u56de\u9000\u5230\u6307\u5b9a\u63d0\u4ea4\uff08\u4e22\u5f03\u4e2d\u95f4\u6240\u6709\u63d0\u4ea4\uff09\n\ngit revert HEAD                   # \u751f\u6210\u4e00\u4e2a\u65b0\u7684\u63d0\u4ea4\u6765\u64a4\u9500\u4e0a\u4e00\u6b21\u63d0\u4ea4\uff08\u63a8\u8350\u7528\u4e8e\u516c\u5171\u5206\u652f\uff09\ngit revert &lt;commit-hash&gt;          # \u64a4\u9500\u67d0\u6b21\u7279\u5b9a\u63d0\u4ea4<\/code><\/pre>\n<blockquote>\n<p><strong><code>reset<\/code> vs <code>revert<\/code><\/strong>\uff1a<code>reset<\/code> \u4f1a\u5220\u9664\u5386\u53f2\uff0c\u4e0d\u8981\u5728\u516c\u5171\u5206\u652f\u4f7f\u7528\uff1b<code>revert<\/code> \u5b89\u5168\u5730\u751f\u6210\u53cd\u5411\u63d0\u4ea4\uff0c\u9002\u5408\u4efb\u4f55\u5206\u652f\u3002<\/p>\n<\/blockquote>\n<hr \/>\n<h2>7. \u6682\u5b58\u4e0e\u50a8\u85cf<\/h2>\n<p>\u5f53\u4f60\u9700\u8981\u5207\u6362\u5206\u652f\u4f46\u4e0d\u60f3\u63d0\u4ea4\u5f53\u524d\u5de5\u4f5c\u8fdb\u5ea6\u65f6\uff1a<\/p>\n<pre><code class=\"language-bash\">git stash                     # \u50a8\u85cf\u5f53\u524d\u4fee\u6539\ngit stash save &quot;\u63cf\u8ff0\u4fe1\u606f&quot;     # \u5e26\u63cf\u8ff0\u7684\u50a8\u85cf\ngit stash list                # \u67e5\u770b\u6240\u6709\u50a8\u85cf\u5217\u8868\n\ngit stash pop                 # \u6062\u590d\u6700\u8fd1\u4e00\u6b21\u50a8\u85cf\u5e76\u5220\u9664\u5b83\ngit stash apply               # \u6062\u590d\u6700\u8fd1\u4e00\u6b21\u50a8\u85cf\u4f46\u4e0d\u5220\u9664\ngit stash apply stash@{2}     # \u6062\u590d\u6307\u5b9a\u50a8\u85cf\n\ngit stash drop stash@{0}      # \u5220\u9664\u6307\u5b9a\u50a8\u85cf\ngit stash clear               # \u6e05\u7a7a\u6240\u6709\u50a8\u85cf\ngit stash branch feature-xxx  # \u4ece\u50a8\u85cf\u521b\u5efa\u65b0\u5206\u652f\uff08\u53ef\u5728\u51b2\u7a81\u65f6\u6062\u590d\uff09<\/code><\/pre>\n<hr \/>\n<h2>8. \u6807\u7b7e\u7ba1\u7406<\/h2>\n<pre><code class=\"language-bash\">git tag                           # \u5217\u51fa\u6240\u6709\u6807\u7b7e\ngit tag -l &quot;v2.*&quot;                 # \u6309\u6a21\u5f0f\u641c\u7d22\u6807\u7b7e\n\ngit tag v1.0.0                    # \u521b\u5efa\u8f7b\u91cf\u6807\u7b7e\ngit tag -a v1.0.0 -m &quot;\u53d1\u5e03 v1.0.0&quot;  # \u521b\u5efa\u9644\u6ce8\u6807\u7b7e\uff08\u63a8\u8350\uff09\ngit tag -a v1.0.0 &lt;commit-hash&gt; -m &quot;\u5bf9\u5386\u53f2\u63d0\u4ea4\u6253\u6807\u7b7e&quot;\n\ngit push origin v1.0.0            # \u63a8\u9001\u5355\u4e2a\u6807\u7b7e\ngit push origin --tags            # \u63a8\u9001\u6240\u6709\u6807\u7b7e\n\ngit tag -d v1.0.0                 # \u5220\u9664\u672c\u5730\u6807\u7b7e\ngit push origin --delete v1.0.0   # \u5220\u9664\u8fdc\u7a0b\u6807\u7b7e\n\ngit describe                      # \u663e\u793a\u6700\u8fd1\u7684\u6807\u7b7e\u540d\uff08\u5e38\u7528\u4e8e\u7248\u672c\u53f7\u81ea\u52a8\u751f\u6210\uff09<\/code><\/pre>\n<h3>\u8bed\u4e49\u5316\u7248\u672c\uff08SemVer\uff09<\/h3>\n<pre><code class=\"language-bash\">v\u4e3b\u7248\u672c.\u6b21\u7248\u672c.\u4fee\u8ba2\u53f7\n\n# \u793a\u4f8b\nv1.0.0    # \u9996\u4e2a\u7a33\u5b9a\u7248\u672c\nv1.1.0    # \u65b0\u589e\u529f\u80fd\nv1.1.1    # \u4fee\u590d bug\nv2.0.0    # \u4e0d\u517c\u5bb9\u7684 API \u53d8\u66f4<\/code><\/pre>\n<hr \/>\n<h2>9. \u5408\u5e76\u4e0e\u53d8\u57fa<\/h2>\n<h3>\u5408\u5e76\uff08Merge\uff09<\/h3>\n<pre><code class=\"language-bash\">git checkout main\ngit merge feature-login           # \u5c06 feature-login \u5408\u5e76\u5230 main\ngit merge --no-ff feature-login   # \u7981\u7528\u5feb\u8fdb\u5408\u5e76\uff08\u4fdd\u7559\u5206\u652f\u5386\u53f2\uff09<\/code><\/pre>\n<pre><code>\/\/ --no-ff \u7684\u6548\u679c\n\/\/ \u4e0d\u52a0 --no-ff\uff08\u5feb\u8fdb\uff0c\u5386\u53f2\u662f\u76f4\u7ebf\uff09\nmain:   A---B---C\n                     \u2191 \u770b\u4e0d\u51fa\u6765\u66fe\u6709\u8fc7 feature \u5206\u652f\n\n\/\/ \u52a0 --no-ff\uff08\u4fdd\u7559\u5206\u652f\u8282\u70b9\uff09\nmain:   A---B---C---D\n                  \\ \/\n            feature<\/code><\/pre>\n<h3>\u53d8\u57fa\uff08Rebase\uff09<\/h3>\n<pre><code class=\"language-bash\">git checkout feature\ngit rebase main                   # \u5c06 feature \u5206\u652f\u53d8\u57fa\u5230 main \u4e4b\u4e0a\n\n# \u4ea4\u4e92\u5f0f\u53d8\u57fa\uff08\u6574\u7406\u63d0\u4ea4\u5386\u53f2\uff09\ngit rebase -i HEAD~3              # \u4ea4\u4e92\u5f0f\u4fee\u6539\u6700\u8fd1 3 \u6b21\u63d0\u4ea4<\/code><\/pre>\n<p>\u4ea4\u4e92\u5f0f\u53d8\u57fa\u63d0\u4f9b\u7684\u64cd\u4f5c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u547d\u4ee4<\/th>\n<th>\u7f29\u5199<\/th>\n<th>\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>pick<\/code><\/td>\n<td><code>p<\/code><\/td>\n<td>\u4fdd\u7559\u8be5\u63d0\u4ea4<\/td>\n<\/tr>\n<tr>\n<td><code>reword<\/code><\/td>\n<td><code>r<\/code><\/td>\n<td>\u4fdd\u7559\u4f46\u4fee\u6539\u63d0\u4ea4\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td><code>edit<\/code><\/td>\n<td><code>e<\/code><\/td>\n<td>\u4fdd\u7559\u4f46\u4fee\u6539\u63d0\u4ea4\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td><code>squash<\/code><\/td>\n<td><code>s<\/code><\/td>\n<td>\u5408\u5e76\u5230\u4e0a\u4e00\u4e2a\u63d0\u4ea4<\/td>\n<\/tr>\n<tr>\n<td><code>fixup<\/code><\/td>\n<td><code>f<\/code><\/td>\n<td>\u5408\u5e76\u5230\u4e0a\u4e00\u4e2a\u63d0\u4ea4\u5e76\u4e22\u5f03\u63d0\u4ea4\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td><code>drop<\/code><\/td>\n<td><code>d<\/code><\/td>\n<td>\u5220\u9664\u8be5\u63d0\u4ea4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u89e3\u51b3\u51b2\u7a81<\/h3>\n<pre><code class=\"language-bash\"># \u5408\u5e76\u6216\u53d8\u57fa\u65f6\u51fa\u73b0\u51b2\u7a81\n# 1. \u6253\u5f00\u6587\u4ef6\uff0c\u641c\u7d22 &lt;&lt;&lt;&lt;&lt;&lt;&lt;, =======, &gt;&gt;&gt;&gt;&gt;&gt;&gt;\n# 2. \u624b\u52a8\u4fdd\u7559\u9700\u8981\u7684\u4ee3\u7801\uff0c\u5220\u9664\u51b2\u7a81\u6807\u8bb0\n# 3. \u4fdd\u5b58\u6587\u4ef6\n\ngit add file.txt                  # \u6807\u8bb0\u51b2\u7a81\u5df2\u89e3\u51b3\ngit commit                        # \u5b8c\u6210\u5408\u5e76\uff08merge \u65f6\uff09\ngit rebase --continue             # \u7ee7\u7eed\u53d8\u57fa\uff08rebase \u65f6\uff09\n\ngit rebase --abort                # \u653e\u5f03\u53d8\u57fa\uff0c\u56de\u5230\u5f00\u59cb\u524d\u72b6\u6001\ngit merge --abort                 # \u653e\u5f03\u5408\u5e76\uff0c\u56de\u5230\u5f00\u59cb\u524d\u72b6\u6001<\/code><\/pre>\n<hr \/>\n<h2>10. \u9ad8\u7ea7\u6280\u5de7<\/h2>\n<h3>\u4e8c\u5206\u67e5\u627e\uff08Bisect\uff09<\/h3>\n<p>\u5feb\u901f\u5b9a\u4f4d\u5f15\u5165 bug \u7684\u63d0\u4ea4\uff1a<\/p>\n<pre><code class=\"language-bash\">git bisect start\ngit bisect bad                    # \u6807\u8bb0\u5f53\u524d\u7248\u672c\u4e3a\u6709 bug\ngit bisect good v1.0.0            # \u6807\u8bb0\u4e00\u4e2a\u5df2\u77e5\u7684\u597d\u7248\u672c\n# Git \u4f1a\u5e2e\u4f60\u4e8c\u5206\u67e5\u627e\uff0c\u6bcf\u6b21\u544a\u8bc9\u4f60\u8fd8\u5269\u591a\u5c11\u6b65\n# \u6d4b\u8bd5\u540e\u6807\u8bb0\uff1a\ngit bisect good                   # \u5f53\u524d\u7248\u672c\u65e0 bug\ngit bisect bad                    # \u5f53\u524d\u7248\u672c\u6709 bug\n# \u91cd\u590d\u76f4\u5230\u627e\u5230\u7b2c\u4e00\u4e2a\u6709 bug \u7684\u63d0\u4ea4\ngit bisect reset                  # \u7ed3\u675f bisect<\/code><\/pre>\n<h3>\u67e5\u627e\u8c01\u4fee\u6539\u4e86\u67d0\u884c<\/h3>\n<pre><code class=\"language-bash\">git blame file.txt                # \u67e5\u770b\u6bcf\u884c\u662f\u8c01\u6539\u7684\ngit blame -L 10,20 file.txt       # \u53ea\u770b\u7b2c 10-20 \u884c\ngit blame -w file.txt             # \u5ffd\u7565\u7a7a\u683c\u53d8\u66f4<\/code><\/pre>\n<h3>\u6e05\u7406<\/h3>\n<pre><code class=\"language-bash\">git clean -n                      # \u9884\u89c8\u5c06\u88ab\u5220\u9664\u7684\u672a\u8ddf\u8e2a\u6587\u4ef6\ngit clean -f                      # \u5220\u9664\u672a\u8ddf\u8e2a\u6587\u4ef6\ngit clean -fd                     # \u5220\u9664\u672a\u8ddf\u8e2a\u6587\u4ef6\u548c\u76ee\u5f55<\/code><\/pre>\n<h3>\u9009\u62e9\u63d0\u4ea4\uff08Cherry-pick\uff09<\/h3>\n<pre><code class=\"language-bash\"># \u5c06\u67d0\u4e2a\u5206\u652f\u7684\u7279\u5b9a\u63d0\u4ea4\u5e94\u7528\u5230\u5f53\u524d\u5206\u652f\ngit cherry-pick &lt;commit-hash&gt;\ngit cherry-pick &lt;hash1&gt; &lt;hash2&gt;   # \u6311\u9009\u591a\u4e2a\u63d0\u4ea4\ngit cherry-pick A..B              # \u6311\u9009 A \u5230 B \u4e4b\u95f4\uff08\u4e0d\u542b A\uff09\u7684\u6240\u6709\u63d0\u4ea4<\/code><\/pre>\n<h3>\u5b50\u6a21\u5757<\/h3>\n<pre><code class=\"language-bash\">git submodule add &lt;url&gt; path              # \u6dfb\u52a0\u5b50\u6a21\u5757\ngit clone --recurse-submodules &lt;url&gt;      # \u514b\u9686\u9879\u76ee\u5e76\u521d\u59cb\u5316\u5b50\u6a21\u5757\ngit submodule update --init --recursive   # \u62c9\u53d6\u6240\u6709\u5b50\u6a21\u5757\u66f4\u65b0<\/code><\/pre>\n<hr \/>\n<h2>11. \u5e38\u89c1\u5de5\u4f5c\u6d41<\/h2>\n<h3>\u4e2a\u4eba\u9879\u76ee\uff08\u6700\u7b80\u5355\uff09<\/h3>\n<pre><code class=\"language-bash\">git init\ngit add .\ngit commit -m &quot;init&quot;\ngit remote add origin &lt;url&gt;\ngit push -u origin main\n# \u65e5\u5e38\uff1a\ngit add . &amp;&amp; git commit -m &quot;xxx&quot; &amp;&amp; git push<\/code><\/pre>\n<h3>\u529f\u80fd\u5206\u652f\u5de5\u4f5c\u6d41\uff08Feature Branch\uff09<\/h3>\n<pre><code class=\"language-bash\"># \u4ece main \u521b\u5efa\u529f\u80fd\u5206\u652f\ngit checkout -b feature\/user-profile\n\n# \u5728\u529f\u80fd\u5206\u652f\u4e0a\u5f00\u53d1\ngit add . &amp;&amp; git commit -m &quot;feat: \u6dfb\u52a0\u7528\u6237\u8d44\u6599\u9875&quot;\n\n# \u540c\u6b65\u4e3b\u5206\u652f\uff08\u5b9a\u671f\u53d8\u57fa\uff09\ngit fetch origin\ngit rebase origin\/main\n\n# \u63d0\u4ea4 PR \/ Merge Request \u524d\ngit rebase -i HEAD~3     # \u6574\u7406\u63d0\u4ea4\u5386\u53f2\ngit push -u origin feature\/user-profile\n\n# \u5408\u5e76\u5230 main\uff08\u901a\u5e38\u901a\u8fc7 PR \u5728\u5e73\u53f0\u64cd\u4f5c\uff09\ngit checkout main\ngit pull\ngit branch -d feature\/user-profile<\/code><\/pre>\n<h3>Git Flow<\/h3>\n<pre><code class=\"language-bash\"># \u7ecf\u5178\u5206\u652f\u6a21\u578b\nmain          # \u751f\u4ea7\u5206\u652f\uff0c\u4fdd\u6301\u7a33\u5b9a\ndevelop       # \u5f00\u53d1\u4e3b\u5206\u652f\nfeature\/*     # \u529f\u80fd\u5206\u652f\uff0c\u57fa\u4e8e develop\nrelease\/*     # \u53d1\u5e03\u5206\u652f\uff0c\u57fa\u4e8e develop\nhotfix\/*      # \u7d27\u6025\u4fee\u590d\uff0c\u57fa\u4e8e main<\/code><\/pre>\n<h3>\u7d27\u6025\u4fee\u590d\uff08Hotfix\uff09<\/h3>\n<pre><code class=\"language-bash\">git checkout main\ngit checkout -b hotfix\/crash-fix\n# \u4fee\u590d\u4ee3\u7801\ngit add . &amp;&amp; git commit -m &quot;fix: \u4fee\u590d\u5d29\u6e83&quot;\ngit push -u origin hotfix\/crash-fix\n# \u5408\u5e76\u5230 main \u548c develop<\/code><\/pre>\n<hr \/>\n<h2>\u9644\uff1a\u914d\u7f6e\u901f\u67e5\u8868<\/h2>\n<h3><code>.gitignore<\/code> \u5e38\u7528\u6a21\u5f0f<\/h3>\n<pre><code class=\"language-gitignore\"># \u7f16\u8bd1\u4ea7\u7269\n*.exe\n*.dll\n*.so\n*.o\n*.class\ntarget\/\nbuild\/\ndist\/\n\n# \u4f9d\u8d56\nnode_modules\/\nvendor\/\n.venv\/\n\n# \u73af\u5883\u4e0e\u914d\u7f6e\n.env\n.env.local\n*.config.js\n\n# IDE\n.idea\/\n.vscode\/\n*.swp\n*.swo\n.DS_Store\nThumbs.db\n\n# \u65e5\u5fd7\u4e0e\u4e34\u65f6\u6587\u4ef6\n*.log\n*.tmp<\/code><\/pre>\n<h3><code>.gitattributes<\/code> \u5e38\u89c1\u914d\u7f6e<\/h3>\n<pre><code class=\"language-gitignore\"># \u6587\u672c\u6587\u4ef6\u81ea\u52a8\u8f6c\u6362\u6362\u884c\u7b26\n* text=auto\n\n# \u6307\u5b9a\u7279\u5b9a\u6587\u4ef6\u7684\u6362\u884c\u7b26\n*.sh text eol=lf\n*.bat text eol=crlf\n\n# \u4e8c\u8fdb\u5236\u6587\u4ef6\u58f0\u660e\n*.png binary\n*.jpg binary\n*.zip binary<\/code><\/pre>\n<h3>\u5e38\u7528\u547d\u4ee4\u901f\u67e5\u5361<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c<\/th>\n<th>\u547d\u4ee4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u521d\u59cb\u5316<\/td>\n<td><code>git init<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u514b\u9686<\/td>\n<td><code>git clone &lt;url&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u6dfb\u52a0<\/td>\n<td><code>git add .<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u63d0\u4ea4<\/td>\n<td><code>git commit -m &quot;msg&quot;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u63a8\u9001<\/td>\n<td><code>git push<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u62c9\u53d6<\/td>\n<td><code>git pull --rebase<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u521b\u5efa\u5206\u652f<\/td>\n<td><code>git switch -c &lt;name&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u5207\u6362\u5206\u652f<\/td>\n<td><code>git switch &lt;name&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u5408\u5e76\u5206\u652f<\/td>\n<td><code>git merge &lt;name&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u770b\u72b6\u6001<\/td>\n<td><code>git status<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u67e5\u770b\u5386\u53f2<\/td>\n<td><code>git log --oneline --graph<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u64a4\u9500\u5de5\u4f5c\u533a<\/td>\n<td><code>git restore &lt;file&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u64a4\u9500\u6682\u5b58\u533a<\/td>\n<td><code>git restore --staged &lt;file&gt;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u50a8\u85cf<\/td>\n<td><code>git stash<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u6062\u590d\u50a8\u85cf<\/td>\n<td><code>git stash pop<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u6253\u6807\u7b7e<\/td>\n<td><code>git tag -a v1.0 -m &quot;msg&quot;<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u63a8\u9001\u6807\u7b7e<\/td>\n<td><code>git push --tags<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p><strong>\u751f\u6210\u65f6\u95f4<\/strong>\uff1a2025-01<br \/>\n<strong>\u6570\u636e\u6765\u6e90<\/strong>\uff1aGit \u5b98\u65b9\u6587\u6863\u3001Pro Git \u4e66\u7c4d\u3001\u793e\u533a\u5b9e\u8df5\u603b\u7ed3<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Git \u5e38\u7528\u547d\u4ee4 \u4e00\u4efd\u9762\u5411\u521d\u5b66\u8005\u7684 Git \u547d\u4ee4\u901f\u67e5\u4e0e\u6559\u7a0b\uff0c\u6db5\u76d6\u914d\u7f6e\u3001\u57fa\u672c\u64cd\u4f5c\u3001\u5206\u652f\u7ba1\u7406\u3001\u8fdc\u7a0b\u534f\u4f5c\u3001\u64a4\u9500\u4fee\u6539\u7b49 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-ai-"],"_links":{"self":[{"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":3,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":267,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/posts\/262\/revisions\/267"}],"wp:attachment":[{"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mumudlin.com\/index.php\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}