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
相关推荐
leoZ2312 小时前
Git 集成实战完全指南(二):智能分支管理
大数据·git·elasticsearch
c238565 小时前
Bug 猎手入门指南
c++·算法·bug
qq_452396237 小时前
第六篇:《GitLab CI 进阶:多环境部署与环境变量管理》
git·ci/cd·gitlab
有想法的py工程师8 小时前
GPG 密钥迁移指南:多私钥备份、批量导入与自动信任
git·github
嘛也学不会9 小时前
OpenSpec + Superpowers 的一个使用思路
教程·基础·skill·openspec·superpower
浮江雾11 小时前
Flutter第五节------Flutter开发环境配置与项目创建指南
开发语言·前端·git·学习·flutter·入门·函数
aramae15 小时前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
BerryS3N17 小时前
VS Code Git 工作树:解锁多分支并行开发新体验
大数据·git·elasticsearch
工具派19 小时前
从 git commit 到交付 PDF:我的一条在线工具流实录
git·elasticsearch·pdf
咋吃都不胖lyh1 天前
提交(Commit)到本地的 Git 仓库,然后才能推送(Push)到远程的 Git 仓库
git