詳解git 刪除分支和回滾

這篇文章主要介紹了git 刪除分支和回滾的實例詳解的相關(guān)資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下

git 刪除分支和回滾的實例詳解

【git 刪除本地分支】

git?branch?-D?br

【git 刪除遠程分支】

git?push?origin?:br?(origin?后面有空格)

git代碼庫回滾: 指的是將代碼庫某分支退回到以前的某個commit id

【本地代碼庫回滾】:

git?reset?--hard?commit-id?:回滾到commit-id,講commit-id之后提交的commit都去除    git?reset?--hard?HEAD~3:將最近3次的提交回滾

【遠程代碼庫回滾】:

這個是重點要說的內(nèi)容,過程比本地回滾要復(fù)雜

應(yīng)用場景:自動部署系統(tǒng)發(fā)布后發(fā)現(xiàn)問題,需要回滾到某一個commit,再重新發(fā)布

原理:先將本地分支退回到某個commit,刪除遠程分支,再重新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 //刪除遠程 the_branch

6、git push origin the_branch //用回滾后的本地分支重新建立遠程分支

7、git push origin :the_branch_backup //如果前面都成功了,刪除這個備份分支?

【查看分支】

git?branch?-a

【創(chuàng)建本地分支并推送到遠程】

git?branch?test    git?push?origin?test

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點贊5 分享