不小心 git stash clear 找回 clear 的代码

分类:Git |

首先输入
git fsck --lost-found
     
会看到 一条一条的记录 类似 
   dangling commit 7010e0447be96627fde29961d420d887533d7796
 
复制dangling commit 的id(其他的dangling blob不用理会) 
然后输入
git show 7010e0447be96627fde29961d420d887533d7796
 
    查看具体内容, 找到你想要的记录
    记录中会描述日期和摘要,
    日期是你git stash 的日期, 
    摘要会记录你是在哪一条commit 上进行git stash操作的, 
    类似(WIP on integration-xf: 2e205ac Merge branch 'release' into develop)
    貌似只能一条记录一条记录的查看
 
找到你想要的记录后输入
git merge 7010e0447be96627fde29961d420d887533d7796
 
这样就还原了你git stash drop, git stash clear  的内容


--------------------------------------------------------------------


背景介绍:

    使用 git stash list  查看 stash 的缓存历史,发现有历史记录,为了防止弄混新旧历史纪录,使用git stash clear 清除所有的stash 栈, 再次使用 git stash list 查看是否全部清除,注意:出错就是在这里,查看的时候不小心忘了输入list,结果把现有的代码全部缓存到了stash 的栈里面,此时发现栈内仍有内容,这时候没有多想,直接执行git stash clear 清除stash 栈的全部内容,结果悲剧了,刚刚写的所有代码全部被清除掉了。

    以下是找回代码的步骤, 执行git log --graph --oneline --decorate  $( git fsck --no-reflog | awk '/dangling commit/ {print $3}’ )调出stash 的log,该log 对应stash 的栈缓存纪录,WIP 为midify 内容,index 为add 内容,所以,一般情况下,WIP 比index 内容要全

Git log --graph --oneline --decorate  $( git fsck --no-reflog | awk '/dangling commit/ {print $3}’ )



20151116142530109.jpeg


然后执行 git stash apply f00c5ab恢复最后stash 的内容

至此,stash 被删除的内容全部被找回

from : http://blog.csdn.net/yangqing_dt/article/details/49865375



Git
阅读( 6142 ) |