Revert a file to a specific Git commit

With Git command line

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

  • git checkout <commit> -- <file-path-1> <file-path-2> ...
    • 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.

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

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.

Rename a branch with SmartGit.