Git 的便携式 VSCode - 相对 Git 路径

Portable VSCode with Git - relative Git path

我正在尝试使用 Git 设置 VSCode 的便携版本。我将 portable git 放在 VSCode 可执行文件夹中,在 .\tools\Git.

我使用以下内容编辑了设置文件:

{
    "git.path": "C:\my-folder\tools\Git\bin\git.exe"
}

而且这种方式效果很好。

但是如果我更改为以下内容,git 将不再起作用:

{
    "git.path": ".\tools\Git\bin\git.exe"
}

根据我的研究,VSCode 似乎不支持设置文件中的相对路径。

有人知道解决这个问题的方法吗?

我使用的解决方法是:

  • 设置VSCode设置中的PATH
  • 通过脚本启动 VSCode,该脚本将首先设置 %PATH% 和 VSCode 工作所需的文件夹,包括 C:\my-folder\tools\Git\bin

该脚本(可以在 C:\my-folder\tools 中)可以:

  • 找到自己的路径(当前所在的位置),
  • 将该路径用作其他相对于自身的路径的基础。

它可以开始于:

@echo off
setlocal enabledelayedexpansion

for %%i in ("%~dp0.") do SET "script_dir=%%~fi"
cd /d "%script_dir%" || echo "unable to cd to '%script_dir%'"&& exit /b 1

set PATH=%PATH%;%script_dir%\Git\bin
%script_dir%\VSCode\bin\code.cmd