正文:部署 Node/Docker 应用时遇到
fatal: Need to specify how to reconcile divergent branches,不是 Git 错误,而是历史保护机制。本文重现一次真实生产事故的诊断与修复过程。- 问题:
git pull + docker compose up 脚本因分支分歧失败- 诊断:执行
git rev-list --left-right --count HEAD...origin/main 得到 1 16(服务器本地 1 个提交,GitHub 16 个提交)- 根因:服务器上有通过
git commit 或 git pull 产生的合并提交,导致历史不再线性- 生产级修复:不用
git pull,改用 git fetch origin + git reset --hard origin/main,确保服务器完全镜像远程仓库- 最佳实践脚本:
git fetch → git reset --hard origin/main → docker compose down → docker compose up --build -d#开发者 #工具 #Git #DevOps #部署
📢 频道:@DevToolboxHub
