我有两个版本的 Git 和一个正在使用的旧版本。我该如何解决?

I have two versions of Git and old one being used. How can I fix it?

由于历史原因,我的 Windows 10 机器上有两个版本的 git。

$ where git C:\Users\xxxxxxxxx\AppData\Local\Atlassian\SourceTree\git_local\mingw32\bin\git.exe C:\Program Files\Git\cmd\git.exe

SourceTree 以某种方式使用了前者,但它已经过时了 (2.7.4)。 后者是最新的 (2.17.1.2)。

我猜是关于某个地方的 PATH 设置,但我不知道。

这是相关的,但我认为对于其他平台。 Two versions of git installed, currently using old one, how do I switch?

我看了这个,但没有帮助。 https://confluence.atlassian.com/bitbucketserver/installing-and-upgrading-git-776640906.html#InstallingandupgradingGit-InstallorupgradeGitonWindows

您的链接问题有正确答案 - 您需要更新您的 PATH 变量。

从终端确保当前 PATH 中的 git.exe 不正确:

echo %PATH%

然后复制结果,用新的替换旧的git,并更新PATH:

set PATH=<updatedpath>

如果您在某些 GUI 工具中使用 git,它可能在配置中将路径存储到 git.exe 某处,您需要找到此选项并更新它。

的输出

echo %PATH%

包括C:\Program Files\Git\cmd,即新版本。所以我想 SourceTree 必须有一些覆盖 PATH 的东西。

然后我想可以是SourceTree偏好。工具 > 选项 > Git 选项卡有 Git 版本 窗格,您可以在其中选择“嵌入式”或“系统'。在我的例子中,选择了“嵌入式”。它旁边有一个“更新嵌入式”按钮。那个按钮完成了工作!

我通过 SourceTree 的通知意识到 Git 版本太旧,但它没有告诉我在哪里以及如何更新它。