推动变化而不拉动

Wil*_*ill 18 git

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

git reset --hard COMMIT-HASH
Run Code Online (Sandbox Code Playgroud)

但是现在它不会让我在没有先拉动的情况下推动,这当然会击败目的.我试过了:

git push -f
Run Code Online (Sandbox Code Playgroud)

出了哪些错误:

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'
Run Code Online (Sandbox Code Playgroud)

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

ver*_*nzt 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
Run Code Online (Sandbox Code Playgroud)