Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set VSCode as Git Blame & Git History Viewer?

I know I can install the GitLens extension and view the Git Blame & Git History when the file is open. What I would like to know is how to set this automatically in my .gitconfig file.

I'm expecting the behaviour to be similar to git gui blame & gitk where it launches VSCode and instantly I can see the blame annotations or history panel.

Here is how my .gitconfig file looks like now:

[credential]
    helper = store
[user]
    email = [email protected]
    name = MyName
[core]
    editor = code --wait
[diff]
    tool = vscode
[difftool "vscode"]
    cmd = code --wait --diff $LOCAL $REMOTE
[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = code --wait $MERGED
[cola]
    spellcheck = false
    expandtab = true
    blameviewer = code --wait **What should this line be?**
[gui]
    editor = code
    historybrowser = code --wait **What should this line be?**
like image 655
Type Definition Avatar asked Oct 19 '25 20:10

Type Definition


2 Answers

The git blame and git log commands pipe their output to a pager instead of an editor, so you have to set the core.pager setting in your git config.

Try this:

git config --global core.pager 'code --wait'

Then run git blame <file> and it will open VSCode.

I don't have VSCode to test this, but this likely just opens the normal output of git blame in VSCode. VSCode probably won't automatically reformat the output and put the annotations in the gutter of the IDE window. It will look the same as running the command on the CLI with the default pager.

like image 68
BrokenBinary Avatar answered Oct 21 '25 12:10

BrokenBinary


open the file in VSC and click the git icon in the editor title menu.

like image 26
rioV8 Avatar answered Oct 21 '25 11:10

rioV8