iy88@DESKTOP-BL3O7B2:~/test (test)$ git checkout main Switched to branch 'main' iy88@DESKTOP-BL3O7B2:~/test (main)$ git branch -D test Deleted branch test (was 362e71d).
iy88@DESKTOP-BL3O7B2:~/test (main)$ git reflog 96655ee (HEAD -> main) HEAD@{0}: checkout: moving from test to main 362e71d HEAD@{1}: commit: commit on branch test 96655ee (HEAD -> main) HEAD@{2}: checkout: moving from main to test 96655ee (HEAD -> main) HEAD@{3}: commit (initial): first commit
注意到,362e71d 这个 commit 是我们切换回
main
前的最后一个提交记录,也就是我们需要恢复的状态,于是我们创建一个临时分支
restore
git
1 2
iy88@DESKTOP-BL3O7B2:~/test (main)$ git checkout -b restore 362e71d Switched to a new branch 'restore'