How to Revert a File to a Specific Git Commit

Revert File to Specific Commit

Revert File to Commit

To revert (or reset) the content of one or more files to a specific commit, you can use following command:

To determine the <commit>-ID of the desired commit, you may use some kind of git log --format=oneline <file-path> combined with grep.

This places the target file contents directly into the index.

git checkout <commit> -- <file-path-1> <file-path-2> ...

Considerations

  • If there are any changes for these files in the working tree or index, they will be overwritten without warning! Therefore, it is advisable to (selectively) stash away working tree and index changes beforehand using git stash.

With SmartGit

Revert file to specific commit with SmartGit

In SmartGit, select your desired commit in the Graph view, then choose the target files in the Files view and use Rollback To from the context menu.

You will have the option to place the target file contents either solely in the working tree or also in the index. SmartGit ensures that any local or existing staged changes for the files will not be overwritten.

Try these Git operations with SmartGit's intuitive interface

Download SmartGit
Illustration of Smart Gitty, the SmartGit mascot -- a grey cartoon cat with glasses, sitting behind a laptop