How does git restore a deleted branch? git delete branch deletes a branch by mistake

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 commitSHA value obtained" command to restore the deleted branch. .

The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.

When merging the code, delete source branch was checked.

How to restore deleted branches in git

There are two possibilities for branch deletion. Either the deletion operation is performed using a command, which can be seen with git log; or when the browser merges branches, the option to delete the source branch after merging is checked.

1. View deleted branches

1

git remote prune --dry-run origin

The deleted branch is dev

2. Find the commit SHA value of the last commit record of the deleted branch

1

git reflog

The commit SHA value of the last commit is 5f8fe57

3. Restore branch

1) Use command to restore;

1

git checkout -b dev 5f8fe57

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

Guess you like

Origin blog.csdn.net/u012118993/article/details/124613777