How to find when a line was last changed in Visual Studio – 080

Previously, I mentioned how to use Blame on GitHub.com to find the commit that changed a specific line. Today we’re going to rinse and repeat this scenario within Visual Studio.

I told think anyone ever realized how scared I was of the world (if not plain neurotic) as a small child. I remember once in first grade (6 years old) being asked by the teacher for the answer to a multiple choice question. I thought it was ‘D’ but the answer was ‘C’. When the teacher said no that was wrong, I broke down sobbing from fear and embarrassment. I didn’t know what was going to happen to me for getting it wrong. I thought perhaps I’d get into serious trouble when I got home or lose my recess or something. Unfortunately, the teacher completely misread why I was crying (she thought I was acting out for attention) and scolded me, etc., which was my first foray into the self-fulfilling prophecy*.

I share this story because the first time I saw “Blame” on GitHub, I felt the same emotion as I did as a little kid. Why would I ever want to put myself into a position of having people call me out publicly via my code and blame me? But as I said in my previous post, Blame doesn’t mean “to imply blame” but rather “look up the commit that changed this line of code.”

I was happy to see this command referred to as Annotate in Visual Studio 2015, but a bit saddened to see now called Blame (Annotate) in Visual Studio 2017. I get it. I get it. When in Rome… but I often muse what would be the equivalent of commercial airline pilots who have to reskill like we do in the software industry. Would they start lowering the landing gear prior to take off? Would they refer to Air Traffic Controller as Air Traffic View or Air Traffic Model? (see what I did there? #PointsMe!)

In today’s scenario, I want to know two things:

  1. When was a specific line of code changed? as in, which commit changed a given line of code?
  2. What changed in that line?

1.  open the file that contains the line in question (either via Double-Click in Solution Explorer or File – Open – File provided you are connected to the repo in Team Explorer)

2. anywhere in the file, right-click and select Source Control – Blame (Annotate)

Source Control - Blame (Annotate) in context menu for file

The Blame / Annotate window will appear on the left hand side. This window shows for each line what was the last commit that modified it.

Annotated window shown for a given file

In the above example, lines 1-2 were last modified by commit ID 44af5057 (most likely my initial commit). But line 3, the one I’m interested in, was last modified in commit fd80ad89.

As any long time Visual Studio user will do… let’s click the fd80ad89 and see what happens!

Commit details for the last commit that modified line 3

Seeing the Commit Details appear in Team Explorer answers the part one of my scenario – the when. Now it is time to figure out the what – what was changed in the line…

TE - Commit Details - Changes - main.js - Compare with Previous

By clicking on the Compare with Previous… command in the context menu for the main.js file listed in the Changes list for that commit, you’ll see the file diff view appear.

"Tray" shown added to list of const

And now we  have “the what” for what has changed in the file. The “Tray” const was added to the list, giving it a type of Electron.Tray, so I could put the app in the Taskbar tray (or Mac tray thingy at top of screen).

*Sometimes I wonder if I’m the reincarnation of Rod Serling (technically, he died before I was born) or a zen master looking for a challenge. But then again, I’ve always hated smoking, so I’m not the former. And during the Visual Studio 2017 Launch Event when they were showing my Happy Birthday Visual Studio video, I was at home yelling at the Yoga DVD Instructor over the “share  your breath with the community” breathing stuff, so it can’t be the later either.

2 thoughts on “How to find when a line was last changed in Visual Studio – 080

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s