Git(2.53.0)在WSL2的 Ubuntu 24.04上未找到凭据管理器

编程语言 2026-07-10
  • 我已经在我的Windows 11机器上安装了Windows版 Git,以及一个全新的Ubuntu 24.04环境(截至2026年 3月 31日)。
  • 随后我在WSL中更新到了最新版本的git(git版本2.53.0)。
  • 接下来我在WSL上配置了git,使其指向Windows端的GCM:
$ git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"
  • 我也验证了直接在WSL内执行时可以正常工作
$ /mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe --version 
13:53:16.515705 exec-cmd.c:266     trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
13:53:16.536324 git.c:502          trace: built-in: git config --null --list
2.7.3+5fa7116896c82164996a609accd1c5ad90fe730a

但当我尝试在GIT中验证凭据管理器的版本时:

$ GIT_TRACE=1 git credential-manager --version
14:00:07.429358 git.c:808           trace: exec: git-credential-manager --version
14:00:07.429399 run-command.c:673   trace: run_command: git-credential-manager --version
git: 'credential-manager' is not a git command. See 'git --help'.

作对比,Windows端的情况如下:

PS C:\Program Files\Git\mingw64\libexec\git-core> git credential-manager --version
14:09:52.227910 exec-cmd.c:266          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
14:09:52.234605 git.c:809               trace: exec: git-credential-manager --version
14:09:52.234605 run-command.c:674       trace: run_command: git-credential-manager --version
14:09:52.234605 run-command.c:935       trace: start_command: git-credential-manager --version
14:09:52.307249 exec-cmd.c:266          trace: resolved executable dir: C:/Program Files/Git/mingw64/libexec/git-core
14:09:52.310246 git.c:502               trace: built-in: git config --null --list
2.7.3+5fa7116896c82164996a609accd1c5ad90fe730a

似乎要么它没有使用提供的git-credential-manager.exe,要么它并未将其放在PATH中

还有谁能确认,或者有解决方案吗?

解决方案

WSL在 PATH中搜索可执行文件时不会像Windows那样自动去除 .exe 后缀。(我觉得老版本的WSL曾经会这样做,也许,但现在不是这样。)

这仍然应该可以工作:

$ git credential-manager.exe --version

我通常通过复制该exe并在副本上去掉扩展名来处理这个问题,但你也可以创建一个指向该exe的符号链接或硬链接,使用截断后的名称,或者每次调用该命令时都带上.exe后缀,或者创建一个别名,或还有其他许多类似的解决方案。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章