git 恢复误删的远程分支

需求

实际工作上,肯定会有不小心的时候,比如我吧,删除了本地dev分支,intellij idea提示是否将tracked branch也删掉,结果一不小心将远程分支也删除了,接下来就是我的救赎之旅。

查看reflog,找到最后一次commitid

git reflog --date=iso

reflogreference log的意思,也就是引用log,记录HEAD在各个分支上的移动轨迹。选项 --date=iso,表示以标准时间格式展示。这里你肯定会问,为什么不用git log?git log是用来记录当前分支的commit log,分支都删除了,找不到commit log了。
找到目标分支最后一次的commitid,

D:\>git reflog --date=iso
287ba1b HEAD@{2019-05-13 15:35:18 +0800}: checkout: moving from dev to deploy
528a169 HEAD@{2019-05-13 09:23:58 +0800}: commit: 添加忽略,.idea,*.iml,*.log

切出分支

git checkout -b recovery_branch_name commitid

切出分支后,本地有分支了,再push到远程仓库就可以了

git push  origin recovery_branch_name 

恢复分支后,个人感受,git还是很强大的!

发布了336 篇原创文章 · 获赞 369 · 访问量 193万+

猜你喜欢

转载自blog.csdn.net/wangjun5159/article/details/90202710