If you've made a mistake on part of a file and want to only revert portions of it rather than the whole file, you can do that using:
git checkout -p the_filename.ext
The -p flag allows you to step through each code chunk and actively select or ignore changes you want to undo since the last commit.
[ Source ]