如何强制推送重置到远程存储库? [英] How to force push a reset to remote repository?

查看:80
本文介绍了如何强制推送重置到远程存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的远程主分支不知何故被搞砸了。当前的开发代码与最新的提交一起在主分支上。显然,开发代码没有准备好用于master分支。



因此,在我的本地存储库中,我重置了最新的标记 git重设--hard(标签)。主分支现在在我的本地存储库上正确。现在,当我尝试将更改推送到远程存储库时, git push origin master ,出现错误:

 到(远程GIT仓储位置)
! [被拒绝] master - > master(非快进)
错误:无法将某些参考推送到'(远程GIT存储库位置)'
为了防止您丢失历史记录,非快进更新被拒绝
再次按下之前合并远程更改(例如'git pull')。有关详细信息,请参阅git push --help的快速转发部分的
'注意事项。

因此,在环顾四周后,我发现 - force 选项。所以我做了一个强制推送到远程仓库, git push --force origin master ,但我仍然遇到错误:

 合计0(delta 0),重用0(delta 0)
remote:错误:拒绝非快进refs / heads / master第一个)
到(远程存储库位置)
! [remote rejected] master - >主(非快进)
错误:未能将某些参考推送到'(远程GIT存储库位置)'

我无法对主控进行操作,因为它包含了不能在主控上的开发代码。

解决方案

此消息意味着您不允许进行非快进推送。



您的远程存储库在其配置中最有可能是 denyNonFastforwards = true 。如果你改变了这个设置, git push --force 应该可以工作。



要更改设置,你需要访问该机器与远程存储库。从那里,做 git config receive.denynonfastforwards false


Our remote master branch somehow got messed up. Current development code is on the master branch along with the latest commits. Obviously, the development code is not ready for the master branch.

So on my local repository, I did a reset to the latest tag, git reset --hard (Tag). The master branch is now correct on my local repository. Now when I try to push the changes on to the remote repository, git push origin master, I get an error:

To (REMOTE GIT REPOSITORY LOCATION)
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

So after looking around I found out the --force option. So I did a force push on to the remote repository, git push --force origin master, and I still got an error:

Total 0 (delta 0), reused 0 (delta 0)
remote: error: denying non-fast-forward refs/heads/master (you should pull first)
To (REMOTE GIT REPOSITORY LOCATION)
 ! [remote rejected] master -> master (non-fast-forward)
error: failed to push some refs to '(REMOTE GIT REPOSITORY LOCATION)'

I can't do a pull on master, because it contains development code which can't be on master.

解决方案

The message means that you're not allowed to do non-fast-forward push.

Your remote repository has most likely denyNonFastforwards = true in its config. If you change that, git push --force should work.

To change the setting, you need access to the machine with the remote repository. From there, do git config receive.denynonfastforwards false.

这篇关于如何强制推送重置到远程存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆