1

I was working on a project. Now a few weeks later the client asked me about a branch I had called feature/zomato

It's gone, It can't checkout to it anymore, I don't see it my list of branches in phpstorm either.

I looked online for some solutions

Reflog Solution

This solution required you to know that latest commit on that branch, but the only rows I see in reflog are switching to and away to that branch, I don't see any commits being made on it.

enter image description here

Do you know other solutions to restore a deleted branch? **Or the proof that I deleted it? Is it possible to see that in logs somewhere?

Thank you!

Community
  • 1
  • 1
Miguel Stevens
  • 8,631
  • 18
  • 66
  • 125
  • try `git branch` it will print all available the branch – Rajendran Nadar Dec 04 '17 at 17:53
  • https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git – Hackerman Dec 04 '17 at 17:53
  • It's not there when I try "git branch". – Miguel Stevens Dec 04 '17 at 17:54
  • As I typed above here, That didn't work because I can't see what the latest sha is on that branch. – Miguel Stevens Dec 04 '17 at 17:55
  • 3
    Possible duplicate of [Can I recover a branch after its deletion in Git?](https://stackoverflow.com/questions/3640764/can-i-recover-a-branch-after-its-deletion-in-git) – Channaveer Hakari Dec 04 '17 at 18:02
  • Nope! As I said before I don't know the latest sha, did you even read my full question? I know how to search on stackoverflow. – Miguel Stevens Dec 04 '17 at 18:05
  • 1
    The hash at the left of the `git reflog` output *is* the hash to which the branch pointed at the time you ran `git checkout`. Unless something else moved the branch since then (which *is* possible, e.g., you could have run `branch -f `), that would be the latest hash on that branch. – torek Dec 04 '17 at 18:24
  • 1
    Did you even read the answer at Channaveer's link? The SHAs are in the reflog output. You can recreate the branch from the SHA, with complete history, because that's [how commit objects work](https://blog.thoughtram.io/git/2014/11/18/the-anatomy-of-a-git-commit.html). – JDB Dec 04 '17 at 18:37
  • I tried all those steps, I'm nog getting my branch back, nothing changes compared to the master branch. Thanks for your response. – Miguel Stevens Dec 04 '17 at 18:39
  • In your current repo, the `develop` and `feature/zomato` branches are pointing to the same commit: `5945f47`. The reflog history expires [after 90 days (by default)](https://git-scm.com/docs/git-reflog#git-reflog---expirelttimegt). Is it possible that more than 90 days ago, you did a hard reset to make zomato point to develop? – JDB Dec 04 '17 at 18:48
  • Also, reflog only tracks the current repo. It's not shared with other repos. Is it possible you were working on another machine at the time? If so, reflog is not going to help unless you can get back to that machine/repo. – JDB Dec 04 '17 at 18:50
  • Thanks for the tips! I'm sure I was on this machine. Might be duplicate of a codebase with different repo, I'll check that out now. And it might be around 3 months ago so 90 days could be true... – Miguel Stevens Dec 04 '17 at 18:52

1 Answers1

0

If you've deleted (or moved) the ref but haven't GC'd it, you can use git fsck --lost-found to get a list of dangling commits. If one (or more) show up, you can then recreate the branch from the SHA (git branch feature/zomato SHA).

Allen Luce
  • 7,859
  • 3
  • 40
  • 53