git 不拉动推动变化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11829911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:19:05  来源:igfitidea点击:

push changes without pull

git

提问by Will

I'm trying to undo some changes that have already been pushed to a remote repository, and I've done so locally with

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

git reset --hard COMMIT-HASH

But now it won't let me push without pulling first, which of course defeats the purpose. I've tried:

但是现在不先拉就不会让我推,这当然达不到目的。我试过了:

git push -f

Which errors out with:

哪个错误:

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

So how do I get my new, correct version of the branch to the remote?

那么如何将我的新的、正确版本的分支发送到远程?

回答by vergenzt

From the git configman page:

git config手册页:

receive.denyNonFastForwards

If set to true, git-receive-pack will deny a ref update which is not a fast-forward. Use this to prevent such an update via a push, even if that push is forced. This configuration variable is set when initializing a shared repository.

receive.denyNonFastForwards

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

The server you are trying to push to has this setting enabled. So, short answer, is that in this case you will not be able to git push --force.

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



To get the correct version of the branch to the remote, you will have to make a new commit to the tip of the branch that gets it to the correct state. If you are currently at the commit for the correct state, you can run the following:

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

$ 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

回答by linquize

Does your server disallow non-fast forward push?

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

git config file

git配置文件

[receive]
denyNonFastforwards = true

回答by Karthik Bose

The best way to undo changes in git is using git revertcommand.

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

To undo your last commit: git revert HEAD^

要撤消上次提交: git revert HEAD^

it will undo changes made in last commit, then creates a new commit on top of it.

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

Hope it helps someone..

希望它可以帮助某人..