更新博客上游代码

要更新你在 GitHub 上 fork 的 Astro 模板 添加上游仓库 首先,将原始仓库添加为上游远程仓库: git remote add upstream https://github.com/原始仓库所有者/原始仓库名.git 获取上游更改 从上游仓库获取最新的更改: git fetch upstream 合并上游更改 将上游的更改合并到你的本地主分支: git checkout main # 切换到你的主分支 git merge upstream/main # 合并上游的更改,保留上游的commit 这里一般会有冲突,需要解决冲突 如果上游并不是以 fork 的方式获取,在 merge 的时候会提示fatal: refusing to merge unrelated histories 此时需要添加参数 –allow-unrelated-histories # 合并上游的更改,保留上游的commit git merge upstream/main --allow-unrelated-histories # 合并上游的更改,压缩上游的commit git merge upstream/main --allow-unrelated-histories --squash 推送更改到你的 GitHub 仓库 将合并后的更改推送到你的 GitHub 仓库: git push origin main Done

2025年01月18日