Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 455
Brady Moritz Avatar asked Mar 05 '11 01:03

Brady Moritz


People also ask

How do you revert a file to previous commit in Visual Studio?

To do the same in Visual Studio, right-click the commit you want to revert and then select Revert. After you confirm your action and the operation is complete, Visual Studio displays a success message and a new commit appears in the Outgoing section.

How do I revert a single file in Git Visual Studio?

To revert changes made to a file in the working directory, just choose "revert changes" from the context menu in Visual Studio.

How do I revert a git commit extension?

Locate the commit you want to revert in the Log tab of the Git tool window Alt+9 , right-click it and select Revert Commit from the context menu. This option is also available from the context menu of a commit in the file History view. The Commit Changes dialog will open with an automatically generated commit message.


2 Answers

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.

like image 103
Henk Avatar answered Sep 17 '22 06:09

Henk


While the technique suggested by @Henk will work, here's the Git way.

  1. Select the commit that changed the file you wish to revert.
  2. 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.

like image 32
Sri Sankaran Avatar answered Sep 19 '22 06:09

Sri Sankaran