As of git 2.22+:
To undo uncommitted changes to a directory:
git checkout --no-overlay -- <directory>
To reset a directory to its state as of a specific commit:
git checkout --no-overlay <commit> -- <directory>
How to revert a folder to a particular commit by creating a patch
Prior to git 2.22:
WARNING: These methods will also delete git-ignored files from the directory.
To undo uncommitted changes to a directory:
rm -rf <directory>
git checkout -- <directory>
To reset a directory to its state as of a specific commit:
rm -rf <directory>
git checkout <commit> -- <directory>
Note: git checkout <directory>
by itself is a terrible answer. In simple cases it will do the right thing, and in advanced cases it will do the wrong thing but give the appearance of working. This is because git reasons about files, not directories, and in the case of checkout git will only update files that existed in the code being checked out. Therefore you need to use the --no-overlay flag (2.22+) or need to first delete all files in that directory.