Check git history for a range of lines in VSCode
Asked Answered
R

2

15

Is it possible in VSCode to show git history for a range of line ?

Let's say I have 1000 commits concerning this file, and a range of line in this file had its last change on commit 24, I have to check 976 commits in the editor.

I saw something related here, but is it possible directly in the IDE?

Rosio answered 4/2, 2022 at 13:54 Comment(0)
M
7

You can see the commits related to only a set of lines by using the Gitlens extension.

That provides two functionalities, "File history" and "Line history", that are accessible from the VCS menu once Gitlens is installed.

In the "File history" tab you can see all the commits related to the currently viewed file, whereas in the "Line history" tab you only see the commits related to the currently selected lines.

Example below:

enter image description here

This is the gitlens documentation reference.

Mort answered 1/2, 2023 at 10:0 Comment(4)
Just a comment, I don't see the "Line History" panel in GitLense 13 Free version, VSCode version 1.75.1. The settings file does have the line gitlens.views.lineHistory.enabled, but it says that this setting is deprecated and not used. In my case the "File History" is good enough, but I doubt its little drop list can handle 1000 commits. Which is unfortunate. Imho, this is exactly the feature for GitLense inside VSCode. I don't think that just committing stuff inside VSCode is that useful.Macmahon
weird, I have vscode 1.75.1 and gitlens 13.2.0 and it works fine. You may try to right-click on another tab of the VCS menu, like file history, tags or branches, and see if you can check the line history option. That is the way I discovered it. Anyway, I don't know if this feature can handle so many commits, but I think it may be useful in many situations.Mort
you are absolutely right, it is in the right-clicked list! thanks! Indeed, this is a perfect git feature for a text editor. Most often I just need to look up how the line changed from the previous commit.Macmahon
For anyone else struggling to find the line history, using vscode 1.81.1 I was able to find it under the "GitLens Inspect" icon button and not the "GitLens" button ....Try
P
0

I'm not aware of a way to do exactly what you ask for; and I'm not sure if it's at all possible (or what the exact semantics of it would be).

The closest workaround for me is to use the GitLens VSCode extension and specifically its Blame functionality.

Psia answered 13/1, 2023 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.