为什么git reset --hard和push --force不会还原我的远程分支

时间:2014-09-06 08:17:35

标签: git push reset

我有一个名为hfix的分支。我在origin/hfix上有一些脏提交。当我发出以下命令时:

git reset --hard abd000b3ce70557f05a469d580fc8f3bf1c3a8b2

我的本​​地头指针向后移动到我想要的位置。现在我想做的是强制我的远程分支与我的本地历史相同,所以我发出:

git push --force origin hfix 

但是我收到以下错误:

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/hfix (you should pull first)
To root@172.16.131.9:/var/local/fxxx/local_core.repo
 ! [remote rejected] hfix -> hfix (non-fast-forward)  

我不想拉,因为它会使我的本地像远程一样。我该怎么做才能将远程分支清理为本地分支?

1 个答案:

答案 0 :(得分:2)

您的远程存储库很可能在其配置中denyNonFastforwards = true。如果将其切换为false,则git push --force origin hfix应该按预期工作。