0

I had a remote branch called bug_fix that I wanted to rename to status_page. These are steps that I have taken being on master:

git branch bug_fix // this was a mistake
git branch -m bug_fix status_page
git push origin --delete bug_fix
git push origin status_page

After git branch bug_fix the code was same as in master and basically I pushed empty branch. Is there a way to get back the code from bug_fix?

Cheaker
  • 89
  • 8
  • you can try to reset changes to last commit – Uladz Kha Jul 17 '19 at 20:24
  • @MatzHeri commits are gone as well :( – Cheaker Jul 17 '19 at 20:28
  • please check this question might it help https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git – Uladz Kha Jul 17 '19 at 20:30
  • @MatzHeri thanks for advice, this would work, but `git reflog` does not show old commits at all, probably because the repository was newly cloned – Cheaker Jul 17 '19 at 20:40
  • I was hoping to offer a solution using `git fsck --unreachable --no-reflogs` but in trying to verify it I wasn't able to show it working for your use case. You may give that a shot and look at commits there to find the correct one. Also, do you have collaborators you can leverage? If they have a recent checkout they will have the commit hash in question and can recover the branch. – PhiloEpisteme Jul 17 '19 at 21:16

1 Answers1

1

I was managed to recover lost branch following instructions in this answer.

P.S.: Thanks @MatzHeri and @PhiloEpisteme for help :)

Cheaker
  • 89
  • 8