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
相关推荐
淘矿人1 天前
从0到1:用Claude启动你的第一个项目
开发语言·人工智能·git·python·github·php·pygame
lpfasd1231 天前
Git/Gitee/GitHub 3 个安全凭证详解
git·gitee·github
李日灐1 天前
< 7 > Linux 开发工具:git 版本控制器 和 cgdb/gdb 调试器
linux·运维·服务器·开发语言·git·调试器·gdb/cgdb
鸿儒5171 天前
记录一个C++ Windows程序移植到Linux系统的bug
开发语言·c++·bug
Gust of wind1 天前
idea结合git和Gitee的初步使用
git·gitee·intellij-idea
夜七少eleanor1 天前
【Git】2026全图文详解安装教程
git
海边的Kurisu1 天前
从零开始的Git生活 | 刚实习同学的噩梦 And 参与开源不可缺的一环
git·生活
不老刘1 天前
Git Cherry-Pick:微前端架构下的“精准医疗”与最佳实践
前端·git
爬楼的猪2 天前
Git Folder Dashboard
git
Uncertainty!!2 天前
claude code中添加skills自动生成git commit信息
git·git commit·claude code