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/
感謝,解決了