意外地回到了主人,失去了未提交的变化 [英] Accidentally reverted to master, lost uncommitted changes

查看:113
本文介绍了意外地回到了主人,失去了未提交的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设法犯了一个大错(在周一早上)
在Master上工作时,忘记创建新分支,对文件进行了更改,然后无意中还原到了主文件,失去了所有更新。
我没有提交更新过的文件。



我是否丢失了所有更新或可以检索它们?

不要问我是怎么回事,因为每当我想到这一点时,我都要自in一下。 解决方案

如果您没有提交暂存存储,则无法恢复这些更改。



编辑:恢复丢失的更改。在 Mark Longair的建议(在评论中)添加此项。这还包括从他的答案(*)中的几个SO链接,我发现相当丰富。




  • 如果您有曾经承诺一些更改并且已经丢失了该提交(例如提交处于分离状态),您可以使用 reflog 找到该提交。请参阅此 SO问题 *。


  • 如果您丢失了上次暂存更改,您还可以恢复该更新。请参阅此 SO问题 *。 (我从未使用或自己尝试过)。

  • 如果您有隐藏更改,您也可以使用 pop apply 。 (我不确定弹出/丢弃的窗口是否也可以恢复,但没有提交)。你可能会发现这个恢复丢弃在git中是有用的。




如果有其他任何人都可以建议的方法,我会进一步编辑这个答案来添加它们。

I've managed to make a huge blunder (on a Monday morning) Working on Master, forget to create new branch, made changes to files then inadvertently reverted to the master, loosing all updates. I didn't commit the updated files.

Have I lost all updates or can I retrieve them?

Don't ask me how because every time I think about it I have to punch myself in the face.

解决方案

If you had not commited, staged, or stashed the changes you made, there is no way you can recover those changes.

EDIT: Recovering lost changes. Adding this on Mark Longair's suggestion (in the comment). This also includes a couple of SO links from his answer below(*), that I found quite informative.

  • If you have ever committed some change and have lost that commit (like committing in a detached state), you can find that commit using reflog. See this SO question*.

  • If you have lost your last staged changed, you can also recover that. See this SO question*. (I have never used or tried it myself).

  • If you have stashed a change, you can also recover that using pop or apply. (I am not sure if the popped/dropped stashes are also recoverable that were not committed). You may find this Recover dropped stash in git useful.

If there are any other methods that anyone can suggest, I'd edit this answer further to add them.

这篇关于意外地回到了主人,失去了未提交的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆