我们的远程主分支不知怎的搞砸了.当前开发代码与最新提交一起在主分支上.显然,开发代码还没有为主分支做好准备.
所以在我的本地存储库中,我重置了最新的标记,git reset --hard (Tag)
.现在主分支在我的本地存储库上是正确的.现在,当我尝试将更改推送到远程存储库时git push origin master
,我收到一个错误:
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.
Run Code Online (Sandbox Code Playgroud)
所以环顾四周之后,我发现了这个--force
选项.所以我强行推进了远程存储库,git push --force origin master
我仍然遇到错误:
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)'
Run Code Online (Sandbox Code Playgroud)
我不能对master进行拉动,因为它包含的开发代码不能在master上.
svi*_*ick 144
该消息表示您不允许进行非快进推送.
您的远程存储库很可能denyNonFastforwards = true
在其配置中.如果你改变它,git push --force
应该工作.
要更改设置,您需要使用远程存储库访问计算机.从那里,做git config receive.denynonfastforwards false
.
ric*_*cho 15
遥控器不允许非快进.
您最好的选择是git revert
所有不应该存在的提交,并且将来会更加小心.
git revert [commit]
将创建一个新的提交,撤消[commit]
所做的任何事情.
eme*_*ery 12
永久启用强制推送的步骤,采用以下样式
git push -f myrepo my-branch
Run Code Online (Sandbox Code Playgroud)
在远程存储库上以".git"结尾的文件夹中编辑名为"config"的文件
在git的失败推送的命令行输出中,查找如下所示的行:
error: failed to push some refs to 'ssh://user@some-remote-server.mycompany.com/srv/git/myrepo.git
Run Code Online (Sandbox Code Playgroud)
然后
ssh user@some-remote-server.mycompany.com
cd /srv/git/myrepo.git
vi config
Run Code Online (Sandbox Code Playgroud)
将"denyNonFastforwards"设置为false
在"配置"中,设置
[receive]
denyNonFastforwards = false
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用-f从本地计算机进行推送
git push -f myrepo my-branch
Run Code Online (Sandbox Code Playgroud)
Chr*_*det 11
尝试使用该-f
标志并将其放在远程分支名称之后.
git push origin master -f