Hard reset of a single file
git
Solution
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.
Problem
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.
Related problems
- How do I stash only one file out of multiple files that have changed?
- Deleting a badly named git branch
- Difference between "git checkout <filename>" and "git checkout -- <filename>"
- Why git can't do hard/soft resets by path?
- What's the difference between HEAD, working tree and index, in Git?
- What is `git restore` and how is it different from `git reset`?
- How can I reset or revert a file to a specific revision?