Check history of specific line in vscode
You can check the history of a specific line in VS Code using the built-in Git Blame feature or the Timeline view. For a much more powerful experience, the free GitLens extension is highly recommended.
Method 1: Using the Built-in Git Blame
This feature displays the commit information for every line of the current file directly in the editor.
- Open the file you want to inspect.
- Open the Command Palette:
- Windows/Linux:
Ctrl+Shift+P - macOS:
Cmd+Shift+P
- Windows/Linux:
- Type
Git: Toggle File Blameand press Enter.
This will add an annotation to every line, showing the commit hash, author, and date of the last change. You can hover over the annotation for more details, including the full commit message and a link to open the changes.
To turn it off, simply run the Git: Toggle File Blame command again.
Method 2: Using the Timeline View
The Timeline view provides a chronological history of a file, allowing you to see how it evolved.
- Open the file you want to inspect.
- In the Explorer panel (the file icon in the left-hand sidebar), find the Timeline view. It's usually located below the list of files.
- If you don't see it, right-click the "Explorer" title bar and make sure "Timeline" is checked.
- The Timeline view will now show a list of all commits that have modified this file, ordered by date.
- Clicking any commit in the list will open a diff view, showing you exactly what changed in that specific commit and highlighting the lines that were added, removed, or modified.
Method 3: Using the GitLens Extension (Highly Recommended)
GitLens is a free, powerful extension that supercharges VS Code's built-in Git capabilities. It's the most common way developers interact with line history.
-
Inline Blame: After installing GitLens, it automatically adds a subtle blame annotation to the current line you have selected. This annotation shows the author, date, and commit message without cluttering the entire file.
-
Rich Hover Details: Hovering over this inline annotation gives you a pop-up with deep details about the commit, links to view the changes, and more.
-
Toggle Full Blame: GitLens also adds a "Toggle File Blame" button to the editor's title bar (near the top right), which works like the built-in command but with a richer interface.
For checking line-by-line history, GitLens provides the fastest and most detailed experience.
Sources
Here are the sources for checking Git history in VS Code:
- VS Code Built-in Git Support (Blame):
https://code.visualstudio.com/docs/editor/versioncontrol#_git-support - VS Code Timeline View:
https://code.visualstudio.com/updates/v1_40#_timeline-view - GitLens Extension Marketplace:
https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens - Git Blame Concept (Atlassian):
https://www.atlassian.com/git/tutorials/git-blame
