Reverting File Changes With git

This is not obvious to those of us with lingering Subversion habits. If you’ve edited a file and simply want to discard its changes (à la Subversion’s revert), use:

git checkout filename

If it so happens that your file name is the same as a branch, you’ll need to use:

git checkout -- filename

Use the Right Tool for the Job

You may be tempted to use git reset --hard, but that will reset all uncommitted changes. If you just want to undo the changes to a single file, that’s the wrong tool.


This entry was posted in Computer, Programming and tagged , , , , , . Bookmark the permalink.

Leave a Reply