如何撤消 git reset --soft 以恢复我的更改?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21038045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:34:03  来源:igfitidea点击:

How to undo git reset --soft to get my changes back?

gitgit-commitgit-reset

提问by dennis

I had some local changes in my directory that I committed using git commit. Later I realized that by mistake my changes broke my build. So I did a "git reset --soft" on my repo. But I am screwed up, as I did not back up the changes that were all undone, as some of them did contain the new functionality that I wanted. Any help on how to undo a "git reset --soft" operation so that I can get my committed changes back.

我在使用 git commit 提交的目录中进行了一些本地更改。后来我意识到我的更改错误地破坏了我的构建。所以我在我的 repo 上做了一个“git reset --soft”。但是我搞砸了,因为我没有备份所有已撤消的更改,因为其中一些确实包含我想要的新功能。有关如何撤消“git reset --soft”操作的任何帮助,以便我可以恢复已提交的更改。

回答by Franck

In $ git reflogyou should find some of your commits. Once you find the latest commit that you want to move to

$ git reflog你应该找到你的一些提交。找到要移动到的最新提交后

you should reset back to your commit id $ git reset _Your_Hash_, as $ git reset --softjust reset the files and not the index or working tree.

你应该重置回你的提交 id $ git reset _Your_Hash_,因为$ git reset --soft只是重置文件而不是索引或工作树。