How to Quickly Revert Changes in Git

Sometimes you experiment with a new feature and you decide not to use a certain library or an approach. You need to revert back to the previous working version. I was working with flip.js jQuery plugin and decided not to use it. The git status shows the files that were modified.

$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:   app/assets/javascripts/application.js
    modified:   app/assets/stylesheets/application.scss
    modified:   app/controllers/welcome_controller.rb
    modified:   config/routes.rb

You can list only the modified files like this:

$git ls-files -m

no changes added to commit (use "git add" and/or "git commit -a")

You can now combine xargs with this output to revert your changes.

$git ls-files -m | xargs git checkout
$git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Related Articles

Create your own user feedback survey