简体   繁体   English

如何撤消git checkout文件中未提交的更改?

[英]How to undo git checkout file for uncommitted changes?

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状态,并注意到上演了许多应该被GIT忽略忽略的文件,例如.gitignore,.htaccess和我的Drupal网站的设置文件。

I mistakenly used git checkout <file> instead of git rm <file> to remove them from the staging area. 我错误地使用git checkout <file>而不是git rm <file>将它们从临时区域中删除。 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? 我想我现在知道git checkout会还原对这些文件所做的任何更改,对吗? The changes weren't committed because they weren't supposed to be tracked in the first place. 未提交更改,因为最初不应该跟踪它们。

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 checkout <file> (它的相反意思),现在我可以撤消撤消操作,或者从这里去哪里?

According to the documentation of git here : 根据git的文档在这里

It's important to understand that git checkout -- <file> is a dangerous command. 重要的是要了解git checkout -- <file>是危险的命令。 Any changes you made to that file are gone – Git just copied another file over it. 您对该文件所做的任何更改均已消失-Git只是在其上复制了另一个文件。 Don't ever use this command unless you absolutely know that you don't want the file. 除非您完全知道自己不需要该文件,否则不要使用此命令。

So you can't undo this command. 因此,您无法撤消此命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM