Tag: windows-only

How to revert changes in Visual Studio – 085

Yesterday’s tip talked about how to use `git revert` from the command line. Today’s tip describes the functional equivalent in Visual Studio.

TBH I clicked the wrong command in VS initially when I started writing this post. I clicked “reset ” then the “–hard” option, which should have been a hint. Revert doesn’t have the soft, mixed, or hard options. But, I was able to fix my git history (by going to the command line) to write this tip without deleting my .git folder and starting over, which is a first for me. So perhaps all this work writing out these tips is working!

Let’s say you have a console application that shows a blue background. And you’re like “no.”

console app with blue background

You want to remove this commit altogether. If you’ve been committing in small, atomic chunks of code, you should be able to revert this background color change. But don’t take my word for it. I wouldn’t know because I’m still trying to train myself to do small commits.

Going to the history shows where this change was introduced, i.e. “added ChangeColors()”. You can revert this commit by right-click and selecting “Revert.”

History - Revert on selected commit

Click Yes on the confirmation prompt.

If you refresh History, you’ll see the new commit.

Revert "added ChangeColors()"

You can double-click to open that commit’s details. If you edit the commit message, the Amend Message option will become available.

reverted commits details

Double-clicking on the Program.cs file listed under Changes for the Commit Details pane shows what’s been removed or “reverted” from the codebase.

Changes for Program.cs showing the ChangeColors method removed

And to verify we are back to our familiar console application background, let’s run the project.

default black background for console app

How to use the VS status bar buttons as a shortcut to Team Explorer panes – 083

Something new in Visual Studio 2015 and still there in Visual Studio 2017 is the ability to click buttons(!!!) in the status bar O_O.

You can switch branches without having to touch the Team Explorer pane.

branches button shown in status bar w list of branches to checkout

You can jump to the Connect pane, which will save you time when you’re debating “is it the Home icon or the green Plug icon?”

repo button in status bar showing Connect pane

Yeah, I guess I need to get around to deleting deletemetoday one of these days…

You can jump to the Changes pane, regardless whether you have uncommitted changes (or staged changes as shown in my screenshot – yeah SDET skills die hard).

This button won’t automatically commit your changes, but only takes you to the pane.

pen or pencil icon button for Changes pane

And last but not least, you can jump to the Sync pane. Again, it doesn’t perform any commands other than just navigating to the pane.

up arrow button for Sync pane

Looks like you can click the Line, Column, and Character status bar “buttons” and new UI appears for Visual Studio 2017!! (provided you have a file opened).

Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips
Must focus on Git and GitHub tips

Okay, it looks like if you double-click on any of those status bar buttons, you’ll get a new Go To Line dialog, which seems to be part of a global search window…

new Go to Line window in VIsual Studio 2017

but it doesn’t seem to let you specify columns or character positions.

Yeah, old habits die hard, even when trying to focus.

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.

How to open a GitHub repo that does not contain a solution in Visual Studio 2017 – 079

In recent years, I started dabbling in ruby, node.js, electron, etc. As time passed, I (somehow) forgot the notion of a “solution” file. I know that sounds exaggerated or cra-cra coming from me, but hold on. I’ll explain. To open an electron application (e.g. your moment of GitHub Zen app) in a non-VS editor like Atom, you’d simply `cd` into the root folder of where you cloned your repo and type in `atom .` The dot in the `atom .` means open all the files listed here.

View solution-less repo in Atom

And there in atom, you’ll see a similar experience to Solution Explorer, but instead of a solution file at the top, you see the root folder.

atom with an electron app opened

View solution-less repo in Visual Studio 2015

Now let’s say you connect to the your-moment-of-GitHub-zen repo via Team Explorer in Visual Studio 2015. But oh-no! Your solution explorer will be empty. After spending a year using Atom, it’s really odd feeling when none of your files appear available in your editor. (See! I told ya’ll I could justify forgetting about a solution file!)

Solution Explorer just looks at you

You might hope that Team Explorer will have some sort of solution available… (boom! did you see what I did there with that play on words re having a solution for not having a solution? thank you! I’m here all week…)

No solutions available

The workaround is to manually File – Open – File your files and use Team Explorer to manage your changes (or command line – I guess you can’t have too many options).

View solution-less repo in Visual Studio 2017

Hello Visual Studio 2017! What do we have here??

Show Folder View

Let’s see what this Show Folder View button does…


And there we go! You can now open a project in Visual Studio without requiring a solution. I’ve spent all of 2 minutes playing with this new feature, so I’ll have to learn where to go from here!

How to use the arrows in the View History graphs in Visual Studio – 078

There was a saying back in Mountaineering Search and Rescue* in Seattle about why you should *never* pack cotton-based clothes in your cold-weather gear. It went like, “No matter how far down you pack cotton in your bag, water will find it.”  I feel the same about Visual Studio. “If there is a clickable pixel somewhere in Visual Studio, no matter how small or obscure you place it, I will find it.”

As I was prep’ing yesterday’s tip, I noticed that the View History graph showed these arrows pointing in various directions. TBH I had to ask someone to explain what the arrows meant.

Graph with arrows pointing down

If you click on this downward-facing arrow, a connector line will appear!

graph connecting line shown going offscreen

The connector line will go all the way down off screen until it reaches its commit.

connecting line reaching its commit

The idea behind these arrows is to show you that they connect to a commit that’s not currently visible on the screen.

BTW, the arrows can also point upwards as well, reaching back up to its counterpart in the graph.

arrows pointing in either direction

*So yeah, about search and rescue, well over 10 years ago, genius here wanted to volunteer to learn more about hiking and volunteer my time and whatever skills to helping out, since I love the outdoors so much. Only one small problem… I hate the cold! And I had never camped in the cold before, and at that time anything below 70 was considered cold to my NOLA standards. Anyways, it was 27 degrees one particular weekend of training. I made it the first night, but was never able to get to sleep. The second night I dropped out so my partner (who was kicking butt and taking names) could find other same skill-level people so she could pass. But yeah I still laugh at the thought of me thinking I could go find people lost in the woods when I get lost driving down the street!

How to open files in a repo that doesn’t contain a solution in Visual Studio 2015 – 075

tl;dr if you have a repo that doesn’t have a solution, don’t worry. You can still use File – Open – File to open files associated with the repo and Team Explorer will still track those files the same as if a solution were open.

P.S. I’m writing these tips for VS 2015. I’ll need to update for Visual Studio 2017.

For all my adult life (minus 2 years), the Solution file was your go-to starting point in Visual Studio. Even if you create a new text file via File – New – File, Visual Studio creates a new Solution nevertheless.

a solution still appears

It’s almost like Visual Studio has a Solution that’s in search of a problem.

bear w meme text "thank you thank you i'm here all week"

Can’t believe I’ve never thought of that one before… Anyways…

Repos that do not contain a Solution

If you open a repo that doesn’t have a solution in it, you’ll see the following:

no solution found

You can still go to File – Open – File and open files that are associated with that repo. In fact, File – Open – File will open to that repo’s folder.

Opening a different Solution when Team Explorer is connected

A solution will always take precedence over a repo opened in Team Explorer.

For example, in the previous screenshot, I have a repo named “amend” that’s open, but this repo doesn’t a Solution. If I open a different solution that does not contain a repo, you’ll see that Team Explorer goes offline.

Team Explorer Offline

I guess this is Team Explorer’s way of saying, “Hey Look, I don’t want you to get confused which solution is tied to which repo.”

Switching to a different Repo with a Solution Open

Now having said that, let’s suppose I’m connected to a repo that has a solution, let’s say some ConsoleApplication54 project (you know you have them!) and you have the ConsoleApplication54 solution opened.

If you switch repos (via Team Explorer – Manage Connections) to any other repo, regardless whether it has a solution file opened, you’ll be in an odd state. On one hand you’ll have a solution opened, but Team Explorer will be tracking changes for an entirely different repo. This is the state you couldn’t get in to in the previous section.

It’s almost like a Game of Thrones battle (or so I’m told – haven’t seen or read yet) being played out inside the IDE: solutions vs repos.

How not to quit your career when Git opens a vi editor – 072

There’s a joke, “How do you generate a random string? Put a Windows user in front of vi editor and tell them to exit.” Credit to Aaron Jorbin.

Suppose you’re doing research on the git commit –amend -m “some message” command and you forgot the -m “some message” part.

Everything spins around and suddenly I’m elsewhere…*

vi editor - one of the scariest images a Windows user will ever see

I’m in a sandy beach on a tropical isle.

Actually, you’re in the vi editor. Before you start typing anything, stop. Get up, stretch your legs. Odds are you’ve been at your desk for way too long anyways 🙂 Get some coffee and come back and search google what to do before you start typing.

If you are like “Say Yoho! SAY YOHO!!!*” to get out of here without making any changes, you’ll want to hit ESC and then type :q! Don’t think about it. just do it.

typing in the command :q!

You can verify in the git log that the amend had no impact.

*The reason I got into computer programming was because of Scott Adam’s Pirates Adventure text-based adventure game for the TI-99 4A Home Computer. As a 6 year old, it fascinated me how a computer could understand some English commands (get safety sneakers) but not others (open refrigerator – you are in a kitchen after all!) “Say Yoho!” was the command to jump to a different part of the island. Say it too many times in a row and you’d die (I think). Never beat the game as a kid, but later in college, I downloaded an emulator and finally got past those crocodiles!