[{"data":1,"prerenderedAt":377},["ShallowReactive",2],{"/2025/04/04/git-tongbu":3,"surround-/2025/04/04/git-tongbu":225,"toc-/2025/04/04/git-tongbu":236},{"id":4,"title":5,"body":6,"categories":202,"date":204,"description":205,"draft":206,"extension":207,"image":208,"meta":209,"navigation":210,"path":211,"readingTime":212,"recommend":190,"references":217,"seo":218,"stem":219,"tags":220,"type":217,"updated":223,"__hash__":224},"content/posts/2025/04/04/Git-tongbu.md","Git 同步上游仓库的更新",{"type":7,"value":8,"toc":189},"minimark",[9,13,17,20,24,32,42,45,48,54,57,60,66,69,75,78,84,87,90,93,99,102,108,111,114,117,123,126,132,161,164,170,180,183],[10,11,5],"h2",{"id":12},"git-同步上游仓库的更新",[14,15,16],"p",{},"　　使用一个 Github Template 创建了我自己的仓库，需要同步一下补丁更新，总不能自己手抄一遍吧，搜了一下解决方案。",[14,18,19],{},"　　记录一下。",[21,22,23],"h3",{"id":23},"添加上游仓库",[14,25,26,27,31],{},"　　给上游仓库取个名字，如果将命名为 ",[28,29,30],"code",{"code":30},"upstream","​ ，可以在本地仓库中运行以下命令：",[33,34,40],"pre",{"className":35,"code":37,"language":38,"meta":39},[36],"language-sh","git remote add upstream https://github.com/$\u003Cupstream-repo>.git\n","sh","",[28,41,37],{"__ignoreMap":39},[21,43,44],{"id":44},"获取上游仓库的更改",[14,46,47],{},"　　运行以下命令以获取上游仓库中的所有分支和提交：",[33,49,52],{"className":50,"code":51,"language":38,"meta":39},[36],"git fetch upstream\n",[28,53,51],{"__ignoreMap":39},[21,55,56],{"id":56},"合并上游更改",[14,58,59],{},"　　现在，将上游 main 分支的更改合并到您的本地 main 分支：",[33,61,64],{"className":62,"code":63,"language":38,"meta":39},[36],"git merge upstream/main --allow-unrelated-histories\n",[28,65,63],{"__ignoreMap":39},[14,67,68],{},"　　如果只需要合并特定的 commit ：",[33,70,73],{"className":71,"code":72,"language":38,"meta":39},[36],"git cherry-pick \u003Ccommit-hash>\n",[28,74,72],{"__ignoreMap":39},[14,76,77],{},"　　也可以使用",[33,79,82],{"className":80,"code":81,"language":38,"meta":39},[36],"gcp \u003Ccommit-hash>\n",[28,83,81],{"__ignoreMap":39},[14,85,86],{},"　　commit-hash 可以直接从 github 网页上复制。",[14,88,89],{},"　　这时 commit 的作者是源仓库的作者， Vercel 提示我 Build 失败，需要升级到 Pro，可以再修改一个文件，自己添加一条 commit 。",[14,91,92],{},"　　当然这很不优雅，可以使用下面的命令获取更改到文件，但是不会提交 commit ，",[33,94,97],{"className":95,"code":96,"language":38,"meta":39},[36],"git cherry-pick \u003Ccommit-hash> --no-commit\n",[28,98,96],{"__ignoreMap":39},[14,100,101],{},"　　然后手动提交一下",[33,103,106],{"className":104,"code":105,"language":38,"meta":39},[36],"git commit -m \"commit information\"\n",[28,107,105],{"__ignoreMap":39},[21,109,110],{"id":110},"解决冲突",[14,112,113],{},"　　如何自己已经修改过源代码，在合并过程中可能发生冲突，需要手动解决。\nGit 也会进行提示，手动编辑冲突文件并保存，然后再提交更改。",[21,115,116],{"id":116},"批量提交",[33,118,121],{"className":119,"code":120,"language":38,"meta":39},[36],"git cherry-pick \u003C起始提交>^..\u003C结束提交>\n",[28,122,120],{"__ignoreMap":39},[14,124,125],{},"　　如果有冲突会按照顺序处理，然后执行， continue 直到结束",[33,127,130],{"className":128,"code":129,"language":38,"meta":39},[36],"git cherry-pick --continue\n",[28,131,129],{"__ignoreMap":39},[133,134,135,143,149,155],"ul",{},[136,137,138,139,142],"li",{},"​",[28,140,141],{"code":141},"\u003C起始提交>","​：范围的开始点（不包含此提交，除非用 \u003C起始提交>~ 或 \u003C起始提交>^）。",[136,144,138,145,148],{},[28,146,147],{"code":147},"\u003C结束提交>","​：范围的结束点（包含此提交）。",[136,150,138,151,154],{},[28,152,153],{"code":153},"^","​ 是 Git 的语法，用于指定“之前的提交”。",[136,156,138,157,160],{},[28,158,159],{"code":159},"..","​ 表示范围。",[21,162,163],{"id":163},"推送",[33,165,168],{"className":166,"code":167,"language":38,"meta":39},[36],"git push origin main\n",[28,169,167],{"__ignoreMap":39},[14,171,172,173,175,176,179],{},"　　当然默认来说，并不会推送到新加入的 ",[28,174,30],{"code":30},"​ ，直接 ",[28,177,178],{"code":178},"git push","​ 即可",[14,181,182],{},"　　如果不再需要同步，可以删除上游的仓库",[33,184,187],{"className":185,"code":186,"language":38,"meta":39},[36],"git remote remove upstream\n",[28,188,186],{"__ignoreMap":39},{"title":39,"searchDepth":190,"depth":190,"links":191},4,[192],{"id":12,"depth":193,"text":5,"children":194},2,[195,197,198,199,200,201],{"id":23,"depth":196,"text":23},3,{"id":44,"depth":196,"text":44},{"id":56,"depth":196,"text":56},{"id":110,"depth":196,"text":110},{"id":116,"depth":196,"text":116},{"id":163,"depth":196,"text":163},[203],"技术分享","2025-04-04 20:13:15","如何同步上游仓库的更新到你的本地仓库。",false,"md","https://i1.wp.com/dev.ruom.top/i/2025/04/07/995956.webp",{},true,"/2025/04/04/git-tongbu",{"text":213,"minutes":214,"time":215,"words":216},"3 min read",2.455,147300,491,null,{"title":5,"description":205},"posts/2025/04/04/Git-tongbu",[221,222],"教程","Git","2025-04-04 20:16:59","9zfqUQ9s4sHtnVMfKrqJe7CU0ht3m4rHi0XpmcflXLM",[226,231],{"title":227,"path":228,"stem":229,"date":230,"type":217,"children":-1},"Markdown 换行语法","/2025/06/28-1/markdown-huanhang","posts/2025/06/28-1/markdown-huanhang","2025-06-28 22:45:50",{"title":232,"path":233,"stem":234,"date":235,"type":217,"children":-1},"Umami博客访问统计Vercel+Cloudflare Wokers部署","/2025/04/06/umami-deploy-cloudflare","posts/2025/04/06/Umami-deploy-cloudflare","2025-04-06 23:25:55",{"id":4,"title":5,"body":237,"categories":372,"date":204,"description":205,"draft":206,"extension":207,"image":208,"meta":373,"navigation":210,"path":211,"readingTime":374,"recommend":190,"references":217,"seo":375,"stem":219,"tags":376,"type":217,"updated":223,"__hash__":224},{"type":7,"value":238,"toc":362},[239,241,243,245,247,251,256,258,260,265,267,269,274,276,281,283,288,290,292,294,299,301,306,308,310,312,317,319,324,342,344,349,355,357],[10,240,5],{"id":12},[14,242,16],{},[14,244,19],{},[21,246,23],{"id":23},[14,248,26,249,31],{},[28,250,30],{"code":30},[33,252,254],{"className":253,"code":37,"language":38,"meta":39},[36],[28,255,37],{"__ignoreMap":39},[21,257,44],{"id":44},[14,259,47],{},[33,261,263],{"className":262,"code":51,"language":38,"meta":39},[36],[28,264,51],{"__ignoreMap":39},[21,266,56],{"id":56},[14,268,59],{},[33,270,272],{"className":271,"code":63,"language":38,"meta":39},[36],[28,273,63],{"__ignoreMap":39},[14,275,68],{},[33,277,279],{"className":278,"code":72,"language":38,"meta":39},[36],[28,280,72],{"__ignoreMap":39},[14,282,77],{},[33,284,286],{"className":285,"code":81,"language":38,"meta":39},[36],[28,287,81],{"__ignoreMap":39},[14,289,86],{},[14,291,89],{},[14,293,92],{},[33,295,297],{"className":296,"code":96,"language":38,"meta":39},[36],[28,298,96],{"__ignoreMap":39},[14,300,101],{},[33,302,304],{"className":303,"code":105,"language":38,"meta":39},[36],[28,305,105],{"__ignoreMap":39},[21,307,110],{"id":110},[14,309,113],{},[21,311,116],{"id":116},[33,313,315],{"className":314,"code":120,"language":38,"meta":39},[36],[28,316,120],{"__ignoreMap":39},[14,318,125],{},[33,320,322],{"className":321,"code":129,"language":38,"meta":39},[36],[28,323,129],{"__ignoreMap":39},[133,325,326,330,334,338],{},[136,327,138,328,142],{},[28,329,141],{"code":141},[136,331,138,332,148],{},[28,333,147],{"code":147},[136,335,138,336,154],{},[28,337,153],{"code":153},[136,339,138,340,160],{},[28,341,159],{"code":159},[21,343,163],{"id":163},[33,345,347],{"className":346,"code":167,"language":38,"meta":39},[36],[28,348,167],{"__ignoreMap":39},[14,350,172,351,175,353,179],{},[28,352,30],{"code":30},[28,354,178],{"code":178},[14,356,182],{},[33,358,360],{"className":359,"code":186,"language":38,"meta":39},[36],[28,361,186],{"__ignoreMap":39},{"title":39,"searchDepth":190,"depth":190,"links":363},[364],{"id":12,"depth":193,"text":5,"children":365},[366,367,368,369,370,371],{"id":23,"depth":196,"text":23},{"id":44,"depth":196,"text":44},{"id":56,"depth":196,"text":56},{"id":110,"depth":196,"text":110},{"id":116,"depth":196,"text":116},{"id":163,"depth":196,"text":163},[203],{},{"text":213,"minutes":214,"time":215,"words":216},{"title":5,"description":205},[221,222],1757075508055]