简体   繁体   中英

GIT I want to cancel my checkout and get not committed changes back ! (Can I do that ?)

I have done commit. Next I made some changes to a file. Then I run the command checkout for only one file. Which looks like this:

git checkout HEAD^ filename.php

That did not help me at all. So I would like to cancel my checkout. THE QUESTION IS: Can I go back to not only last committed but also to changes made after (not committed)?

Thanks for your help: :* Love You all :)

PS: I got the answer in comments bellow. To save you time guys. The answer was NO: :(

The modern command (since Git 2.23, Q3 2019) would be git restore :

git restore -- filename.php

It would restore the file content from, by default, HEAD.

But it would also overwrite the original content (local uncommitted changes), leaving you with alternatives like a VSCode timeline to get your local modification back.

A git restore -p or -m would at least attempt to merge hunks of code between the restore source and the restore location, instead of blindly overwriting everything.

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