在本地完成重置后恢复远程git仓库

时间:2012-06-20 19:02:21

标签: git

如何在本地重置后恢复远程git仓库?

我们不小心将更改推送到主分支。我已将本地分支中的代码恢复到最后一次良好的提交。现在,我正在尝试更新远程仓库,以便它也在最后一次提交 - 未来的拉动和克隆是最后一次提交,但是遇到了错误。

这是我尝试过的:

git reset --hard <last-good-commit-hash>

工作正常

然后,要更新远程仓库,

git push origin master

哪位给了我:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'host:/srv/git/cms'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

然后,我试过了:

git push --force origin master

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To host:/srv/git/cms
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'host:/srv/git/cms'

如果我拉,我回到了糟糕的提交。

2 个答案:

答案 0 :(得分:2)

而不是git reset <commit>尝试

git revert <commit>
git push origin master

答案 1 :(得分:2)

检查服务器上的配置文件,它是否有denyNonFastForwards=true

如果是,请执行以下操作:

git config receive.denyNonFastForwards false