How to Git Revert a File to a Specific Commit?

How to Revert a Single File to an Older Commit?

You can use the following command to revert a file to an older version in another commit simply by specifying the commit hash and the file you wish to revert:

git checkout 45db03581b3b5581ed7cc44dbc -- file/to/restore

Basically, it has the following syntax:

git checkout <commit-ref> -- <filename>

How to Revert Multiple Files to an Older Commit?

If you wish to restore multiple files to a version in an earlier commit, simply append more file names at the end (separated by a space). For example:

git checkout 45db03581b3b5581ed7cc44dbc -- file1/to/restore file2/to/restore

This post was published (and was last revised ) by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.