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.
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
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).
git checkout myfile.txt
git restore myfile.txt
Discard all changes in the entire repo.
git restore :/
Discard all changes in the current directory (and sub-directories)
git restore .
2.23.0 also introduced git switch.