Undoing modifications of a file in Git

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>

# Examples:
# Undo modifications of index.php
$ git checkout -- index.php

If fact, 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)

        modified:   index.php

Note: 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.