Git version 2.23.0 introduced a new command git restore. This command does a subset of what git checkout does (because git checkout does so many different things). You can continue using git checkout for this functionality but the idea is git restore is clearer for those starting out.
Error Message
If you get the message,
git: ‘restore’ is not a git command. See ‘git –help’.
you’re probably running an older version of git.
In this case, you can run git checkout instead of git restore.
Discard Changes
When you have changes but want to discard them, git restore will discard the changes and restore the file(s) to the state they were in the last time you made a commit.
This is done with git restore <filename> or git restore <directory> (when a directory is given all of the changes in the directory will be discarded).
Old Way
git checkout myfile.txt
New Way
git restore myfile.txt
Get a File From a Specific Branch
When you want to grab one file (myfile.txt) from another branch (develop).
Old Way
git checkout develop myfile.txt
New Way
git restore myfile.txt --source=develop
Other Examples
Discard all changes in the entire repo.
git restore :/
Discard all changes in the current directory (and sub-directories)
git restore .
See Also
Git version 2.23.0 also introduced git switch.
Thanks
Thanks, really useful!