Git怎样撤销一次分支的合并Merge
Git怎样撤销一次分支的合并Merge
出现的问题:
某一天,所有的开发文件已经在development分支上,但是这时候,线上出了一个问题,需要及时修复,于是从master分支上,拉了一个bug分支,进行处理,master分支本应合并bug分支,结果合并了dev分支,而且还commit,并推到了远端的master分支,这时候才发现出了问题,于是乎,问题就来了
解决方法:
-
1.找到最后一次提交到master分支的版本号,即【merge前的版本号】
-
2.回退到某个版本号
git reset --hard 【merge前的版本号】
这个时候已经会退到了上一次提交的版本,但是之后的修改还是存在master分支上,以下步骤很关键
- 3.重新创建一个分支,这时候的分支就是上一次提交的代码
git checkout -b newmaster
- 4.推到对应的远程newmaster
git push
- 5.这个时候相当于备份做好了,接下来就可以删除本地及远端的master分支
git branch -d master
git push --delete origin master
- 6.从newmaster分支,重新在创建master分支,并推向远端
git checkout newmaster
git checkout -b master
git push
- 7.大功告成!
Yesterday is history.
Tomorrow is a mystery.
But today is a gift.
That is why it's called the present.
The old game: give a wolf a taste, then keep him hungry.
Tomorrow is a mystery.
But today is a gift.
That is why it's called the present.
The old game: give a wolf a taste, then keep him hungry.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步