Home >Development Tools >git >How to restore deleted branches in git
How to restore a deleted branch in git: 1. Use the "git reflog" command to find the commitSHA value of the last commit record of the deleted branch; 2. Use the "git checkout -b dev" command to obtain the commitSHA value. Just restore the deleted branch.
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
How to restore a deleted branch in git
There are two possibilities for branch deletion, either by deleting it with a command, you can use You can see it in git log; or when merging branches in the browser, you have checked the option to delete the source branch after merging.
1, check the deleted branch
git remote prune --dry-run origin
The deleted branch is dev
2, find the last time of the deleted branch The commit SHA value of the commit record
git reflog
The commit SHA value of the last commit is 5f8fe57
3, and the recovery branch
1) is used Command recovery;
git checkout -b dev 5f8fe57
2) Create a new branch directly on Gitlab based on commit SHA to restore the deleted branch;
Recommended learning: " Git tutorial》
The above is the detailed content of How to restore deleted branches in git. For more information, please follow other related articles on the PHP Chinese website!