How to revert uncommitted changes to files of a certain type in git

Mujo Osmanovic picture Mujo Osmanovic · Feb 13, 2013 · Viewed 11.9k times · Source

I have a bunch of modified files in my git repository and a large number of them are xml files. How do I revert changes (reset modifications) of only the xml files?

Answer

CharlesB picture CharlesB · Feb 13, 2013

You don't need find or sed, you can use wildcards as git understands them (doesn't depend on your shell):

git checkout -- "*.xml"

The quotes will prevent your shell to expand the command to only files in the current directory before its execution.

You can also disable shell glob expansion (with bash) :

set -f
git checkout -- *.xml

This, of course, will irremediably erase your changes!