git: revert (reset) a single file

I’ve made the leap from subversion to git.  I really like git, but there are a few things that confused me.  One is how to (in svn terms) revert an uncommitted file back to the latest version of the file under source control.

git checkout filename

This will checkout the file from HEAD of the current branch, overwriting your changed file.  Since this is the same command used to checkout branches, if you have a file with the same name as a branch you have to make a slight change.

git checkout -- filename

You can also pull files from any location in your repository like this.  man git-checkout for all the details.

git checkout [<tree-ish>] -- [<paths>...]

If you need to revert (reset) all your uncommitted work, the command is

git reset --hard