Home >Development Tools >git >How to restore deleted remote branch in git

How to restore deleted remote branch in git

WBOY
WBOYOriginal
2022-01-14 16:14:2813677browse

Method: 1. Use the reflog operation to find the last commitid, the syntax is "git reflog --date=iso"; 2. Use checkout to cut out the branch to restore the deleted remote branch, the syntax is "git checkout -b branch name commitid".

How to restore deleted remote branch in git

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

How does git restore a deleted remote branch

In actual work, there will definitely be times when I accidentally delete the local branch. In the dev branch, IntelliJ IDEA prompted whether to delete the tracked branch, but accidentally deleted the remote branch. What followed was my journey of redemption.

Check the reflog and find the last commitid

git reflog --date=iso

reflog means reference log, which is a reference log that records the movement trajectory of HEAD on each branch. The option --date=iso means displaying in standard time format. You will definitely ask here, why not use git log? Git log is used to record the commit log of the current branch. The branches have been deleted and the commit log cannot be found.

Find the last commitid of the target branch,

D:\>git reflog --date=iso
287ba1b HEAD@{2019-05-13 15:35:18 +0800}: checkout: moving from dev to deploy
528a169 HEAD@{2019-05-13 09:23:58 +0800}: commit: 添加忽略,.idea,*.iml,*.log

Cut out the branch

git checkout -b recovery_branch_name commitid

After cutting out the branch, if there is a branch locally, just push it to the remote warehouse

git push  origin recovery_branch_name

Recommended learning: "Git Tutorial"

The above is the detailed content of How to restore deleted remote branch in git. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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