1

我想删除远程存储库上的两个损坏的提交。

我用了:

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
4

1 回答 1

5

您的远程存储库可能receive.denyNonFastForwards在其配置中启用了该设置。此选项的文档状态:

如果设置为 true,git-receive-pack 将拒绝不是快进的 ref 更新。使用它来防止通过推送进行此类更新,即使该推送是强制的。此配置变量在初始化共享存储库时设置。

您可以通过以下方式解决此问题:

git push origin :master
git push origin master

第一个命令中分支名称的前导冒号将其转换为删除远程存储库上的分支的请求。完成后,推送当前版本的分支将不再被视为非快进推送。但是还有一个选项可以在远程存储库上设置以防止删除,receive.denyDeletes.

于 2013-08-04T15:21:13.493 回答