Visual Studio Tip #9: You can edit directly in the Diff tool


Here is one I just discovered just last week by accident. When you are doing a diff on a file to compare what has changed from the source control, the diff window can be used to edit the file directly. (works on both Git and TFS source control)

I always assumed the window was just a read only view, but on a whim I tried it and it works. This is nice because, in my workflow, I typically do a diff of my files before I check them in to ensure that I don’t have any unwanted edits still hanging around. But without this, I would have to do a diff, take a note of where the unwanted change is, go open the original file and make the edits, then do a new diff on the file again (rinse and repeat).

For example, look at the following diff view. You can see that I added a lot of code to this file, but maybe during the process I added the namespace “Windows.UI.Xaml.Shapes” which is no longer needed now that I’ve finished the full edit.

image

Traditionally I would have opened GamePage.cs, removed that line, saved it and then done a new Diff on the file. But because this Diff view is live on the file, I can just remove that line in the right hand pane and the Diff updates in real time. In the picture below, note that the green bar (indicating a new line inserted) is now gone from the red circle area.

image

This is also a great way to find and eliminate all that commented out code that people sprinkle around as they make changes but you don’t want to check it in.

(Of course always rebuild and test after you do this before you hit the commit button Smile)

This post is part of a series of Visual Studio tips. The first post in the series contains the whole list.

Comments (3)

  1. Jeff says:

    This was an incredibly useful feature when it came out!
    But it no longer works. Do you know why they removed it, or if it’s possible to turn it back on using configuration?

    1. BenWilli says:

      It does still work. I recently installed a brand new machine with VS 2015 Update 3 plus the power tools and I have that behavior. I’m not sure what could turn it off.

  2. Martin Dunschen says:

    Editing in the diff view works for certain file types, but not all. Unfortunately it does not work for python source code, which is a shame. It looks like this is filed a a bug on the githab pages for python tools for visual studio

Skip to main content