问题描述

不小心将刚stash的change删除了,导致之前的工作内容都没有了

分析和解决

方法一

通过git fsck --unreachable或者git fsck -- lost -found命令可以列出正常途径无法看见的节点,然后出现一个列表blob/commit/tree + 一串表示版本的字符。
由上而下可以看见最近的一次commit也就是那次stash的内容,可以通过git show "版本号" 查看确定是否是自己要找回的节点,忽略dangling blob 的类型的记录,只找 dangling commit 的记录。
确定之后用git merge “版本号”命令即可恢复到stash之前的状态。

方法二

利用IDEA自带的功能,

  1. 首先右键自己的项目或某个文件夹、或者某个文件,选择Local History -> Show History
  2. 然后就可以看到历史记录了
  3. 选择对应的记录右键Revert就可以了

参考资料

官网https://git-scm.com/docs/git-stash

Recovering stash entries that were cleared/dropped erroneously
If you mistakenly drop or clear stash entries, they cannot be recovered through the normal safety mechanisms. However, you can try the following incantation to get a list of stash entries that are still in your repository, but not reachable any more:

git fsck --unreachable |
grep commit | cut -d\  -f3 |
xargs git log --merges --no-walk --grep=WIP
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐