简体   繁体   中英

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.

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.

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?

According to the documentation of git here :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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