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次的提交回滾
【遠程代碼庫回滾】:
這個是重點要說的內容,過程比本地回滾要復雜
應用場景:自動部署系統發布后發現問題,需要回滾到某一個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 //如果前面都成功了,刪除這個備份分支
【查看分支】
git branch -a
【創建本地分支并推送到遠程】
git branch test git push origin test
如有疑問請留言或者到本站社區交流討論,以上就是對git 回滾及刪除分支的詳解,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!