Reset a single file in Git
Resetting a single file is possible using Git.
How to restore a single file
In Git versions 2.23 and higher, git restore natively supports resetting a single file.
1git restore path/to/file.txtThe above restores path/to/file.txt to the prior commit.
In addition, restoring from another branch is possible:
1git restore -s my-feature-branch pathTo/MyFileThe -s option specifies a source (my-feature-branch in this case).
How to reset a single file
In Git versions that predate 2.23, the following command will reset a single file:
1git checkout HEAD -- path/to/file.txtAnything after the -- is treated as a filename in unix.