0

I have been searching for a solution to this mistake I did. Can't find it anywhere.

I was working on a larger change, and I did a commit --ammend to add this as a patch to my earlier smaller change. However, for some reason, I deleted the commit --ammend message in editor (which unfortunately deleted my commit as a whole). So I am now left without my changes, anywhere. Is there any way I can get my changes/files back?

ps I have learned my lesson not to keep the changes without committing them for very long. I would appreciate any help.

4

1 回答 1

1

是的,不保留未提交的更改确实是一个宝贵的教训。在做一些重要的事情之前,请务必查看您未提交的更改并决定您是要提交还是放弃它们。(设置良好的提示将帮助您识别您的工作区是否脏。)

您提交的几乎所有内容都已保存并可随时恢复。棘手的部分是确定您想要的提交。

通常有两种方法可以做到这一点:git loggit reflog

git log你可以列出一个分支的官方历史。只要您只偶尔提交一次工作就足够了。但是,如果您通过修改或重新定位来更改历史记录,您显然将无法再看到正常的废弃版本git log

这就是git reflog派上用场的地方。这将记录您所做的几乎所有操作以及作为您操作结果的提交 ID。只需键入git reflog,您就会得到一个您应该识别的操作列表。时间从下往上。提交一些东西,你会得到一个新的条目。

如果您想恢复旧版本,只需扫描列表以查找所需条目并使用git reset在那里进行时间扭曲。:)

于 2013-06-12T06:36:13.043 回答