git 如何恢复丢弃的 stash 数据

参考:https://zhuanlan.zhihu.com/p/28948567

1、问题

不小心把缓存 stash(储藏)起来的代码删除了

  • sourcetree删除

  • 命令行删除

$ git stash list
#stash@{0}: On pine/test: test

$ git stash drop stash@{0}
#Dropped stash@{0} (897fbefe9bae04f3b70512d1a137a904a7fc909c)

2、解决

git fsck --unreachable
#查找所有unreachable记录

Checking object directories: 100% (256/256), done.
Checking objects: 100% (8338/8338), done.
unreachable tree 15011b05b3ef298a105ffe5a0ac0899084c7fa2e
unreachable tree 8286f465ed738ad25d97dbaa8d1537f22a5b8c52
unreachable blob 9306d737410ac2532c2be9b8561a3aedaca1bdab
unreachable blob 1db93bfd2022fd3d3cf526ec656104b76e5b005a
unreachable tree c13a1c9e36017443e67db34d7ec71a0e3633b51d
unreachable commit c845707e0aef81b46c71cdfab7373b7e77436ab0
unreachable commit f9540ce0db5c176d55583486938e31e9ccdabaff
unreachable commit 92d6ee4258a8f2118333421788c880eb1667a418
unreachable blob 2edc52b333a997a25f6f610e4ef12e15c2c9b9de
unreachable tree 48e2f38885a07b37a6ea9a6b5d6eb69c9c50d806
unreachable commit 2eed40a47b0328321c3992ccd87ddf2191bd32fd
unreachable blob 05fbeb18df635eb69761d6ba8a11fc8f917a69f2

  • 靠下的 commit 就是最近被删的
git show 2eed40a47b0328321c3992ccd87ddf2191bd32fd
#查看详细信息

git stash apply 2eed40a47b0328321c3992ccd87ddf2191bd32fd
#恢复被删stash的修改

git status
#查看恢复
posted @ 2023-03-08 18:48  pine007  阅读(306)  评论(0编辑  收藏  举报