如何在 Windows 上的 Git Gui 或 Gitk 中撤消硬重置?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的工作树中有一些更改在您执行 git reset --hard 时未提交,那么这些更改将永远消失。你必须使用你的记忆(在你的头脑中)来重新创建它们。
在您切换到的提交之后提交的更改不会丢失。它们可能没有指向它们的参考资料,这使得它们更难以定位。列出存储库所有低级更改的工具是 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 个字符,但毕竟,这篇文章中可能还有其他需要改进的地方。
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.
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
orgit 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.
请参阅问题链接中 Brian Riehman 和 Pat Notz 的答案。
一种解决方案是使用命令行。
在 Windows 中,在包含
.git
目录的目录中打开 DOS。输入类似以下内容以查看您想要转到哪个提交:
要转到某个提交,请输入类似以下内容,其中最后一个表达式是该提交的 SHA1 代码:
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:
To go to a certain commit, type something like the following, where the last expression is the SHA1 code of that commit:
我认为您无法撤消硬重置来恢复未提交的更改 - 您可以撤消变基,因为 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!