Git 恢复未提交的更改
我有很多局部变化。
我只是不小心做了
git merge another_branch
git reset --hard HEAD^
很多工作。 :( 我不想在这里合并更改。
我如何恢复原始状态?
不,本地更改从未提交/隐藏。
不可能吗?
I had a lot of local changes.
I just accidentally did
git merge another_branch
git reset --hard HEAD^
on a lot of work. :( with the intention I didn't want the merged changes in here.
How do I recover the original state?
No, the local changes were never committed/stashed.
No way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于任何在 IDE 中遇到此问题的人来说,这里有一个解决方案。
搜索 IDE 的 IDE 编辑器历史文件。我在使用Android Studio时遇到了问题,所以在这里我将为您提供Android Studio的解决方案。
例如:在 Android Studio 中,您始终可以通过右键单击项目文件夹→本地历史记录→显示历史记录来查看以前的文件。
您可以查看文件的更改历史记录,还可以打开文件并将其与新文件并排进行比较。如果您需要旧代码,只需从那里复制粘贴即可。
Foy anyone who is facing this problem in IDEs, there is a solution.
Search for the IDE editor history files of your IDE. I had a problem with Android Studio, so here I will give you a solution for Android Studio.
For example: In Android Studio you can always see the previous files by right clicking on the project folder → Local History → Show History.
You can see the change history of files and you can also open the files and compare it with new files side by side. If you need the old code, just copy paste it from there.
如果更改从未被提交、隐藏或上演,那么您就不走运了。如果有,那么您应该能够通过在 git reflog 中查找更改来取回更改。
If the changes had never been committed, stashed, or staged, then you're out of luck. If they have, then you should be able to get your changes back by looking for them in
git reflog
.尽管对跟踪文件的未提交修改将会丢失,但我认为任何未跟踪的文件仍然会存在,除非您随后删除它们。
Although the uncommitted modifications to tracked files will have been lost, I think any untracked files will still be around unless you subsequently deleted them.
看看回收站!
我在那里找到了我已删除(未提交)的文件。
Look into the Recycle Bin!
I found my deleted (uncommitted) files there.
尝试直接从 IDE 撤消该文件。你会得到你需要的。
这可能对 @Lakshman Prasad 没有帮助,但对其他人会有帮助:-D
Try undoing on the file directly from the IDE. You'll get what you need.
It is probably not helpful for @Lakshman Prasad, but it will help someone else :-D
我能够使用 git log -g 恢复我的文件。
我的更改就在那里,因为我提交了一次,未提交我的更改,然后我看到我正在处理的所有文件都丢失了。
通过执行 git log -g || git reflog -g 它将显示最近的提交日志。
我找到了我的提交哈希,并使用以下命令对其进行了检查:
git reset #commitHashID
这可能会对遇到类似情况的人有所帮助。
I was able to recover my files, by using
git log -g
.My changes were there, because I committed them once, uncommitted my changes and then I saw all files on which I was working were lost.
By doing
git log -g
||git reflog -g
it will display the recent commit logs.I found my commit hash and I checked it out to that using this command:
git reset #commitHashID
This may help someone with a similar scenario.