Bug: git stash恢复误drop的提交

Bug: git stash恢复误drop的提交

前几天在写ut时突然需要通过本地代码临时出一个包,但是本地ut又不想直接作为一个commit提交,所以为了省事就将ut的代码暂时stash起来。出完包后想apply stash,但是手误操作点成了drop stash,丢失了之前stash的代码。后来通过一顿猛操作摸索,成功恢复丢失的代码。

1 stash本地代码

这是我本地修改的代码,现在我通过goland将它stash起来

选中目录,右键 - git - Stash Changes

为此次stash添加一个备注信息:

create stash成功之后,我们开始的修改就都没了:

2 drop stash

本地出完包后,想要应用之前stash的代码:

  • 选中对应目录 - Git - Unstash Changes

原本我们应该选中之前的stash点击右下角的apply stash,但是由于误操作,点成了右侧的drop,导致之前的stash丢失。

3 恢复之前drop的stash

3.1 通过命令找到之前的stash id

可视化展示git提交信息:git log --graph --decorate --pretty=oneline --abbrev-commit --all $(git fsck --no-reflogs | grep commit | cut -d' ' -f3)

命令行执行下面命令,图形化展示git提交信息:

bash 复制代码
git log --graph --decorate --pretty=oneline --abbrev-commit --all $(git fsck --no-reflogs | grep commit | cut -d' ' -f3)

3.2 git stash apply commitID

在命令行执行下面命令,应用丢失的stash:

bash 复制代码
git stash apply b77f01c
相关推荐
DianSan_ERP20 小时前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
YAY_tyy21 小时前
2025 最新版 Node.js 下载安装及环境配置教程
前端·node.js·教程·工具配置
ALGO阿狗1 天前
SimpleDateFormat(“YYYY-MM-dd“)格式化时间出现了bug?
bug
红豆子不相思1 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享1 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
梅孔立1 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
qq_426003962 天前
git切换当前分支到远程分支
git
xcLeigh2 天前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
ON10N2 天前
100% 纯 Vibe Coding,我是怎么用 AI 撸出一个 VS Code 插件的
git·ai编程·visual studio code
NPE~2 天前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具