Reviving a Deleted Git Branch
Overview
What to do when you force-deleted a branch with the command below, only to realize afterward that you actually needed it.
1 | $ git branch -D <branch_name> |
How to Recover
- Check the HEAD change history
- Create a branch from the HEAD log number
1 | $ git reflog |
Example:
1 | $ git reflog |
Once you figure out that HEAD@{3} above is the commit for the branch you deleted, run:
1 | $ git branch hogehoge HEAD@{3} |
After running the command above, running git branch shows that the branch hogehoge has been created.
So it’s a good idea to commit frequently.
Reviving a Deleted Git Branch
https://kenzo0107.github.io/en/2015/12/09/revive-deleted-git-branch/