Git – Revert File to Previous Commit

Sometimes it happens that you make some changes to a file but later realize that it was a mistake and these changes have to be discarded.

In Git you can revert the changes made to a file if you haven’t committed them yet, as well as you can revert a file to any previous commit.

Here i will show how to revert a single file to a specific revision and how to reset an uncommitted file to the initial master’s state.

Cool Tip: Want to look back to see what has happened with one particular file? Find out the commit history of this file, history of diffs and up to the history of renames! Read more →

Git – Revert Changes to File

Revert (reset) changes to a file if they haven’t been committed yet:

$ git checkout -- <file>

Git – Revert File to Previous Commit

Revert (reset) a single file to a specific revision:

$ git checkout <commit_hash> -- <file>