Remove Unwanted Unstaged Changes in Tracked Files from a git Repository
This article demonstrates how to discard undesired, unstaged changes to tracked files in a git repository with git checkout
so that they do not wind up in your next commit.
Usage
$ git checkout -- [pathspec]
where pathspec
can be a wildcard or file path value.
All Files
To discard changes to all unstaged files use the following command:
$ git checkout -- .
Files by Wildcard
To discard changes to files by wildcard (e.g. by specific file extension type) use a command like this:
$ git checkout -- "*.py"
The above command resets all files with a .py
extension to the index versions.
Files by File Path
To discard changes for a specific file path, include the file path as the argument:
$ git checkout -- somefile.py
The above command will revert the file on the path somefile.py
to the index version.