user5047085
user5047085

Reputation:

I deleted a branch with -d, how can I restore/recover it?

I deleted a branch with:

git branch -d <branch>

it said:

 git branch -d oleg/feature/1533692217
warning: deleting branch 'oleg/feature/1533692217' that has been merged to
         'refs/remotes/origin/oleg/feature/1533692217', but not yet merged to HEAD.
Deleted branch oleg/feature/1533692217 (was f7a4a13).

I think I know what that means, how can I restore branch with name:

oleg/feature/1533692217

is there a way to restore the branch without checking it out?

Note that I squashed the feature branch that I deleted, when I merged it with the integration branch, and that's one reason why the warning message may have appeared..maybe git doesn't handle that case?

Upvotes: 2

Views: 100

Answers (2)

LarsH
LarsH

Reputation: 28004

I would do

git branch oleg/feature/1533692217 f7a4a13

This has the same effect as Ry-'s answer -- it recreates the deleted branch, pointing to the same tip commit that it was pointing to before it was deleted -- except that it doesn't rely on understanding what's going on with the origin/oleg/feature/1533692217 branch.

Upvotes: 5

Ry-
Ry-

Reputation: 225238

git branch oleg/feature/1533692217 origin/oleg/feature/1533692217

Upvotes: 1

Related Questions