how.wtf

Reset a single file in Git

· Thomas Taylor

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.txt

The 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/MyFile

The -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.txt

Anything after the -- is treated as a filename in unix.

#git  

Reply to this post by email ↪