git reflog 可以查看所有分支的所有操作记录(包括(包括commit和reset的操作),包括已经被删除的commit记录,git log则不能察看已经删除了的commit记录
具体一个例子,假设有三个commit, git st:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
如果执行git reset –hard HEAD~1则 删除了commit3,如果发现删除错误了,需要恢复commit3,这个时候就要使用git reflog
HEAD@{0}: HEAD~1: updating HEAD
63ee781 HEAD@{1}: commit: test3
:q
加粗的即是被删除了的 commit3,运行git log则没有这一行记录
可以使用git reset –hard 63ee781将红色记录删除,则恢复了cmmit3,运行git log后可以看到:
commit3: add test3.c
commit2: add test2.c
commit1: add test1.c
这里也可以使用另外一种方法来实现:git cherry-pick 63ee78
本文介绍如何利用git reflog命令恢复已被硬重置删除的提交记录。通过实例说明,在执行git reset --hard HEAD~1后如何找回丢失的commit,并提供了两种恢复方法:一是使用git reset --hard直接恢复;二是采用git cherry-pick进行选择性恢复。
4484

被折叠的 条评论
为什么被折叠?



