You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用git subtree推送gh-pages分支时遇分支落后错误求助

问题描述

我有一个名为gh-pages的分支,它的内容实际来自main分支下的public文件夹(该分支包含index.html文件)。我用Node.js配合TailwindCSS开发,main分支目录包含项目源码与public输出目录。

此前一直使用命令:

git subtree push --prefix public origin gh-pages

推送public文件夹到gh-pages分支,一切正常。但今天在public文件夹内新增了一个仅包含HTML和JS文件的tictactoe文件夹(其中通过../style.css引用上级目录的样式文件)后,推送时出现错误,提示:

updates were rejected because a pushed branch tip is behind its remote counterpart. check out this branch and integrate the remote changes (e.g. 'git pull ...') before pushing again.

我尝试了以下解决方案,但都未解决问题:

  • 使用git push -f origin gh-pages,提示Everything up-to-date
  • 尝试git pull -f origin gh-pages,出现错误:fatal: refusing to merge unrelated histories
  • 改用git pull origin gh-pages --allow-unrelated-histories成功拉取,但之后依旧无法正常推送subtree,还是收到相同的分支落后错误

内容的提问来源于stack exchange,提问作者qud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 18:06:39