我想删除远程存储库上的两个损坏的提交。
我用了:
git reset --hard <commit_id>
所以我可以回到我想恢复的最后一次提交。然后我通过从外部文件夹(不在存储库中)粘贴我修改过的文件来应用我所做的更改。
现在,当我推回远程存储库时,它会引发错误:
$ git push origin master --force
me@mydomain.com's password:
stdin: is not a tty
Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first
)
To ssh://me@mydomain/repos.git
! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'ssh://me@mydomain/repos.git'
但是如果我再次拉取,我使用 git reset 删除的旧提交会回来。
我尝试使用
git push origin master --force
已经,但它仍然不起作用。
我应该如何解决这个问题,以便我可以从远程删除提交,并将我的新文件附加回它?
谢谢!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
更新:
on using git push origin :master
here是来自qqx的答案的输出
$git push origin :master
stdin: is not a tty
remote: error: By default, deleting the current branch is denied, because the next
remote: error: 'git clone' won't result in any file checked out, causing confusion.
remote: error:
remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: error: current branch, with or without a warning message.
remote: error:
remote: error: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To ssh://me@domain.com/repos.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to ssh://me@domain.com/repos.git