git 回滚远程服务端master的代码
1.先备份版本
git checkout master git pull git branch master_backup //备份一下这个分支当前的情况
git push origin master_backup 推送到远端服务器
2.切到对应的要回流的版本上
git reset --hard the_commit_id //把master本地回滚到the_commit_id
3.先删除远端的版本
git push origin :master //删除远程 master
4.推送本地的到远端服务端上面
git push origin master //用回滚后的本地分支重新建立远程分支
5.删除备份版本
git branch -d master_backup //如果前面都成功了,删除这个备份分支
流程是这样子,但是进行到第三个操作的时候就各种问题
remote: GitLab: You are not allowed to push code to protected branches on this project. To git@gitlab.ins.risk.regn.net:cmd/release.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@gitlab.ins.risk.regn.net:cmd/release.git'
先是没有权限的错
我们用的是gitlab ,大概在 Setting中 => Protected branches 启用 master 分支可被 develop 角色提交即可。
1.那就开权限.
再次是不是
remote: error: By default, deleting the current branch is denied, because the next remote: error: 'git clone' won't result in any file checked out, causing confusion. remote: error: remote: error: You can set 'receive.denyDeleteCurrent' configuration variable to remote: error: 'warn' or 'ignore' in the remote repository to allow deleting the remote: error: current branch, with or without a warning message. remote: error: remote: error: To squelch this message, you can set it to 'refuse'. remote: error: refusing to delete the current branch: refs/heads/master To /Users/along/GitHub/GitRepository/gitStudy.git ! [remote rejected] master (deletion of the current branch prohibited) error: failed to push some refs to '/Users/along/GitHub/GitRepository/gitStudy.git'
这个错,需在要远程仓库中执行,记住是远程仓库,不是本地
git config receive.denyDeleteCurrent false
参考: https://blog.csdn.net/sunalongl/article/details/52013435
https://www.centos.bz/2017/07/git-merge-and-roll-back/
感谢,解决了