如何撤消git checkout文件中未提交的更改? [英] How to undo git checkout file for uncommitted changes?

查看:146
本文介绍了如何撤消git checkout文件中未提交的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我做了一个GIT状态,并注意到上演了许多应该被GIT忽略的文件,例如.gitignore,.htaccess和我的Drupal站点的设置文件.

So I did a GIT status and noticed a bunch of files that were staged that should have been ignored by GIT ignore, such as .gitignore, .htaccess, and settings files for my Drupal site.

我错误地使用了 git checkout< file> 而不是 git rm< file> 从临时区域中将其删除.虽然看起来可行,但我还是中断了网站.我想我现在明白了 git checkout 会还原我对这些文件所做的任何更改,对吗?更改未提交,因为最初不应该对它们进行跟踪.

I mistakenly used git checkout <file> instead of git rm <file> to remove them from the staging area. While it looked like it worked, I broke the website. I think I now understand that git checkout reverts any changes I've made to those files, correct? The changes weren't committed because they weren't supposed to be tracked in the first place.

应该如何使用 git checkout< file> (这是相反的意思),现在我可以撤消撤消操作,还是从这里去哪里?

How is git checkout <file> supposed to be used (what is the opposite of it) and ow can I undo the undo or where do I go from here?

推荐答案

根据git的文档此处:

重要的是要了解 git checkout-< file> 是一个危险的命令.您对该文件所做的任何更改均已消失– Git刚刚复制了另一个文件.除非使用此命令,否则不要使用您完全知道您不需要该文件.

It’s important to understand that git checkout -- <file> is a dangerous command. Any changes you made to that file are gone – Git just copied another file over it. Don’t ever use this command unless you absolutely know that you don’t want the file.

所以您不能撤消该命令.

So you can't undo this command.

这篇关于如何撤消git checkout文件中未提交的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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