Git undo local branch delete

后端 未结 8 1687
慢半拍i
慢半拍i 2020-11-29 14:52

I just deleted the wrong branch with some experimental changes I need with git branch -D branchName.

How do I recover the branch?

相关标签:
8条回答
  • 2020-11-29 15:27

    If you just deleted the branch, you will see something like this in your terminal:

    Deleted branch branch_name(was e562d13)
    
    • where e562d13 is a unique ID (a.k.a. the "SHA" or "hash"), with this you can restore the deleted branch.

    To restore the branch, use:

    git checkout -b <branch_name> <sha>
    

    for example:

    git checkout -b branch_name e562d13 
    
    0 讨论(0)
  • 2020-11-29 15:33

    Follow these Steps:

    1: Enter:

    git reflog show 
    

    This will display all the Commit history, you need to select the sha-1 that has the last commit that you want to get back

    2: create a branch name with the Sha-1 ID you selected eg: 8c87714

    git branch your-branch-name 8c87714
    
    0 讨论(0)
提交回复
热议问题