如何在 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.