首页 > 其他分享 >Git stash被误删恢复策略

Git stash被误删恢复策略

时间:2022-11-30 15:02:49浏览次数:36  
标签:git -- stash 误删 Git blob unreachable ID

场景:

通过stash保存,被使用git stash drop 丢起。 项目开发中,不想commit提交,但要切换到其他commit或者branch,临时处理紧急任务,使用 git stash 备份当前的工作内容。但因不当操作使用“git stash drop”,暂存被删除  

策略1:

  • 要求:知道被删除的ID
通过历史操作记录,查看自己drop的ID,通过“git show ID”,“git stash apply ID” 进行查看和恢复  

策略2:

  • 要求:知道被删除的大致内容

方式a:

git fsck --lost-found 或者git fsck --unreachable 找到各丢弃的标识ID,如下:
$ git fsck --unreachable
Checking object directories: 100% (256/256), done.
unreachable blob 09c039a0e54677c113dafd4494378889b22a37ab
unreachable blob 2fc07e1fbbf4751d4fde1db05857a54b890aa5f9
unreachable commit 36c05a804042b9622dd13ef133f737d345f83595
unreachable blob 38400bf13924e1dc93181214e4e4f44e9af063b5
unreachable commit 3b80bea1acb07dce3ee4207bdb613f2aa52a4c78
unreachable blob 454099f6835c71dc35ad051fb411da30e1c11515
unreachable blob 45c0153261c7dc0872ea5db048b34b16b2d4646b
unreachable blob 62001790e7e38f8e2e6248e5eb76b5d7f1659750
unreachable blob 7900546139bf5486be9c71cca69190982a5ef581
unreachable blob 7b80cadb286acffc3153963eb1e35bfc4f285a7c
unreachable tree 84c027109e118eae511f8ed27801095a451b8b06
unreachable commit 88802967342507b6ccdd721667a49a0f7fb084e2
unreachable blob dc8002335b2eed9110ca1e0c16b3faed1ccbc66f
unreachable blob 0201f67c69d93516234b1e86aad444b5efd0edbc
unreachable blob 088160e56449dff21367a42ffe0a6dd9dd13f083
unreachable blob 3141ab5a6c2529acaf017931f42a4528d9d9b14b
unreachable tree 478138ac916c76ee401fd980e9a12044d416e865
unreachable tree 53418198a575f9adf980068cb2f5a1f285f8f07c
unreachable blob 5741e1d3f274e84c9a352db47c05c8ecdbdc152d
......
可配合通过策略1进行查看、内容恢复。
    • 缺点:commitID 数量大(几百上千个),而且不是根据顺序进行排列的,找起来麻烦,不太使用
改进:git fsck --lost-found >>1.txt 导入到文件,根据根绝“暂存stash”的特征,编写脚本进行过滤筛选

方式b:

查询被clear的相关历史
 git log --graph --oneline --decorate $(git fsck --no-reflog | awk '/dangling commit/ {print $3}')
执行命令后黄色字体为曾不可达(丢弃)的记录ID。如下:
  • On:被clear 的stash记录
  • index:被丢失的branch记录
  • 上面为最新记录
根据自己保存名称,直接 git stash apply ID 进行恢复;不记得名字可通过git show 查看具体内容,筛选需要的ID

策略3:

  • 要求:使用jetBrains
  • 方式:
      • 点击项目右键:选择“Local History” => "Show History"
      • 选中某条记录,右键“Revert”
     
 

标签:git,--,stash,误删,Git,blob,unreachable,ID
From: https://www.cnblogs.com/spaceapp/p/16938455.html

相关文章

  • Visual Studio 第一次上传代码至gitee
    前情概要今天尝试将自己在Visualstdio上写的代码上传至gitee上,解决历程通过Git    将码云上这个地址复制至2中   会让你输入以下用户名, 密码不......
  • Visual Studio 2022 提交git代码
    VisualStudio2022更换了全新的git提交方式,接下来实践一下。我们以gitte作为远程仓库参考实践一下环境说明环境和版本很重要,大量的博客没有环境说明和版本介绍,对新......
  • IntelliJ IDEA:Unregistered VCS root detected. The directory…is under Git, but i
    https://blog.csdn.net/CHENYUFENG1991/article/details/74136439/当我们在IDEA中导入一个Git项目或者初始化一个Git项目的时候,往往会出现“UnregisteredVCSrootdetect......
  • coding上创建项目、创建代码仓库、将IDEA中的代码提交到coding上的代码仓库、Git的下
    一、Git的安装以及子啊IDEA上配置Git(下载好的可以跳过)git官网:https://git-scm.com/参考这位博主的git下载教程。也是很详细()https://blog.csdn.net/orange228/article/det......
  • oracle误删除数据恢复
    查找对应删除的时间点select*fromv$sqlwheresql_textlike'%test_table%';使用时间来回复指定的表数据insertintotest_tableselect*fromtest_tableas......
  • git的回退以及合并,删除什么的
    有时候不小心合并了别的分支中的commit.我们需要回退某些提交记录。可以通过reset来操作,reset会回退到指定commit。这种方式会删除记录,我们最好使用revert命令来操作git......
  • ubuntu 安装 github desktop
    原文:https://gist.github.com/berkorbay/6feda478a00b0432d13f1fc0a50467f1sudowgethttps://github.com/shiftkey/desktop/releases/download/release-3.1.1-linux1/Gi......
  • git提交日志中文配置
    gitbash已配置显示中文  但拉取时显示中文提交文件名为数字串 原因为在默认设置下,中文文件名在工作区状态输出,中文名不能正确显示,而是显示为八进制的字符编码。......
  • git的操作--gitee
    目录git介绍和安装git工作流程git常用命令git过滤文件git多分支开发git远程仓库协同开发git介绍和安装1.远程仓库:后端,写了一个接口,完成了一个功能,在公司里,功能完成,要把代......
  • es,logstash,redis,filebeat
    logstash从redis中拿取数据后会删除reids中的key,就无法在redis中查询到beats输入的值。----filebeat.ymlfilebeat.inputs:-type:tcphost:"0.0.0.0:8000"output.redis:......