I originally wrote this article for Codementor in October 2014. It should have something for everyone, from fairly new git users to experienced developers.
Sometimes the best way to get a feel for a problem is diving in and playing around with the code. Unfortunately, the changes made in the process sometimes turn out to be less than optimal, in which case reverting the file to its original state can be the fastest and easiest solution:
git checkout -- Gemfile # reset specified path
git checkout -- lib bin # also works with multiple arguments