To check a single file from a specific Git commit, just specify the commit and file path in
git checkout command.
$ git checkout <commit> -- <file-path>
# Checkout asset/css/style.css from commit 8bc723c
$ git checkout 8bc723c -- asset/css/style.css
# Checkout asset/css/style.css from the parent commit.
$ git checkout HEAD~ -- asset/css/style.css
To discard the changes of a file no matter it is staged or not:
# Undo modifications of a file from working tree and index
$ git checkout -- <file>
# Undo modifications of index.php
$ git checkout -- index.php
git status tells you how to undo the changes:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
stash command is a safer way to discard changes, because it allows you to revert the changes again. See stashing changes for how to use it.