How do I discard the changes to a single file and overwrite it with a fresh HEAD copy? I want to do git reset --hard
to only a single file.
Question
Answer
To reset both the working copy of my-file.txt
and its state in the Git index to that of HEAD:
git checkout HEAD -- my-file.txt
--
means "treat every argument after this point as a filename". More details in this answer. Thanks to VonC for pointing this out.