如何在 Windows 上的 Git Gui 或 Gitk 中撤消硬重置?

发布于 09-25 22:41 字数 247 浏览 9 评论 0原文

我在 Windows 上使用 Git Gui 和 Gitk。如何撤消过去两小时内的硬重置?

(是否可以在不使用命令行的情况下从这些应用程序执行此操作?)

我看到 这个 SO 帖子,它说在 git 的垃圾收集发生之前可以进行撤消。我可能已退出并重新打开其中一个或两个应用程序。

I'm using Git Gui and Gitk on Windows. How do I undo a hard reset from within the past two hours?

(Is it possible to do this from these applications, without using the command line?)

I saw this SO post, which says that undos are possible before git's garbage collection occurs. I might have quit and reopened one or both of these applications.

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

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

发布评论

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

评论(3

亢潮2024-10-02 22:41:14
  1. 如果您的工作树中有一些更改在您执行 git reset --hard 时未提交,那么这些更改将永远消失。你必须使用你的记忆(在你的头脑中)来重新创建它们。

  2. 在您切换到的提交之后提交的更改不会丢失。它们可能没有指向它们的参考资料,这使得它们更难以定位。列出存储库所有低级更改的工具是 git reflog 。
    找到要恢复的提交后,观察第一行中的哈希值,然后使用 git reset --hard #hashnumber 或 git checkout #hashnumber 来获取变化。
    我在 http://quirkygba.blogspot 上发现了这条有用的行.com/2008/11/recovering-history-with-git-reflog.html

<代码>
gitk --all $(git reflog | cut -c1-7)

这将显示 gitk 中所有隐藏的更改,您可以在其中轻松查看、指向、单击并创建新分支。

正如您提到的,未引用的提交通常会在存储库中保留 30 天。

编辑:我必须在这里添加内容,以便我的编辑至少有 6 个字符。我知道,有时代码修复少于 6 个字符,但毕竟,这篇文章中可能还有其他需要改进的地方。

  1. If you had changes in your working tree that were not committed when you did git reset --hard, those changes are gone for ever. You have to use your memory (in your head) to recreate them.

  2. Changes that were committed after the commit to which you switched are not lost. They likely have no reference pointing to them, making them more difficult to locate. The tool to list all low-level changes to the repo is git reflog.
    After you locate the commit which you want to revert to observe the hash number in the first row and use git reset --hard #hashnumber or git checkout #hashnumber to get the changes.
    I found this useful line on http://quirkygba.blogspot.com/2008/11/recovering-history-with-git-reflog.html:


gitk --all $(git reflog | cut -c1-7)

This will display all the hidden changes in gitk, where you can comfortably view, point, click and create new branches.

As you mentioned the unreferenced commits are normally being kept in the repository for 30 days.

EDIT: I have to add stuff here so that my edit is at least 6 characters. I know, sometimes code fixes are less than 6 characters, but there might, after all, be something else to improve in this post.

独行侠2024-10-02 22:41:14

请参阅问题链接中 Brian Riehman 和 Pat Notz 的答案。

一种解决方案是使用命令行。

在 Windows 中,在包含 .git 目录的目录中打开 DOS。

输入类似以下内容以查看您想要转到哪个提交:

"c:\Program Files\Git\bin\git.exe" reflog

要转到某个提交,请输入类似以下内容,其中最后一个表达式是该提交的 SHA1 代码:

"c:\Program Files\Git\bin\git.exe" reset --hard 5eb4080

See the answers by Brian Riehman and Pat Notz in the link in the question.

One solution is to use the command line.

In Windows, open DOS in the directory containing your .git directory.

Type something like the following to see what commit you want to go to:

"c:\Program Files\Git\bin\git.exe" reflog

To go to a certain commit, type something like the following, where the last expression is the SHA1 code of that commit:

"c:\Program Files\Git\bin\git.exe" reset --hard 5eb4080
最好是你2024-10-02 22:41:14

我认为您无法撤消硬重置来恢复未提交的更改 - 您可以撤消变基,因为 blob 仍然可用,但如果您从未将最新更改提交到 Git,它重写的任何东西很可能都是历史。我很想知道我错了!

I don't think you can undo a hard reset to get uncommitted changes back - you can undo a rebase because the blobs are still available, but if you never committed your newest changes to Git ever, anything it overwrote is most likely history. I'd love to find out that I'm wrong though!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文