如何撤消git还原以取回更改 [英] How to undo a git restore to get back changes

查看:46
本文介绍了如何撤消git还原以取回更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况,我对git还是陌生的,而当我从事一个项目时,我并没有经常提交.

Here is my situation, I'm still new to git and while I was working on a project I didn't constantly commit.

我完成了项目,并添加了除index.html文件以外的所有内容并提交了它们.我将更改推送到我的存储库.然后,我检查了我的git状态,发现仍然列出了index.html,我认为这是一个错误,也许我只是偶然地进行了一些编辑或其他操作,所以我进行了git restore index.html.

I finished the project and added everything other than the index.html file and committed them. I pushed the changes to my repository. I then checked my git status and saw that index.html was still listed which I thought was a mistake and maybe I just did a little edit by accident or something so I did a git restore index.html.

我几乎立即意识到我的所作所为,并检查了文件,看该文件已还原为原始格式.请告诉我有一种方法可以找回我的更改.我只想强调一下,我使用的命令是 git restore index.html

I almost immediately realized what I did and checked the file to see that the file had been reverted to its original form. Please tell me there is a way to get my changes back. I just want to emphasize that the command I used was git restore index.html

推荐答案

如果您意外还原的文件当前已在文本编辑器"或IDE中打开,则只需执行 Undo (撤消)操作即可获得提示.您将您的更改退回.

If the file you accidentally restored is currently open in your Text Editor or IDE, a simply Undo operation would do the trick and get you your changes back.

当我只想还原一个文件时,我不小心输入了 git restore..对我来说幸运的是,该命令还原的所有文件仍在VSCode中打开,我在其中进行了更改,因此在这些文件中的每个文件上执行撤消操作对我来说很成功,我又将更改恢复了.

I accidentally typed git restore . while I only wanted to restore one file. Luckily for me, all the files that had been restored by the command were still open in VSCode, where I made the changes, so executing an Undo in each of those files did the trick for me and I got my changes back.

这篇关于如何撤消git还原以取回更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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