Get Git Blame insights directly in VS Code using GitLens

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet

Whenever I need to make a change to a file that includes a part I don't grasp I try to gather as much informations as possible. One tool that turned out to be very helpful to build up context was seeing who wrote the code & when.

In this lesson I demonstrate you how this can easily be achieved using the VS Code GitLens extension and how to set it up in a way that it's not constantly bothering you.

Instructor: [0:00] Let us install the VS Code extension, Gitlens. Then, let's open a file inside a Git repository. In my case, I'm opening the tooltip implementation of the read GI library. Once you install gitlens, you will see an annotation next to every line.

[0:18] Here, you can see where I made a change five month ago. If you hover over it, you also can see further details of this commit. On the next line, [inaudible] changes three months ago. The same information will also be available in the bottom toolbar.

[0:35] Having this information is especially great if encountering a line with a purpose you don't understand and potentially want to change it. Having the information who wrote the line and when provides a lot more context to help you making better decisions.

[0:50] If this is yet not enough, you can activate the Blame limitation for the whole file with the icon on the top right. Select the commit and see which parts of the file were manipulated with the same commit.

[1:04] Personally, I don't need the commit information all the time and I'd rather prefer a cleaner editor view. If you do two, I recommend turning off the current line limitation but keeping the bottom bar. You can do this by opening the UI settings, filter by GitLens current line, and deactivate the option. As you can see, the notation is not visible anymore, but the bottom toolbar still is.

[1:33] By the way, when you click on the bottom toolbar, a dialog will pop up giving it tons of options, like opening a commit in GitHub or open a revision of this file with this commit.