{"id":193250,"date":"2020-06-15T08:05:35","date_gmt":"2020-06-15T00:05:35","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=193250"},"modified":"2020-06-05T09:06:17","modified_gmt":"2020-06-05T01:06:17","slug":"git-hole","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/git-hole.html","title":{"rendered":"Git \u6838\u5fc3\u7684\u9644\u52a0\u4ef7\u503c\u4e4b\u4e00\uff1a\u7f16\u8f91\u5386\u53f2\u8bb0\u5f55"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nGit \u6838\u5fc3\u7684\u9644\u52a0\u4ef7\u503c\u4e4b\u4e00\u5c31\u662f\u7f16\u8f91\u5386\u53f2\u8bb0\u5f55\u7684\u80fd\u529b\u3002\u4e0e\u5c06\u5386\u53f2\u8bb0\u5f55\u89c6\u4e3a\u795e\u5723\u7684\u8bb0\u5f55\u7684\u7248\u672c\u63a7\u5236\u7cfb\u7edf\u4e0d\u540c\uff0c\u5728 Git \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u5386\u53f2\u8bb0\u5f55\u4ee5\u9002\u5e94\u6211\u4eec\u7684\u9700\u8981\u3002\u8fd9\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e86\u5f88\u591a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u8ba9\u6211\u4eec\u53ef\u4ee5\u50cf\u4f7f\u7528\u91cd\u6784\u6765\u7ef4\u62a4\u826f\u597d\u7684\u8f6f\u4ef6\u8bbe\u8ba1\u5b9e\u8df5\u4e00\u6837\uff0c\u7f16\u7ec7\u826f\u597d\u7684\u63d0\u4ea4\u5386\u53f2\u3002\u8fd9\u4e9b\u5de5\u5177\u5bf9\u4e8e\u65b0\u624b\u751a\u81f3\u662f\u6709\u7ecf\u9a8c\u7684 Git \u7528\u6237\u6765\u8bf4\u53ef\u80fd\u4f1a\u6709\u4e9b\u4ee4\u4eba\u751f\u754f\uff0c\u4f46\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u6211\u4eec\u63ed\u5f00\u5f3a\u5927\u7684 git-rebase \u7684\u795e\u79d8\u9762\u7eb1\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff1a\u4e00\u822c\u5efa\u8bae\u4e0d\u8981\u4fee\u6539\u516c\u5171\u5206\u652f\u3001\u5171\u4eab\u5206\u652f\u6216\u7a33\u5b9a\u5206\u652f\u7684\u5386\u53f2\u8bb0\u5f55\u3002\u7f16\u8f91\u7279\u6027\u5206\u652f\u548c\u4e2a\u4eba\u5206\u652f\u7684\u5386\u53f2\u8bb0\u5f55\u662f\u53ef\u4ee5\u7684\uff0c\u7f16\u8f91\u8fd8\u6ca1\u6709\u63a8\u9001\u7684\u63d0\u4ea4\u4e5f\u662f\u53ef\u4ee5\u7684\u3002\u5728\u7f16\u8f91\u5b8c\u63d0\u4ea4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 git push -f \u6765\u5f3a\u5236\u63a8\u9001\u4f60\u7684\u4fee\u6539\u5230\u4e2a\u4eba\u5206\u652f\u6216\u7279\u6027\u5206\u652f\u3002<\/p>\n

\u5c3d\u7ba1\u6709\u8fd9\u4e48\u53ef\u6015\u7684\u8b66\u544a\uff0c\u4f46\u503c\u5f97\u4e00\u63d0\u7684\u662f\uff0c\u672c\u6307\u5357\u4e2d\u63d0\u5230\u7684\u4e00\u5207\u90fd\u662f\u975e\u7834\u574f\u6027\u64cd\u4f5c\u3002\u5b9e\u9645\u4e0a\uff0c\u5728 Git \u4e2d\u6c38\u4e45\u4e22\u5931\u6570\u636e\u662f\u76f8\u5f53\u56f0\u96be\u7684\u3002\u672c\u6307\u5357\u7ed3\u5c3e\u4ecb\u7ecd\u4e86\u5728\u72af\u9519\u8bef\u65f6\u8fdb\u884c\u7ea0\u6b63\u7684\u65b9\u6cd5\u3002<\/p>\n

\u8bbe\u7f6e\u6c99\u76d2<\/strong><\/div>\n

\u6211\u4eec\u4e0d\u60f3\u7834\u574f\u4f60\u7684\u4efb\u4f55\u5b9e\u9645\u7684\u7248\u672c\u5e93\uff0c\u6240\u4ee5\u5728\u6574\u4e2a\u6307\u5357\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u6c99\u76d2\u7248\u672c\u5e93\u3002\u8fd0\u884c\u8fd9\u4e9b\u547d\u4ee4\u6765\u5f00\u59cb\u5de5\u4f5c\u3002<\/p>\n

git init \/tmp\/rebase-sandbox\r\ncd \/tmp\/rebase-sandbox\r\ngit commit --allow-empty -m\"Initial commit\"<\/pre>\n

\u5982\u679c\u4f60\u9047\u5230\u9ebb\u70e6\uff0c\u53ea\u9700\u8fd0\u884crm -rf \/tmp\/rebase-sandbox\uff0c\u5e76\u91cd\u65b0\u8fd0\u884c\u8fd9\u4e9b\u6b65\u9aa4\u5373\u53ef\u91cd\u65b0\u5f00\u59cb\u3002\u672c\u6307\u5357\u7684\u6bcf\u4e00\u6b65\u90fd\u53ef\u4ee5\u5728\u65b0\u7684\u6c99\u7bb1\u4e0a\u8fd0\u884c\uff0c\u6240\u4ee5\u6ca1\u6709\u5fc5\u8981\u91cd\u505a\u6bcf\u4e2a\u4efb\u52a1\u3002<\/p>\n

\u4fee\u6b63\u6700\u8fd1\u7684\u63d0\u4ea4<\/strong><\/div>\n

\u8ba9\u6211\u4eec\u4ece\u7b80\u5355\u7684\u4e8b\u60c5\u5f00\u59cb\uff1a\u4fee\u590d\u4f60\u6700\u8fd1\u7684\u63d0\u4ea4\u3002\u8ba9\u6211\u4eec\u5411\u6c99\u76d2\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u72af\u4e2a\u9519\u8bef\u3002<\/p>\n

echo \"Hello wrold!\" >greeting.txt\r\ngit add greeting.txt\r\ngit commit -m\"Add greeting.txt\"<\/pre>\n

\u4fee\u590d\u8fd9\u4e2a\u9519\u8bef\u662f\u975e\u5e38\u5bb9\u6613\u7684\u3002\u6211\u4eec\u53ea\u9700\u8981\u7f16\u8f91\u6587\u4ef6\uff0c\u7136\u540e\u7528 --amend \u63d0\u4ea4\u5c31\u53ef\u4ee5\u4e86\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n

echo \"Hello world!\" >greeting.txt\r\ngit commit -a --amend<\/pre>\n

\u6307\u5b9a -a \u4f1a\u81ea\u52a8\u5c06\u6240\u6709 Git \u5df2\u7ecf\u77e5\u9053\u7684\u6587\u4ef6\u8fdb\u884c\u6682\u5b58\uff08\u4f8b\u5982 Git \u6dfb\u52a0\u7684\uff09\uff0c\u800c --amend \u4f1a\u5c06\u66f4\u6539\u7684\u5185\u5bb9\u538b\u6241\u5230\u6700\u8fd1\u7684\u63d0\u4ea4\u4e2d\u3002\u4fdd\u5b58\u5e76\u9000\u51fa\u4f60\u7684\u7f16\u8f91\u5668\uff08\u5982\u679c\u9700\u8981\uff0c\u4f60\u73b0\u5728\u53ef\u4ee5\u4fee\u6539\u63d0\u4ea4\u4fe1\u606f\uff09\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c git show \u770b\u5230\u4fee\u590d\u7684\u63d0\u4ea4\u3002<\/p>\n

commit f5f19fbf6d35b2db37dcac3a55289ff9602e4d00 (HEAD -> master)\r\nAuthor: Drew DeVault \r\nDate: Sun Apr 28 11:09:47 2019 -0400\r\n\u00a0\r\nAdd greeting.txt\r\n\u00a0\r\ndiff --git a\/greeting.txt b\/greeting.txt\r\nnew file mode 100644\r\nindex 0000000..cd08755\r\n--- \/dev\/null\r\n+++ b\/greeting.txt\r\n@@ -0,0 +1 @@\r\n+Hello world!<\/pre>\n
\u4fee\u590d\u8f83\u65e7\u7684\u63d0\u4ea4<\/strong><\/div>\n

--amend \u4ec5\u9002\u7528\u4e8e\u6700\u8fd1\u7684\u63d0\u4ea4\u3002\u5982\u679c\u4f60\u9700\u8981\u4fee\u6b63\u4e00\u4e2a\u8f83\u65e7\u7684\u63d0\u4ea4\u4f1a\u600e\u4e48\u6837\uff1f\u8ba9\u6211\u4eec\u4ece\u76f8\u5e94\u5730\u8bbe\u7f6e\u6c99\u76d2\u5f00\u59cb\uff1a<\/p>\n

echo \"Hello!\" >greeting.txt\r\ngit add greeting.txt\r\ngit commit -m\"Add greeting.txt\"\r\n\u00a0\r\necho \"Goodbye world!\" >farewell.txt\r\ngit add farewell.txt\r\ngit commit -m\"Add farewell.txt\"\r\n\r\n<\/pre>\n

\u770b\u8d77\u6765 greeting.txt \u50cf\u662f\u4e22\u5931\u4e86 \"world\"\u3002\u8ba9\u6211\u4eec\u6b63\u5e38\u5730\u5199\u4e2a\u63d0\u4ea4\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n

echo \"Hello world!\" >greeting.txt\r\ngit commit -a -m\"fixup greeting.txt\"<\/pre>\n

\u73b0\u5728\u6587\u4ef6\u770b\u8d77\u6765\u6b63\u786e\uff0c\u4f46\u662f\u6211\u4eec\u7684\u5386\u53f2\u8bb0\u5f55\u53ef\u4ee5\u66f4\u597d\u4e00\u70b9 \u2014\u2014 \u8ba9\u6211\u4eec\u4f7f\u7528\u65b0\u7684\u63d0\u4ea4\u6765\u201c\u4fee\u590d\u201d\uff08fixup\uff09\u6700\u540e\u4e00\u4e2a\u63d0\u4ea4\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u9700\u8981\u5f15\u5165\u4e00\u4e2a\u65b0\u5de5\u5177\uff1a\u4ea4\u4e92\u5f0f\u53d8\u57fa\u3002\u6211\u4eec\u5c06\u4ee5\u8fd9\u79cd\u65b9\u5f0f\u7f16\u8f91\u6700\u540e\u4e09\u4e2a\u63d0\u4ea4\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u8fd0\u884c git rebase -i HEAD~3\uff08-i \u4ee3\u8868\u4ea4\u4e92\u5f0f\uff09\u3002\u8fd9\u6837\u4f1a\u6253\u5f00\u6587\u672c\u7f16\u8f91\u5668\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

pick 8d3fc77 Add greeting.txt\r\npick 2a73a77 Add farewell.txt\r\npick 0b9d0bb fixup greeting.txt\r\n\u00a0\r\n# Rebase f5f19fb..0b9d0bb onto f5f19fb (3 commands)\r\n#\r\n# Commands:\r\n# p, pick <commit> = use commit\r\n# f, fixup <commit> = like \"squash\", but discard this commit's log message<\/pre>\n

\u662f\u53d8\u57fa\u8ba1\u5212\uff0c\u901a\u8fc7\u7f16\u8f91\u6b64\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u6307\u5bfc Git \u5982\u4f55\u7f16\u8f91\u5386\u53f2\u8bb0\u5f55\u3002\u6211\u5df2\u7ecf\u5c06\u8be5\u6458\u8981\u524a\u51cf\u4e3a\u4ec5\u4e0e\u53d8\u57fa\u8ba1\u5212\u8fd9\u4e00\u90e8\u5206\u76f8\u5173\u7684\u7ec6\u8282\uff0c\u4f46\u662f\u4f60\u53ef\u4ee5\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6d4f\u89c8\u5b8c\u6574\u7684\u6458\u8981\u3002<\/p>\n

\u5f53\u6211\u4eec\u4fdd\u5b58\u5e76\u5173\u95ed\u7f16\u8f91\u5668\u65f6\uff0cGit \u5c06\u4ece\u5176\u5386\u53f2\u8bb0\u5f55\u4e2d\u5220\u9664\u6240\u6709\u8fd9\u4e9b\u63d0\u4ea4\uff0c\u7136\u540e\u4e00\u6b21\u6267\u884c\u4e00\u884c\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u5c06\u9009\u53d6\uff08pick\uff09\u6bcf\u4e2a\u63d0\u4ea4\uff0c\u5c06\u5176\u4ece\u5806\u4e2d\u53ec\u5524\u51fa\u6765\u5e76\u6dfb\u52a0\u5230\u5206\u652f\u4e2d\u3002\u5982\u679c\u6211\u4eec\u5bf9\u6b64\u6587\u4ef6\u6839\u672c\u6ca1\u6709\u505a\u4efb\u4f55\u7f16\u8f91\uff0c\u5219\u5c06\u76f4\u63a5\u56de\u5230\u8d77\u70b9\uff0c\u6309\u539f\u6837\u9009\u53d6\u6bcf\u4e2a\u63d0\u4ea4\u3002\u73b0\u5728\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u6211\u6700\u559c\u6b22\u7684\u529f\u80fd\u4e4b\u4e00\uff1a\u4fee\u590d\uff08fixup\uff09\u3002\u7f16\u8f91\u7b2c\u4e09\u884c\uff0c\u5c06\u64cd\u4f5c\u4ece pick \u66f4\u6539\u4e3a fixup\uff0c\u5e76\u5c06\u5176\u7acb\u5373\u79fb\u81f3\u6211\u4eec\u8981\u201c\u4fee\u590d\u201d\u7684\u63d0\u4ea4\u4e4b\u540e\uff1a<\/p>\n

pick 8d3fc77 Add greeting.txt\r\nfixup 0b9d0bb fixup greeting.txt\r\npick 2a73a77 Add farewell.txt<\/pre>\n

\u6280\u5de7\uff1a\u6211\u4eec\u4e5f\u53ef\u4ee5\u53ea\u7528 f \u6765\u7f29\u5199\u5b83\uff0c\u4ee5\u52a0\u5feb\u4e0b\u6b21\u7684\u901f\u5ea6\u3002
\n\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\uff0cGit \u5c06\u8fd0\u884c\u8fd9\u4e9b\u547d\u4ee4\u3002\u6211\u4eec\u53ef\u4ee5\u68c0\u67e5\u65e5\u5fd7\u4ee5\u9a8c\u8bc1\u7ed3\u679c\uff1a<\/p>\n

$ git log -2 --oneline\r\nfcff6ae (HEAD -> master) Add farewell.txt\r\na479e94 Add greeting.txt<\/pre>\n
\u5c06\u591a\u4e2a\u63d0\u4ea4\u538b\u6241\u4e3a\u4e00\u4e2a<\/strong><\/div>\n

\u5728\u5de5\u4f5c\u65f6\uff0c\u5f53\u4f60\u8fbe\u5230\u8f83\u5c0f\u7684\u91cc\u7a0b\u7891\u6216\u4fee\u590d\u4ee5\u524d\u7684\u63d0\u4ea4\u4e2d\u7684\u9519\u8bef\u65f6\uff0c\u4f60\u53ef\u80fd\u4f1a\u53d1\u73b0\u5199\u5f88\u591a\u63d0\u4ea4\u5f88\u6709\u7528\u3002\u4f46\u662f\uff0c\u5728\u5c06\u4f60\u7684\u5de5\u4f5c\u5408\u5e76\u5230 master \u5206\u652f\u4e4b\u524d\uff0c\u5c06\u8fd9\u4e9b\u63d0\u4ea4\u201c\u538b\u6241\u201d\uff08squash\uff09\u5230\u4e00\u8d77\u4ee5\u4f7f\u5386\u53f2\u8bb0\u5f55\u66f4\u6e05\u6670\u53ef\u80fd\u5f88\u6709\u7528\u3002\u4e3a\u6b64\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u201c\u538b\u6241\u201d\uff08squash\uff09\u64cd\u4f5c\u3002\u8ba9\u6211\u4eec\u4ece\u7f16\u5199\u4e00\u5806\u63d0\u4ea4\u5f00\u59cb\uff0c\u5982\u679c\u8981\u52a0\u5feb\u901f\u5ea6\uff0c\u53ea\u9700\u590d\u5236\u5e76\u7c98\u8d34\u8fd9\u4e9b\uff1a<\/p>\n

git checkout -b squash\r\nfor c in H e l l o , ' ' w o r l d; do\r\necho \"$c\" >>squash.txt\r\ngit add squash.txt\r\ngit commit -m\"Add '$c' to squash.txt\"\r\ndone<\/pre>\n

\u8981\u5236\u4f5c\u51fa\u4e00\u4e2a\u5199\u7740 \u201cHello\uff0cworld\u201d \u7684\u6587\u4ef6\uff0c\u8981\u505a\u5f88\u591a\u4e8b\u60c5\uff01\u8ba9\u6211\u4eec\u5f00\u59cb\u53e6\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u53d8\u57fa\uff0c\u5c06\u5b83\u4eec\u538b\u6241\u5728\u4e00\u8d77\u3002\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u9996\u5148\u7b7e\u51fa\u4e86\u4e00\u4e2a\u5206\u652f\u6765\u8fdb\u884c\u5c1d\u8bd5\u3002\u56e0\u6b64\uff0c\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528 git rebase -i master\u00a0\u8fdb\u884c\u7684\u5206\u652f\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u53d8\u57fa\u6240\u6709\u63d0\u4ea4\u3002\u7ed3\u679c\uff1a<\/p>\n

pick 1e85199 Add 'H' to squash.txt\r\npick fff6631 Add 'e' to squash.txt\r\npick b354c74 Add 'l' to squash.txt\r\npick 04aaf74 Add 'l' to squash.txt\r\npick 9b0f720 Add 'o' to squash.txt\r\npick 66b114d Add ',' to squash.txt\r\npick dc158cd Add ' ' to squash.txt\r\npick dfcf9d6 Add 'w' to squash.txt\r\npick 7a85f34 Add 'o' to squash.txt\r\npick c275c27 Add 'r' to squash.txt\r\npick a513fd1 Add 'l' to squash.txt\r\npick 6b608ae Add 'd' to squash.txt\r\n\u00a0\r\n# Rebase 1af1b46..6b608ae onto 1af1b46 (12 commands)\r\n#\r\n# Commands:\r\n# p, pick <commit> = use commit\r\n# s, squash <commit> = use commit, but meld into previous commit<\/pre>\n

\u6280\u5de7\uff1a\u4f60\u7684\u672c\u5730 master \u5206\u652f\u72ec\u7acb\u4e8e\u8fdc\u7a0b master \u5206\u652f\u800c\u53d1\u5c55\uff0c\u5e76\u4e14 Git \u5c06\u8fdc\u7a0b\u5206\u652f\u5b58\u50a8\u4e3a origin\/master\u3002\u7ed3\u5408\u8fd9\u79cd\u6280\u5de7\uff0cgit rebase -i origin\/master \u901a\u5e38\u662f\u4e00\u79cd\u975e\u5e38\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u53d8\u57fa\u6240\u6709\u5c1a\u672a\u5408\u5e76\u5230\u4e0a\u6e38\u7684\u63d0\u4ea4\uff01
\n\u6211\u4eec\u5c06\u628a\u6240\u6709\u8fd9\u4e9b\u66f4\u6539\u538b\u6241\u5230\u7b2c\u4e00\u4e2a\u63d0\u4ea4\u4e2d\u3002\u4e3a\u6b64\uff0c\u5c06\u7b2c\u4e00\u884c\u9664\u5916\u7684\u6bcf\u4e2a\u201c\u9009\u53d6\u201d\uff08pick\uff09\u64cd\u4f5c\u90fd\u66f4\u6539\u4e3a\u201c\u538b\u6241\u201d\uff08squash\uff09\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

pick 1e85199 Add 'H' to squash.txt\r\nsquash fff6631 Add 'e' to squash.txt\r\nsquash b354c74 Add 'l' to squash.txt\r\nsquash 04aaf74 Add 'l' to squash.txt\r\nsquash 9b0f720 Add 'o' to squash.txt\r\nsquash 66b114d Add ',' to squash.txt\r\nsquash dc158cd Add ' ' to squash.txt\r\nsquash dfcf9d6 Add 'w' to squash.txt\r\nsquash 7a85f34 Add 'o' to squash.txt\r\nsquash c275c27 Add 'r' to squash.txt\r\nsquash a513fd1 Add 'l' to squash.txt\r\nsquash 6b608ae Add 'd' to squash.txt<\/pre>\n

\u4fdd\u5b58\u5e76\u5173\u95ed\u7f16\u8f91\u5668\u65f6\uff0cGit \u4f1a\u8003\u8651\u7247\u523b\uff0c\u7136\u540e\u518d\u6b21\u6253\u5f00\u7f16\u8f91\u5668\u4ee5\u4fee\u6539\u6700\u7ec8\u7684\u63d0\u4ea4\u6d88\u606f\u3002\u4f60\u4f1a\u770b\u5230\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

# This is a combination of 12 commits.\r\n# This is the 1st commit message:\r\n\u00a0\r\nAdd 'H' to squash.txt\r\n\u00a0\r\n# This is the commit message #2:\r\n\u00a0\r\nAdd 'e' to squash.txt\r\n\u00a0\r\n# This is the commit message #3:\r\n\u00a0\r\nAdd 'l' to squash.txt\r\n\u00a0\r\n# This is the commit message #4:\r\n\u00a0\r\nAdd 'l' to squash.txt\r\n\u00a0\r\n# This is the commit message #5:\r\n\u00a0\r\nAdd 'o' to squash.txt\r\n\u00a0\r\n# This is the commit message #6:\r\n\u00a0\r\nAdd ',' to squash.txt\r\n\u00a0\r\n# This is the commit message #7:\r\n\u00a0\r\nAdd ' ' to squash.txt\r\n\u00a0\r\n# This is the commit message #8:\r\n\u00a0\r\nAdd 'w' to squash.txt\r\n\u00a0\r\n# This is the commit message #9:\r\n\u00a0\r\nAdd 'o' to squash.txt\r\n\u00a0\r\n# This is the commit message #10:\r\n\u00a0\r\nAdd 'r' to squash.txt\r\n\u00a0\r\n# This is the commit message #11:\r\n\u00a0\r\nAdd 'l' to squash.txt\r\n\u00a0\r\n# This is the commit message #12:\r\n\u00a0\r\nAdd 'd' to squash.txt\r\n\u00a0\r\n# Please enter the commit message for your changes. Lines starting\r\n# with '#' will be ignored, and an empty message aborts the commit.\r\n#\r\n# Date: Sun Apr 28 14:21:56 2019 -0400\r\n#\r\n# interactive rebase in progress; onto 1af1b46\r\n# Last commands done (12 commands done):\r\n# squash a513fd1 Add 'l' to squash.txt\r\n# squash 6b608ae Add 'd' to squash.txt\r\n# No commands remaining.\r\n# You are currently rebasing branch 'squash' on '1af1b46'.\r\n#\r\n# Changes to be committed:\r\n# new file: squash.txt\r\n#<\/pre>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fd9\u662f\u6240\u6709\u8981\u538b\u6241\u7684\u63d0\u4ea4\u7684\u6d88\u606f\u7684\u7ec4\u5408\uff0c\u4f46\u662f\u50cf\u8fd9\u6837\u5c06\u5176\u4fdd\u7559\u80af\u5b9a\u4e0d\u662f\u4f60\u60f3\u8981\u7684\u3002\u4e0d\u8fc7\uff0c\u65e7\u7684\u63d0\u4ea4\u6d88\u606f\u5728\u7f16\u5199\u65b0\u7684\u63d0\u4ea4\u6d88\u606f\u65f6\u53ef\u80fd\u5f88\u6709\u7528\uff0c\u6240\u4ee5\u653e\u5728\u8fd9\u91cc\u4ee5\u4f9b\u53c2\u8003\u3002<\/p>\n

\u63d0\u793a\uff1a\u4f60\u5728\u4e0a\u4e00\u8282\u4e2d\u4e86\u89e3\u7684\u201c\u4fee\u590d\u201d\uff08fixup\uff09\u547d\u4ee4\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6b64\u76ee\u7684\uff0c\u4f46\u5b83\u4f1a\u4e22\u5f03\u538b\u6241\u7684\u63d0\u4ea4\u7684\u6d88\u606f\u3002
\n\u8ba9\u6211\u4eec\u5220\u9664\u6240\u6709\u5185\u5bb9\uff0c\u5e76\u7528\u66f4\u597d\u7684\u63d0\u4ea4\u6d88\u606f\u66ff\u6362\u5b83\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

Add squash.txt with contents \"Hello, world\"\r\n\u00a0\r\n# Please enter the commit message for your changes. Lines starting\r\n# with '#' will be ignored, and an empty message aborts the commit.\r\n#\r\n# Date: Sun Apr 28 14:21:56 2019 -0400\r\n#\r\n# interactive rebase in progress; onto 1af1b46\r\n# Last commands done (12 commands done):\r\n# squash a513fd1 Add 'l' to squash.txt\r\n# squash 6b608ae Add 'd' to squash.txt\r\n# No commands remaining.\r\n# You are currently rebasing branch 'squash' on '1af1b46'.\r\n#\r\n# Changes to be committed:\r\n# new file: squash.txt\r\n#<\/pre>\n

\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\uff0c\u7136\u540e\u68c0\u67e5\u4f60\u7684 Git \u65e5\u5fd7\uff0c\u6210\u529f\uff01<\/p>\n

commit c785f476c7dff76f21ce2cad7c51cf2af00a44b6 (HEAD -> squash)\r\nAuthor: Drew DeVault\r\nDate: Sun Apr 28 14:21:56 2019 -0400\r\n\u00a0\r\nAdd squash.txt with contents \"Hello, world\"<\/pre>\n

\u5728\u7ee7\u7eed\u4e4b\u524d\uff0c\u8ba9\u6211\u4eec\u5c06\u6240\u505a\u7684\u66f4\u6539\u62c9\u5165 master \u5206\u652f\u4e2d\uff0c\u5e76\u6446\u8131\u6389\u8fd9\u4e00\u8349\u7a3f\u3002\u6211\u4eec\u53ef\u4ee5\u50cf\u4f7f\u7528 git merge \u4e00\u6837\u4f7f\u7528 git rebase\uff0c\u4f46\u662f\u5b83\u907f\u514d\u4e86\u521b\u5efa\u5408\u5e76\u63d0\u4ea4\uff1a<\/p>\n

git checkout master\r\ngit rebase squash\r\ngit branch -D squash<\/pre>\n

\u9664\u975e\u6211\u4eec\u5b9e\u9645\u4e0a\u6b63\u5728\u5408\u5e76\u65e0\u5173\u7684\u5386\u53f2\u8bb0\u5f55\uff0c\u5426\u5219\u6211\u4eec\u901a\u5e38\u5e0c\u671b\u907f\u514d\u4f7f\u7528 git merge\u3002\u5982\u679c\u4f60\u6709\u4e24\u4e2a\u4e0d\u540c\u7684\u5206\u652f\uff0c\u5219 git merge \u5bf9\u4e8e\u8bb0\u5f55\u5b83\u4eec\u5408\u5e76\u7684\u65f6\u95f4\u975e\u5e38\u6709\u7528\u3002\u5728\u6b63\u5e38\u5de5\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u53d8\u57fa\u901a\u5e38\u66f4\u4e3a\u5408\u9002\u3002<\/p>\n

\n

\u5c06\u4e00\u4e2a\u63d0\u4ea4\u62c6\u5206\u4e3a\u591a\u4e2a<\/strong><\/div>\n<\/p>\n

\u6709\u65f6\u4f1a\u53d1\u751f\u76f8\u53cd\u7684\u95ee\u9898\uff1a\u4e00\u4e2a\u63d0\u4ea4\u592a\u5927\u4e86\u3002\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u770b\u62c6\u5206\u5b83\u4eec\u3002\u8fd9\u6b21\uff0c\u8ba9\u6211\u4eec\u5199\u4e00\u4e9b\u5b9e\u9645\u7684\u4ee3\u7801\u3002\u4ece\u4e00\u4e2a\u7b80\u5355\u7684 C \u7a0b\u5e8f\u5f00\u59cb\uff08\u4f60\u4ecd\u7136\u53ef\u4ee5\u5c06\u6b64\u4ee3\u7801\u6bb5\u590d\u5236\u5e76\u7c98\u8d34\u5230\u4f60\u7684 shell \u4e2d\u4ee5\u5feb\u901f\u6267\u884c\u6b64\u64cd\u4f5c\uff09\uff1a<\/p>\n

cat <<EOF >main.c\r\nint main(int argc, char *argv[]) {\r\nreturn 0;\r\n}\r\nEOF<\/pre>\n

\u9996\u5148\u63d0\u4ea4\u5b83\uff1a<\/p>\n

git add main.c\r\ngit commit -m\"Add C program skeleton\"<\/pre>\n

\u7136\u540e\u628a\u8fd9\u4e2a\u7a0b\u5e8f\u6269\u5c55\u4e00\u4e9b\uff1a<\/p>\n

cat <<EOF >main.c\r\n#include &ltstdio.h>\r\n\u00a0\r\nconst char *get_name() {\r\nstatic char buf[128];\r\nscanf(\"%s\", buf);\r\nreturn buf;\r\n}\r\n\u00a0\r\nint main(int argc, char *argv[]) {\r\nprintf(\"What's your name? \");\r\nconst char *name = get_name();\r\nprintf(\"Hello, %s!\\n\", name);\r\nreturn 0;\r\n}\r\nEOF<\/pre>\n

\u63d0\u4ea4\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u51c6\u5907\u5b66\u4e60\u5982\u4f55\u5c06\u5176\u62c6\u5206\uff1a<\/p>\n

git commit -a -m\"Flesh out C program\"<\/pre>\n

\u7b2c\u4e00\u6b65\u662f\u542f\u52a8\u4ea4\u4e92\u5f0f\u53d8\u57fa\u3002\u8ba9\u6211\u4eec\u7528 git rebase -i HEAD~2 \u6765\u53d8\u57fa\u8fd9\u4e24\u4e2a\u63d0\u4ea4\uff0c\u7ed9\u51fa\u7684\u53d8\u57fa\u8ba1\u5212\u5982\u4e0b\uff1a<\/p>\n

pick 237b246 Add C program skeleton\r\npick b3f188b Flesh out C program\r\n\u00a0\r\n# Rebase c785f47..b3f188b onto c785f47 (2 commands)\r\n#\r\n# Commands:\r\n# p, pick <commit> = use commit\r\n# e, edit <commit> = use commit, but stop for amending<\/pre>\n

\u5c06\u7b2c\u4e8c\u4e2a\u63d0\u4ea4\u7684\u547d\u4ee4\u4ece pick \u66f4\u6539\u4e3a edit\uff0c\u7136\u540e\u4fdd\u5b58\u5e76\u5173\u95ed\u7f16\u8f91\u5668\u3002Git \u4f1a\u8003\u8651\u4e00\u79d2\u949f\uff0c\u7136\u540e\u5411\u4f60\u5efa\u8bae\uff1a<\/p>\n

Stopped at b3f188b... Flesh out C program\r\nYou can amend the commit now, with\r\n\u00a0\r\ngit commit --amend\r\n\u00a0\r\nOnce you are satisfied with your changes, run\r\n\u00a0\r\ngit rebase --continue<\/pre>\n

\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u8bf4\u660e\u4e3a\u63d0\u4ea4\u6dfb\u52a0\u65b0\u7684\u66f4\u6539\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c git reset HEAD^ \u6765\u8fdb\u884c\u201c\u8f6f\u91cd\u7f6e\u201d 3\u3002\u5982\u679c\u5728\u6b64\u4e4b\u540e\u8fd0\u884c git status\uff0c\u4f60\u5c06\u770b\u5230\u5b83\u53d6\u6d88\u4e86\u63d0\u4ea4\u6700\u65b0\u7684\u63d0\u4ea4\uff0c\u5e76\u5c06\u5176\u66f4\u6539\u6dfb\u52a0\u5230\u5de5\u4f5c\u6811\u4e2d\uff1a<\/p>\n

Last commands done (2 commands done):\r\npick 237b246 Add C program skeleton\r\nedit b3f188b Flesh out C program\r\nNo commands remaining.\r\nYou are currently splitting a commit while rebasing branch 'master' on 'c785f47'.\r\n(Once your working directory is clean, run \"git rebase --continue\")\r\n\u00a0\r\nChanges not staged for commit:\r\n(use \"git add ...\" to update what will be committed)\r\n(use \"git checkout -- ...\" to discard changes in working directory)\r\n\u00a0\r\nmodified: main.c\r\n\u00a0\r\nno changes added to commit (use \"git add\" and\/or \"git commit -a\")<\/pre>\n

\u4e3a\u4e86\u5bf9\u6b64\u8fdb\u884c\u62c6\u5206\uff0c\u6211\u4eec\u5c06\u8fdb\u884c\u4ea4\u4e92\u5f0f\u63d0\u4ea4\u3002\u8fd9\u4f7f\u6211\u4eec\u80fd\u591f\u9009\u62e9\u6027\u5730\u4ec5\u63d0\u4ea4\u5de5\u4f5c\u6811\u4e2d\u7684\u7279\u5b9a\u66f4\u6539\u3002\u8fd0\u884c git commit -p \u5f00\u59cb\u6b64\u8fc7\u7a0b\uff0c\u4f60\u5c06\u770b\u5230\u4ee5\u4e0b\u63d0\u793a\uff1a<\/p>\n

diff --git a\/main.c b\/main.c\r\nindex b1d9c2c..3463610 100644\r\n--- a\/main.c\r\n+++ b\/main.c\r\n@@ -1,3 +1,14 @@\r\n+#include &ltstdio.h>\r\n+\r\n+const char *get_name() {\r\n+ static char buf[128];\r\n+ scanf(\"%s\", buf);\r\n+ return buf;\r\n+}\r\n+\r\nint main(int argc, char *argv[]) {\r\n+ printf(\"What's your name? \");\r\n+ const char *name = get_name();\r\n+ printf(\"Hello, %s!\\n\", name);\r\nreturn 0;\r\n}\r\nStage this hunk [y,n,q,a,d,s,e,?]?<\/pre>\n

Git \u4ec5\u5411\u4f60\u63d0\u4f9b\u4e86\u4e00\u4e2a\u201c\u5927\u5757\u201d\uff08\u5373\u5355\u4e2a\u66f4\u6539\uff09\u4ee5\u8fdb\u884c\u63d0\u4ea4\u3002\u4e0d\u8fc7\uff0c\u8fd9\u592a\u5927\u4e86\uff0c\u8ba9\u6211\u4eec\u4f7f\u7528 s<\/code> \u547d\u4ee4\u5c06\u8fd9\u4e2a\u201c\u5927\u5757\u201d\u62c6\u5206\u6210\u8f83\u5c0f\u7684\u90e8\u5206\u3002<\/p>\n

Split into 2 hunks.\r\n@@ -1 +1,9 @@\r\n+#include <stdio.h>\r\n+\r\n+const char *get_name() {\r\n+ static char buf[128];\r\n+ scanf(\"%s\", buf);\r\n+ return buf;\r\n+}\r\n+\r\nint main(int argc, char *argv[]) {\r\nStage this hunk [y,n,q,a,d,j,J,g,\/,e,?]?<\/pre>\n

\u63d0\u793a\uff1a\u5982\u679c\u4f60\u5bf9\u5176\u4ed6\u9009\u9879\u611f\u5230\u597d\u5947\uff0c\u8bf7\u6309 ? \u6c47\u603b\u663e\u793a\u3002
\n\u8fd9\u4e2a\u5927\u5757\u770b\u8d77\u6765\u66f4\u597d\uff1a\u5355\u4e00\u3001\u72ec\u7acb\u7684\u66f4\u6539\u3002\u8ba9\u6211\u4eec\u6309 y \u6765\u56de\u7b54\u95ee\u9898\uff08\u5e76\u6682\u5b58\u90a3\u4e2a\u201c\u5927\u5757\u201d\uff09\uff0c\u7136\u540e\u6309 q \u4ee5\u201c\u9000\u51fa\u201d\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\u5e76\u7ee7\u7eed\u8fdb\u884c\u63d0\u4ea4\u3002\u4f1a\u5f39\u51fa\u7f16\u8f91\u5668\uff0c\u8981\u6c42\u8f93\u5165\u5408\u9002\u7684\u63d0\u4ea4\u6d88\u606f\u3002<\/p>\n

Add get_name function to C program\r\n\u00a0\r\n# Please enter the commit message for your changes. Lines starting\r\n# with '#' will be ignored, and an empty message aborts the commit.\r\n#\r\n# interactive rebase in progress; onto c785f47\r\n# Last commands done (2 commands done):\r\n# pick 237b246 Add C program skeleton\r\n# edit b3f188b Flesh out C program\r\n# No commands remaining.\r\n# You are currently splitting a commit while rebasing branch 'master' on 'c785f47'.\r\n#\r\n# Changes to be committed:\r\n# modified: main.c\r\n#\r\n# Changes not staged for commit:\r\n# modified: main.c\r\n#<\/pre>\n

\u4fdd\u5b58\u5e76\u5173\u95ed\u7f16\u8f91\u5668\uff0c\u7136\u540e\u6211\u4eec\u8fdb\u884c\u7b2c\u4e8c\u6b21\u63d0\u4ea4\u3002\u6211\u4eec\u53ef\u4ee5\u6267\u884c\u53e6\u4e00\u6b21\u4ea4\u4e92\u5f0f\u63d0\u4ea4\uff0c\u4f46\u662f\u7531\u4e8e\u6211\u4eec\u53ea\u60f3\u5728\u6b64\u63d0\u4ea4\u4e2d\u5305\u62ec\u5176\u4f59\u66f4\u6539\uff0c\u56e0\u6b64\u6211\u4eec\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n

git commit -a -m\"Prompt user for their name\"\r\ngit rebase --continuegit commit -a -m\"Prompt user for their name\"\r\ngit rebase --continue<\/pre>\n

\u6700\u540e\u4e00\u6761\u547d\u4ee4\u544a\u8bc9 Git \u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u6b64\u63d0\u4ea4\u7684\u7f16\u8f91\uff0c\u5e76\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u4e2a\u53d8\u57fa\u547d\u4ee4\u3002\u8fd9\u6837\u5c31\u884c\u4e86\uff01\u8fd0\u884c git log \u6765\u67e5\u770b\u4f60\u7684\u52b3\u52a8\u6210\u679c\uff1a<\/p>\n

$ git log -3 --oneline\r\nfe19cc3 (HEAD -> master) Prompt user for their name\r\n659a489 Add get_name function to C program\r\n237b246 Add C program skeleton<\/pre>\n

\n

\u91cd\u65b0\u6392\u5e8f\u63d0\u4ea4<\/strong><\/div>\n<\/p>\n

\u8fd9\u5f88\u7b80\u5355\u3002\u8ba9\u6211\u4eec\u4ece\u8bbe\u7f6e\u6c99\u7bb1\u5f00\u59cb\uff1a<\/p>\n

echo \"Goodbye now!\" >farewell.txt\r\ngit add farewell.txt\r\ngit commit -m\"Add farewell.txt\"\r\n\u00a0\r\necho \"Hello there!\" >greeting.txt\r\ngit add greeting.txt\r\ngit commit -m\"Add greeting.txt\"\r\n\u00a0\r\necho \"How're you doing?\" >inquiry.txt\r\ngit add inquiry.txt\r\ngit commit -m\"Add inquiry.txt\"<\/pre>\n

\u73b0\u5728 git log \u770b\u8d77\u6765\u5e94\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

f03baa5 (HEAD -> master) Add inquiry.txt\r\na4cebf7 Add greeting.txt\r\n90bb015 Add farewell.txt<\/pre>\n

\u663e\u7136\uff0c\u8fd9\u90fd\u662f\u4e71\u5e8f\u3002\u8ba9\u6211\u4eec\u5bf9\u8fc7\u53bb\u7684 3 \u4e2a\u63d0\u4ea4\u8fdb\u884c\u4ea4\u4e92\u5f0f\u53d8\u57fa\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u8fd0\u884c git rebase -i HEAD~3\uff0c\u8fd9\u4e2a\u53d8\u57fa\u89c4\u5212\u5c06\u51fa\u73b0\uff1a<\/p>\n

pick 90bb015 Add farewell.txt\r\npick a4cebf7 Add greeting.txt\r\npick f03baa5 Add inquiry.txt\r\n\u00a0\r\n# Rebase fe19cc3..f03baa5 onto fe19cc3 (3 commands)\r\n#\r\n# Commands:\r\n# p, pick <commit> = use commit\r\n#\r\n# These lines can be re-ordered; they are executed from top to bottom.<\/pre>\n

\u73b0\u5728\uff0c\u89e3\u51b3\u65b9\u6cd5\u5f88\u7b80\u5355\uff1a\u53ea\u9700\u6309\u7167\u4f60\u5e0c\u671b\u63d0\u4ea4\u51fa\u73b0\u7684\u987a\u5e8f\u91cd\u65b0\u6392\u5217\u8fd9\u4e9b\u884c\u3002\u5e94\u8be5\u770b\u8d77\u6765\u50cf\u8fd9\u6837\uff1a<\/p>\n

pick a4cebf7 Add greeting.txt\r\npick f03baa5 Add inquiry.txt\r\npick 90bb015 Add farewell.txt<\/pre>\n

\u4fdd\u5b58\u5e76\u5173\u95ed\u4f60\u7684\u7f16\u8f91\u5668\uff0c\u800c Git \u5c06\u4e3a\u4f60\u5b8c\u6210\u5176\u4f59\u5de5\u4f5c\u3002\u8bf7\u6ce8\u610f\uff0c\u5728\u5b9e\u8df5\u4e2d\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u51b2\u7a81\uff0c\u53c2\u770b\u4e0b\u9762\u7ae0\u8282\u4ee5\u83b7\u53d6\u89e3\u51b3\u51b2\u7a81\u7684\u5e2e\u52a9\u3002<\/p>\n

git pull \u2013rebase<\/strong><\/div>\n

\u5982\u679c\u4f60\u4e00\u76f4\u5728\u7531\u4e0a\u6e38\u66f4\u65b0\u7684\u5206\u652f <branch>\uff08\u6bd4\u5982\u8bf4\u539f\u59cb\u8fdc\u7a0b\uff09\u4e0a\u505a\u4e00\u4e9b\u63d0\u4ea4\uff0c\u901a\u5e38 git pull \u4f1a\u521b\u5efa\u4e00\u4e2a\u5408\u5e76\u63d0\u4ea4\u3002\u5728\u8fd9\u65b9\u9762\uff0cgit pull \u7684\u9ed8\u8ba4\u884c\u4e3a\u7b49\u540c\u4e8e\uff1a<\/p>\n

git fetch origin <branch>\r\ngit merge origin\/<branch><\/pre>\n

\u5047\u8bbe\u672c\u5730\u5206\u652f <branch> \u914d\u7f6e\u4e3a\u4ece\u539f\u59cb\u8fdc\u7a0b\u8ddf\u8e2a <branch> \u5206\u652f\uff0c\u5373\uff1a<\/p>\n

$ git config branch.<branch>.remote\r\norigin\r\n$ git config branch.<branch>.merge\r\nrefs\/heads\/<branch><\/pre>\n

\u8fd8\u6709\u53e6\u4e00\u79cd\u9009\u62e9\uff0c\u5b83\u901a\u5e38\u66f4\u6709\u7528\uff0c\u5e76\u4e14\u4f1a\u8ba9\u5386\u53f2\u8bb0\u5f55\u66f4\u6e05\u6670\uff1agit pull --rebase\u3002\u4e0e\u5408\u5e76\u65b9\u5f0f\u4e0d\u540c\uff0c\u8fd9\u57fa\u672c\u4e0a 4<\/a><\/sup> \u7b49\u6548\u4e8e\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n

git fetch origin\r\ngit rebase origin\/<branch><\/pre>\n

\u5408\u5e76\u65b9\u5f0f\u66f4\u7b80\u5355\u6613\u61c2\uff0c\u4f46\u662f\u5982\u679c\u4f60\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 git rebase\uff0c\u90a3\u4e48\u53d8\u57fa\u65b9\u5f0f\u51e0\u4e4e\u53ef\u4ee5\u505a\u5230\u4f60\u60f3\u8981\u505a\u7684\u4efb\u4f55\u4e8b\u60c5\u3002\u5982\u679c\u613f\u610f\uff0c\u53ef\u4ee5\u5c06\u5176\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u884c\u4e3a\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

git config --global pull.rebase true<\/pre>\n

\u5f53\u4f60\u6267\u884c\u6b64\u64cd\u4f5c\u65f6\uff0c\u4ece\u6280\u672f\u4e0a\u8bb2\uff0c\u4f60\u5728\u5e94\u7528\u6211\u4eec\u5728\u4e0b\u4e00\u8282\u4e2d\u8ba8\u8bba\u7684\u8fc7\u7a0b\u2026\u2026\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u4e5f\u89e3\u91ca\u4e00\u4e0b\u6545\u610f\u6267\u884c\u6b64\u64cd\u4f5c\u7684\u542b\u4e49\u3002<\/p>\n

\u4f7f\u7528 git rebase \u6765\u53d8\u57fa<\/strong><\/div>\n

\u5177\u6709\u8bbd\u523a\u610f\u5473\u7684\u662f\uff0c\u6211\u6700\u5c11\u4f7f\u7528\u7684 Git \u53d8\u57fa\u529f\u80fd\u662f\u5b83\u4ee5\u4e4b\u547d\u540d\u7684\u529f\u80fd\uff1a\u53d8\u57fa\u5206\u652f\u3002\u5047\u8bbe\u4f60\u6709\u4ee5\u4e0b\u5206\u652f\uff1a<\/p>\n

A--B--C--D--> master\r\n\\--E--F--> feature-1\r\n\\--G--> feature-2<\/pre>\n

\u4e8b\u5b9e\u8bc1\u660e\uff0cfeature-2 \u4e0d\u4f9d\u8d56\u4e8e feature-1 \u7684\u4efb\u4f55\u66f4\u6539\uff0c\u5b83\u4f9d\u8d56\u4e8e\u63d0\u4ea4 E\uff0c\u56e0\u6b64\u4f60\u53ef\u4ee5\u5c06\u5176\u4f5c\u4e3a\u57fa\u7840\u8131\u79bb master\u3002\u56e0\u6b64\uff0c\u89e3\u51b3\u65b9\u6cd5\u662f\uff1a<\/p>\n

git rebase --onto master feature-1 feature-2<\/pre>\n

\u975e\u4ea4\u4e92\u5f0f\u53d8\u57fa\u5bf9\u6240\u6709\u7275\u8fde\u7684\u63d0\u4ea4\u90fd\u6267\u884c\u9ed8\u8ba4\u64cd\u4f5c\uff08pick\uff09 \uff0c\u5b83\u53ea\u662f\u7b80\u5355\u5730\u5c06\u4e0d\u5728 feature-1 \u4e2d\u7684 feature-2 \u4e2d\u63d0\u4ea4\u91cd\u653e\u5230 master \u4e0a\u3002\u4f60\u7684\u5386\u53f2\u8bb0\u5f55\u73b0\u5728\u770b\u8d77\u6765\u50cf\u8fd9\u6837\uff1a<\/p>\n

A--B--C--D--> master\r\n| \\--G--> feature-2\r\n\\--E--F--> feature-1<\/pre>\n
\u89e3\u51b3\u51b2\u7a81<\/strong><\/div>\n

\u89e3\u51b3\u5408\u5e76\u51b2\u7a81\u7684\u8be6\u7ec6\u4fe1\u606f\u4e0d\u5728\u672c\u6307\u5357\u7684\u8303\u56f4\u5185\uff0c\u5c06\u6765\u8bf7\u4f60\u6ce8\u610f\u53e6\u4e00\u7bc7\u6307\u5357\u3002\u5047\u8bbe\u4f60\u719f\u6089\u901a\u5e38\u7684\u89e3\u51b3\u51b2\u7a81\u7684\u65b9\u6cd5\uff0c\u90a3\u4e48\u8fd9\u91cc\u662f\u4e13\u95e8\u9002\u7528\u4e8e\u53d8\u57fa\u7684\u90e8\u5206\u3002<\/p>\n

\u6709\u65f6\uff0c\u5728\u8fdb\u884c\u53d8\u57fa\u65f6\u4f1a\u9047\u5230\u5408\u5e76\u51b2\u7a81\uff0c\u4f60\u53ef\u4ee5\u50cf\u5904\u7406\u5176\u4ed6\u4efb\u4f55\u5408\u5e76\u51b2\u7a81\u4e00\u6837\u5904\u7406\u8be5\u51b2\u7a81\u3002Git \u5c06\u5728\u53d7\u5f71\u54cd\u7684\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u51b2\u7a81\u6807\u8bb0\uff0cgit status \u5c06\u663e\u793a\u4f60\u9700\u8981\u89e3\u51b3\u7684\u95ee\u9898\uff0c\u5e76\u4e14\u4f60\u53ef\u4ee5\u4f7f\u7528 git add \u6216 git rm \u5c06\u6587\u4ef6\u6807\u8bb0\u4e3a\u5df2\u89e3\u51b3\u3002\u4f46\u662f\uff0c\u5728 git rebase \u7684\u4e0a\u4e0b\u6587\u4e2d\uff0c\u4f60\u5e94\u8be5\u6ce8\u610f\u4e24\u4e2a\u9009\u9879\u3002<\/p>\n

\u9996\u5148\u662f\u5982\u4f55\u5b8c\u6210\u51b2\u7a81\u89e3\u51b3\u3002\u89e3\u51b3\u7531\u4e8e git merge \u5f15\u8d77\u7684\u51b2\u7a81\u65f6\uff0c\u4e0e\u5176\u4f7f\u7528 git commit \u90a3\u6837\u7684\u547d\u4ee4\uff0c\u66f4\u9002\u5f53\u7684\u53d8\u57fa\u547d\u4ee4\u662f git rebase --continue\u3002\u4f46\u662f\uff0c\u8fd8\u6709\u4e00\u4e2a\u53ef\u7528\u7684\u9009\u9879\uff1agit rebase --skip\u3002 \u8fd9\u5c06\u8df3\u8fc7\u4f60\u6b63\u5728\u5904\u7406\u7684\u63d0\u4ea4\uff0c\u5b83\u4e0d\u4f1a\u5305\u542b\u5728\u53d8\u57fa\u4e2d\u3002\u8fd9\u5728\u6267\u884c\u975e\u4ea4\u4e92\u6027\u53d8\u57fa\u65f6\u6700\u5e38\u89c1\uff0c\u8fd9\u65f6 Git \u4e0d\u4f1a\u610f\u8bc6\u5230\u5b83\u4ece\u201c\u5176\u4ed6\u201d\u5206\u652f\u4e2d\u63d0\u53d6\u7684\u63d0\u4ea4\u662f\u4e0e\u201c\u6211\u4eec\u201d\u5206\u652f\u4e0a\u51b2\u7a81\u7684\u63d0\u4ea4\u7684\u66f4\u65b0\u7248\u672c\u3002<\/p>\n

\u5e2e\u5e2e\u6211\uff01 \u6211\u628a\u5b83\u5f04\u574f\u4e86\uff01<\/strong><\/div>\n

\u6beb\u65e0\u7591\u95ee\uff0c\u53d8\u57fa\u6709\u65f6\u4f1a\u5f88\u96be\u3002\u5982\u679c\u4f60\u72af\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c\u5e76\u56e0\u6b64\u800c\u4e22\u5931\u4e86\u6240\u9700\u7684\u63d0\u4ea4\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528 git reflog \u6765\u8282\u7701\u4e0b\u4e00\u5929\u7684\u65f6\u95f4\u3002\u8fd0\u884c\u6b64\u547d\u4ee4\u5c06\u5411\u4f60\u663e\u793a\u66f4\u6539\u4e00\u4e2a\u5f15\u7528\uff08\u5373\u5206\u652f\u548c\u6807\u8bb0\uff09\u7684\u6bcf\u4e2a\u64cd\u4f5c\u3002\u6bcf\u884c\u663e\u793a\u4f60\u7684\u65e7\u5f15\u7528\u6240\u6307\u5411\u7684\u5185\u5bb9\uff0c\u4f60\u53ef\u5bf9\u4f60\u8ba4\u4e3a\u4e22\u5931\u7684 Git \u63d0\u4ea4\u6267\u884c git cherry-pick\u3001git checkout\u3001git show \u6216\u4efb\u4f55\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n

\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e2a\u7a7a\u7684\u521d\u59cb\u63d0\u4ea4\u4ee5\u7b80\u5316\u672c\u6559\u7a0b\u7684\u5176\u4f59\u90e8\u5206\uff0c\u56e0\u4e3a\u8981\u5bf9\u7248\u672c\u5e93\u7684\u521d\u59cb\u63d0\u4ea4\u8fdb\u884c\u53d8\u57fa\u9700\u8981\u7279\u6b8a\u7684\u547d\u4ee4\uff08\u5373git rebase --root\uff09\u3002<\/p>\n

\u5982\u679c\u8981\u7f16\u8bd1\u6b64\u7a0b\u5e8f\uff0c\u8bf7\u8fd0\u884c cc -o main main.c\uff0c\u7136\u540e\u8fd0\u884c .\/main \u67e5\u770b\u7ed3\u679c\u3002<\/p>\n

\u5b9e\u9645\u4e0a\uff0c\u8fd9\u662f\u201c\u6df7\u5408\u91cd\u7f6e\u201d\u3002\u201c\u8f6f\u91cd\u7f6e\u201d\uff08\u4f7f\u7528 git reset --soft \u5b8c\u6210\uff09\u5c06\u6682\u5b58\u66f4\u6539\uff0c\u56e0\u6b64\u4f60\u65e0\u9700\u518d\u6b21 git add \u6dfb\u52a0\u5b83\u4eec\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e00\u6b21\u6027\u63d0\u4ea4\u6240\u6709\u66f4\u6539\u3002\u8fd9\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u3002\u6211\u4eec\u5e0c\u671b\u9009\u62e9\u6027\u5730\u6682\u5b58\u90e8\u5206\u66f4\u6539\uff0c\u4ee5\u62c6\u5206\u63d0\u4ea4\u3002<\/p>\n

\u5b9e\u9645\u4e0a\uff0c\u8fd9\u53d6\u51b3\u4e8e\u4e0a\u6e38\u5206\u652f\u672c\u8eab\u662f\u5426\u5df2\u53d8\u57fa\u6216\u5220\u9664\/\u538b\u6241\u4e86\u67d0\u4e9b\u63d0\u4ea4\u3002git pull --rebase \u5c1d\u8bd5\u901a\u8fc7\u5728 git rebase \u548c git merge-base \u4e2d\u4f7f\u7528 \u201c\u590d\u523b\u70b9fork-point\u201d \u673a\u5236\u6765\u4ece\u8fd9\u79cd\u60c5\u51b5\u4e2d\u6062\u590d\uff0c\u4ee5\u907f\u514d\u53d8\u57fa\u975e\u672c\u5730\u63d0\u4ea4\u3002<\/p>\n

\u5b9e\u9645\u4e0a\uff0c\u8fd9\u53d6\u51b3\u4e8e Git \u7684\u7248\u672c\u3002\u76f4\u5230 2.26.0 \u7248\uff0c\u9ed8\u8ba4\u7684\u975e\u4ea4\u4e92\u884c\u4e3a\u4ee5\u524d\u4e0e\u4ea4\u4e92\u884c\u4e3a\u7a0d\u6709\u4e0d\u540c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u901a\u5e38\u5e76\u4e0d\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff1a\u4e00\u822c\u5efa\u8bae\u4e0d\u8981\u4fee\u6539\u516c\u5171\u5206\u652f\u3001\u5171\u4eab\u5206\u652f\u6216\u7a33\u5b9a\u5206\u652f\u7684\u5386\u53f2\u8bb0\u5f55\u3002\u7f16\u8f91\u7279\u6027\u5206\u652f\u548c\u4e2a\u4eba\u5206\u652f\u7684\u5386\u53f2\u8bb0\u5f55\u662f\u53ef\u4ee5\u7684 […]<\/p>\n","protected":false},"author":323,"featured_media":95067,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-193250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=193250"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193250\/revisions"}],"predecessor-version":[{"id":193302,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/193250\/revisions\/193302"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/95067"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=193250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=193250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=193250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}