ブランチを消したときの対処法
現状
悲惨なことに大事なブランチをremoteからもlocalからも消し去ってしまいました
手順
$ git reflog
まずはこちらのコマンドを叩く↑
するとコミット履歴が出てくる↓
96f72ec7 (HEAD -> develop, origin/develop, origin/HEAD) HEAD@{0}: checkout: moving from deleted-branch to develop
5480e0d9 HEAD@{1}: commit: adjust
cab12ab2 HEAD@{2}: commit: response data debug
9b7873cf HEAD@{3}: commit: debug log modify
c506e1f5 HEAD@{4}: commit: apiUrl = null
b1c620b4 HEAD@{5}: commit: debug comment
e7df592a HEAD@{6}: commit: debug comment
8e3473d3 HEAD@{7}: commit: comment out
....
ちょうど一番上のところに大事なブランチを消し去った痕跡が残っていますね。
消したブランチで作業してたときの最新の状態 に戻したいので
上から二行目の
5480e0d9 HEAD@{1}: commit: adjust
このコミットをしたときの状態に戻したいです。
そこでこのコマンドを叩く↓
$ git branch new-branch HEAD@{1}
分かるかと思いますが少し解説・・・・
$ git branch つけたいブランチ名 HEAD@{戻したいコミットのHEAD番号}
そしてこのままgit push!!
(intelliJならCtrl + Shift + kでgit push できます)
そうすると先ほどのコマンドを叩くときに指定したブランチ名で復活します。
めでたしめでたし・・・・・
備忘録