首页 > 解决方案 > 强制推送到不同的分支时,Git 不会将新文件推送到远程

问题描述

我有两个分支:no-usersold-state. 在本地,我在no-users. 我退出old-state并修复了合并冲突。现在我想推送old-state覆盖该分支上的所有内容并传输新文件,但强制推送( )以某种方式不推送在分支git push -f origin old-state中创建的文件。正在写强制推送已成功运行,但远程文件不存在。no-usersGit

标签: git

解决方案


当你做了

git push -f origin old-state

你推送到提交指向的远程old-state,自从你合并old-state到,它没有改变no-users,而不是相反。这就是为什么强制在这里没有改变任何事情的原因。您的推送没有被拒绝,它只是发送了一个遥控器已经拥有的 ref。

此时只有no-users树的两个部分,所以你最好的方法是

git checkout old-state

# if you're not sure whether you're up-to-date on this branch,
# you might as well do it now before the merge
git pull

git merge no-users

并且您将能够不费力地推动:

git push origin old-state

推荐阅读