4

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 = MyEmail@hotmail.com
    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?**
Type Definition
  • 75
  • 1
  • 13
  • [docs for vscode cli interface](https://code.visualstudio.com/docs/editor/command-line). looks like there's nothing very direct to do this. brainstorming: create a wrapper script that takes the args and sets up a temporary folder with a `./.vscode/task.json` that [executes a vscode command to do an extension action](https://stackoverflow.com/q/57470525/11107541) [upon opening the folder](https://stackoverflow.com/q/34103549/11107541). – starball Sep 06 '22 at 03:06

2 Answers2

2

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.

BrokenBinary
  • 7,731
  • 3
  • 43
  • 54
  • 1
    For future reader's reference: There isn't actually a working solution for this question right now. Such actions simply isn't supported in VSCode as of 2022. – Type Definition Sep 13 '22 at 02:47
1

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

rioV8
  • 24,506
  • 3
  • 32
  • 49