Home > Development Tools > git > How to restore deleted branches in git

How to restore deleted branches in git

WBOY
Release: 2022-01-07 10:20:13
Original
34385 people have browsed it

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.

How to restore deleted branches in git

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
Copy after login

The deleted branch is dev

How to restore deleted branches in git

2, find the last time of the deleted branch The commit SHA value of the commit record

git reflog
Copy after login

How to restore deleted branches in git

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
Copy after login

2) Create a new branch directly on Gitlab based on commit SHA to restore the deleted branch;

How to restore deleted branches in git

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!

Related labels:
git
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template