如何重置上次恢复的存储,但随后错误地丢失了其中包含的更改?

发布于 2025-01-15 01:34:54 字数 533 浏览 2 评论 0原文

我当时使用 GitHub 桌面并恢复了我的存储,但当我继续工作时,错误地覆盖了这些更改,而这种方式无法使用 VS Code 恢复。 (使用 crtl+z 返回文件历史记录,然后错误地覆盖了这些更改)。

即使没有被丢弃,有什么方法可以带回藏匿物吗? 我在 Windows 10 上尝试了以下命令,但我认为它只列出了删除的存储提交: git fsck --no-reflogs | 理想情况

下,我需要一种方法来列出所有最近的存储提交,无论它们是被删除还是恢复。然后使用 git stash apply *hash* 恢复它们。

总结:下图中的恢复按钮是我单击的将存储应用到本地存储库的按钮。但是,现在我丢失了那些恢复的更改。我想取回我的藏品,以便恢复这些更改,因为这似乎是我能做到这一点的唯一方法。

输入图片此处描述

I was using GitHub desktop and restored a stash I had, but then as I went on with the work and mistakenly overwrote those changes in a way that cannot be recovered using VS Code. (used crtl+z to go back in the file history, then overwrote those changes by mistake).

Is there a way I can bring back the stash even though it was not discarded ?
I am on Windows 10, tried the following command, but I think it only lists the dropped stash commits : git fsck --no-reflogs | find "dangling commit"

Ideally I would need a way to list all recent stash commit regardless if they were dropped or restored. Then recovering them with git stash apply *hash*.

In summary : The restore button in the picture below is what I had clicked on to apply the stash to my local repository. However, now That I lost those restored changes. I want to get back my stash so that I recover those changes, as it seems the only way I can do so.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深居我梦 2025-01-22 01:34:54

我能够使用以下命令恢复存储:

  • 命令列出所有丢失/无法访问的存储,例如提交 git fsck --unreachable | grep 提交 |切 -d ' ' -f3 | xargs git log --merges --no-walk
  • 使用 git show *hash* 使用上一命令中列出的哈希值之一显示内容
  • 如果提交是正确的,则使用 < 恢复更改代码>git stash apply *hash*。

请注意,在堆栈溢出上发布问题之前我已经尝试过此操作,但是 Windows 无法识别这些命令,因为它们是 Linux 命令。为了解决这个问题,我安装了 cygwin,它允许您在 Windows 中使用 linux 命令:

  • 安装 https://www.cygwin.com/ (按照视频进行安装和设置:https://www.youtube.com/watch?v=4zp7m7nkt-A)
  • 现在可以在 Cygwin 终端中使用 Linux 命令
  • 能够在 Windows cmd 中使用 Linux 命令。确保 bin 文件夹路径在 env 路径变量中可用。
  • 关闭所有终端以及 GitHub 桌面,然后在项目根文件夹再次打开 Windows 命令行,然后执行 ls 命令。如果它列出了您的目录文件夹和文件,则表示您的配置成功。

I was able to recover the stash using the following commands :

  • Command to list all lost/unreachable stash like commits git fsck --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --merges --no-walk
  • Show contents with git show *hash* using one of the hashes listed in previous command
  • If commit is the right one, recover changes with git stash apply *hash*.

Note that I had already tried this before posting the question on Stack overflow, but windows had not recognized those commands because they are Linux commands.To solve this, I installed cygwin which allows you to use linux commands in windows :

  • Install https://www.cygwin.com/ (Follow vid for installation and setup : https://www.youtube.com/watch?v=4zp7m7nkt-A)
  • Can now use Linux commands in Cygwin Terminal
  • To be able to use linux commands in windows cmd. Make sure bin folder path is available in the env path variables.
  • Close all terminals, as well as GitHub desktop, then open the windows command line again at the project root folder then execute ls command. If it lists your directories folders and files, it means that your configuration was successful.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文