Revert a single file to earlier commit using Git Extensions for Visual Studio
I've found instructions on how to revert a single file in a Git repository to an earlier version. But I am curious if anyone knows of a way to do this using Git Extensions for Visual Studio. This tool works great so far and I really like it, but I can't figure out how to do this one thing.
The easiest way to do this in Git Extensions is to open the file history (e.g., from the context menu in Visual Studio) for the file you want to revert. Then find the revision you need and choose "Save As" in the context menu.
To revert changes made to a file in the working directory, just choose "revert changes" from the context menu in Visual Studio.
While the technique suggested by @Henk will work, here's the Git way.
- Select the commit that changed the file you wish to revert.
- Choose the revert commit operation. Be sure you tell Git Extension not to automatically commit the revert operation. This will result in a) A revert operation on the affected file(s) and b) Reverted file(s) being staged
Then you can unstage the file(s) that you do not wish reverted -- leaving only the one file that you do wish to revert to be committed.
While this might seem more tedious that just File > Save As, it comes in handy when you have to revert a handful of files.
Edited my post. I don't know why I responded about mercurial. Sorry about that. The same idea goes for git. I used tortiseGit (when I used git), but the command line is easier. TortiseGit is still a right click to revert. The command line is just 'git checkout filename' to get the checkout from the HEAD.