Reputation: 18840
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)?
Upvotes: 1
Views: 112
Reputation: 1323203
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.
Upvotes: 1