git代碼庫回滾: 指的是將代碼庫某分支退回到以前的某個commit id
【本地代碼庫回滾】:
git reset --hard commit-id :回滾到commit-id,講commit-id之后提交的commit都去除
git reset --hard HEAD~3:將最近3次的提交回滾
【遠(yuǎn)程代碼庫回滾】:
這個是重點(diǎn)要說的內(nèi)容,遠(yuǎn)程比本地回滾要復(fù)雜
應(yīng)用場景:自動部署系統(tǒng)發(fā)布后發(fā)現(xiàn)問題刀闷,需要回滾到某一個commit井厌,再重新發(fā)布
原理:先將本地分支退回到某個commit嗦随,刪除遠(yuǎn)程分支弓熏,再重新push本地分支
操作步驟:
1五辽、git checkout the_branch
2特碳、git pull
3刻两、git branch the_branch_backup //備份一下這個分支當(dāng)前的情況
4增蹭、git reset --hard the_commit_id //把the_branch本地回滾到the_commit_id
5、git push origin :the_branch //刪除遠(yuǎn)程 the_branch
6磅摹、git push origin the_branch //用回滾后的本地分支重新建立遠(yuǎn)程分支
7滋迈、git push origin :the_branch_backup //如果前面都成功了,刪除這個備份分支
轉(zhuǎn)載地址:
http://www.cnblogs.com/qualitysong/archive/2012/11/27/2791486.html
另外可以參考另一個網(wǎng)友的做法:
回滾遠(yuǎn)程分支我采用的是這篇文章的做法
http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
git revert 先户誓, 然后push到遠(yuǎn)程分支上去饼灿。感覺直接刪遠(yuǎn)程分支有點(diǎn)狠。帝美。碍彭。
另外參考社區(qū)提問:
http://pagespeed.v2ex.com/t/296286
https://ruby-china.org/topics/20638