如何通过.gitconfig配置VSCode为Git Blame及Git History查看器?
配置.gitconfig让VSCode+GitLens直接启动Blame/History面板
要实现通过Git命令直接唤起VSCode并自动显示GitLens的Blame注释或历史面板,核心是利用GitLens提供的命令行触发参数,替换.gitconfig中blameviewer和historybrowser的配置项,具体修改如下:
修改后的完整.gitconfig配置
[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 --command "gitlens.showFileBlame" $1 [gui] editor = code historybrowser = code --wait --command "gitlens.showRepositoryHistory"
参数说明
blameviewer配置:
code --wait --command "gitlens.showFileBlame" $1--command "gitlens.showFileBlame":指定VSCode启动后直接执行GitLens的显示文件Blame命令$1:传递Git命令传入的目标文件路径,确保打开对应文件的Blame注释
historybrowser配置:
code --wait --command "gitlens.showRepositoryHistory"gitlens.showRepositoryHistory:触发GitLens显示当前仓库的完整历史面板,对应gitk的功能
使用方式
配置完成后,执行以下命令即可直接唤起对应功能:
- 查看单个文件Blame:
git gui blame <文件名> - 查看仓库历史:
gitk
内容的提问来源于stack exchange,提问作者Type Definition
相关产品推荐
相关产品推荐

