背景
- 程序员 A 在本地进行了三次 commit 'demo1'、'demo2'、'demo3'
- 程序员 A 不小心进行了回滚 git reset --hard 'commit1',回滚到第一次提交
- 程序员 A 又修改了文件并进行了 commit, 'demo4'
问:如何找回被 reset 的两次 commit,并合并最新的一次 commit 'demo4'
使用 git log 查看,仅能看到 demo1 和 demo4 的提交记录
git reflog
git reflog 可以查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作) 恢复步骤
git reflog
git reset --hard hash
git cherry-pick
git cherry-pick 能够把另一个分支的一个或多个提交复制到当前分支 恢复步骤
git cherry-pick hash