推动变化而不拉动

时间:2012-08-06 14:06:46

标签: git

我正在尝试撤消已经推送到远程存储库的一些更改,我已经在本地完成了

git reset --hard COMMIT-HASH

但是现在它不会让我在没有先拉的情况下推进,这当然会失败。我试过了:

git push -f

出了哪些错误:

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To git@xxx.beanstalkapp.com:/yyy.git
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@xxx.beanstalkapp.com:/yyy.git'

那么如何将我的新分支正确版本送到遥控器?

3 个答案:

答案 0 :(得分:24)

来自git config手册页:

  

receive.denyNonFastForwards

     

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

您尝试推送的服务器已启用此设置。所以,简短的回答是,在这种情况下,你将无法git push --force


要将分支的正确版本提供给远程,您必须对分支的尖端进行新的提交,以使其达到正确的状态。如果您当前处于正确状态的提交状态,则可以运行以下命令:

$ git reset --soft <remote>/<branch>    # point the ref back to the remote, but
                                        #   keep the index and working tree

$ git commit                            # make the 'correction' commit
$ git push

答案 1 :(得分:3)

您的服务器是否禁止非快速推送?

git配置文件

[receive]
denyNonFastforwards = true

答案 2 :(得分:0)

撤消git更改的最佳方法是使用git revert命令。

撤消上次提交: git revert HEAD^

它将撤消上次提交中所做的更改,然后在其上创建一个新提交。

希望它有所帮助..