简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM