git版本回滾

前言

有的時候我們提交了代碼後,發現有些問題,需要版本回退(代碼回滾)。

本地版本回退

查詢提交記錄

git reflog
  • 1

這裏寫圖片描述

紅色區域部分就是你每次提交的commit-id。

版本回退

git reset --hard commit-id  //回滾到commit-id,講commit-id之後提交的commit都去除
  • 1
git reset --hard HEAD~3 //將最近3次的提交回滾
  • 1

遠程版本回退

原理:先將本地分支退回到某個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 //如果前面都成功了,刪除這個備份分支

後記

參考:https://www.cnblogs.com/hqbhonker/p/5092300.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章