在本地完成重置后,如何恢复远程 git repo?
我们不小心将更改推送到主分支。我已将本地分支中的代码还原为最后一次好的提交。现在,我正在尝试更新远程存储库,以便它也处于最后一次提交——未来的拉取和克隆是最后一次好的提交,但是会遇到错误。
这是我尝试过的:
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'
如果我拉动,我会回到错误的提交。