1、在初始分支切出一个test分支
git checkout -b test
Switched to a new branch 'test'
2、在test分支提交一个commit,用git log可以查看,有一个名为“测试”的commit
commit 51d0b42e2c2b9d1fbf3370fbeea2d23b72b965cc
Reflog: HEAD@{1} (c***g <***>)
Reflog message: commit: feat: 测试
Author: c***g <***>
Date: Mon Sep 5 11:55:52 2022 +0800
feat: 测试
3、现有分支如下
git branch
pre
prod
* test
误删分支回复操作
4、误删分支test
git branch -D test
Deleted branch test (was 51d0b42e2).
5、开始恢复:使用git log -g,找回之前提交的commit
commit 51d0b42e2c2b9d1fbf3370fbeea2d23b72b965cc
Reflog: HEAD@{1} (c***g <***>)
Reflog message: commit: feat: 测试
Author: c***g <***
Date: Mon Sep 5 11:55:52 2022 +0800
feat: 测试
6、使用git branch [新分支] commit_id命令用这个commit创建一个分支
git branch recover-branch 51d0b42e2c2b9d1fbf3370fbeea2d23b72b965cc
7、查看本地分支,看分支是否创建成功
git branch
pre
prod
recover-branch
8、切换到新建的分支,查看提交的记录是否都存在;经查看误删的commit已经恢复
git log
commit 51d0b42e2c2b9d1fbf3370fbeea2d23b72b965cc (HEAD -> recover-branch)
Author: c***g <***
Date: Mon Sep 5 11:55:52 2022 +0800
feat: 测试
标签:git,本地,误删,branch,test,commit,分支
From: https://www.cnblogs.com/coderInside/p/16657972.html