Git stash误删后的恢复

46 阅读1分钟

工作遇到紧急的bug需要修复,开发中的代码stash后的代码误删了😭

原理大致理解为,stash一次会有一次对应的commit产生,找出该commitID

如果能直接找到stash的commitID,直接执行git stash apply 你的commitID

  1. 找到项目文件的.git文件夹
  • 找不到隐藏文件按下【command + shift + .】查看隐藏文件 image.png
  1. 控制台打开该文件,执行命令
git log --graph --oneline --decorate $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

image.png 3. 输出内容一般按时间倒序,找到对应的commitID,执行命令

  • 可以使用git show 你的commitd 查看变更内容确定commit
  • 确定好后到对应的项目分支执行git stash apply 你的commitID

原文 blog.csdn.net/qq_36604536…