2

A long time ago i made some work in a branch, which I deleted during a clean up. So I would like to get it back because the request came up again. I can't remember the exact branch name. I have been looking at how to get git log display name of (deleted) branches, but I can't find it in the logs.

Peter Mølgaard Pallesen
  • 1,470
  • 1
  • 15
  • 26

2 Answers2

3

All you need is this command:

git log --all -S somestring

where somestring is a unique string, variable name etc. that can identify the commits in question.

Once you have the commit sha then you can recreate the branch using:

git checkout -b branch-name commit-sha
Kaus2b
  • 747
  • 4
  • 12
1

I just write a node.js script find-deleted-unmerged-branches to find deleted unmerged branches (may with a name or without a name).

You can have a try with

npx find-deleted-unmerged-branches /path/to/your/git/repo

Will output something like:

┌─────────┬─────────────┬───────────┐
│ (index) │    name     │    sha    │
├─────────┼─────────────┼───────────┤
│    0    │ '<unknown>' │ 'bf2ef40' │
│    1    │ '<unknown>' │ 'dc1a360' │
└─────────┴─────────────┴───────────┘

Then checkout to given commit shas, and check whether it's the deleted branch.

banyudu
  • 1,046
  • 9
  • 19