git代碼庫回滾: 指的是將代碼庫某分支退回到以前的某個commit id
【本地代碼庫回滾】:
git reset --hard commit-id :回滾到commit-id,講commit-id之后提交的commit都去除
git reset --hard HEAD~3:將最近3次的提交回滾
【遠程代碼庫回滾】:
這個是重點要說的內容,遠程比本地回滾要復雜
應用場景:自動部署系統發布后發現問題,需要回滾到某一個commit,再重新發布
原理:先將本地分支退回到某個commit,刪除遠程分支,再重新push本地分支
操作步驟:
1、git checkout the_branch
2、git pull
3、git branch the_branch_backup //備份一下這個分支當前的情況
4、git reset --hard the_commit_id //把the_branch本地回滾到the_commit_id
5、git push origin :the_branch //刪除遠程 the_branch
6、git push origin the_branch //用回滾后的本地分支重新建立遠程分支
7、git push origin :the_branch_backup //如果前面都成功了,刪除這個備份分支
轉載地址:
http://www.cnblogs.com/qualitysong/archive/2012/11/27/2791486.html
另外可以參考另一個網友的做法:
回滾遠程分支我采用的是這篇文章的做法
http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
git revert 先, 然后push到遠程分支上去。感覺直接刪遠程分支有點狠。。。
另外參考社區提問:
http://pagespeed.v2ex.com/t/296286
https://ruby-china.org/topics/20638