如何撤销通过git reset –hard HEAD^删除的未暂存更改?

huangapple go评论49阅读模式
英文:

How can I undo that unstaged changes were deleted by git reset --hard HEAD^?

问题

我正在进行我的项目,然后我做了一个错误的提交(最后一次提交),想要永久从git日志中删除它,我执行了以下命令:

git reset --hard HEAD^

问题是,我没有添加我的更改,所以所有未暂存的更改都被删除了。

现在,我如何恢复所有更改?

英文:

I was working on my project, and I made a wrong commit (the last commit) and wanted to permanently delete it from the git logs, and I did the following command:

git reset --hard HEAD^

The problem is that I didn't make add on my changes, so all changes which are unstaged were deleted.

Now, how do I get all the changes back?

答案1

得分: 2

根据Git文档的说明:

git reset
--hard 重置索引和工作树。自从以来,工作树中被跟踪文件的任何更改都将被丢弃。

如果没有恢复源(stash、add、commit),我不知道任何可以恢复文件的方法,因为Git不会自动更新当前工作树的快照。

英文:

As the git documentation specifies:

> git reset
> --hard Resets the index and working
> tree. Any changes to tracked files in the working tree since <commit>
> are discarded.

If there is no restore source (stash, add, commit) I know of no way to restore your files since git doesn't 'auto-updates' a current snapshot of your working tree

huangapple
  • 本文由 发表于 2023年6月26日 01:10:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定