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>
Was it useful? Share this post with the world!

9 Replies to “Git – Revert File to Previous Commit”

  1. Thanks!

  2. Munees Selvaraj says: Reply


  3. thanks

  4. thank you

  5. Thanks

  6. For git checkout, I remember that there is some shorthand notation for the number of previous commits that you want to revert back to.

    eg HEAD~1 HEAD~2 . could you go into detail on that in another article?

  7. Gaurav Acharya says: Reply

    thanks helped

  8. Thank you – perfect!!!

  9. Alfonso Baqueiro says: Reply

    What does the


Leave a Reply