在使用VScode更新Git时,我遇到了问题(Mac电脑)。

3

基本上,我正在尝试在我的Mac上更新git,我正在使用VScode,并将其中一个终端作为powershell打开,因此我使用命令检查其版本:

git --version

我从中得到的是:
git version 2.15.0

所以我以为我没有更新它,于是我使用了命令

brew upgrade git

我收到了一个回复,内容是"警告:git 2.34.1 已经安装",但我再次检查发现git版本仍然是2.15.0。

您有什么想法可以解决这个问题吗?


问题的根源在于brew install安装了一个额外的Git版本,因此现在你有Git 2.15.0和Git 2.34.1。这意味着你必须先引导运行git的任何程序查找安装的brew版本,然后再查找系统安装的版本。正如VonC回答的那样,有多种方法可以实现这一点。 - torek
2个回答

5

大家好,感谢所有评论提供的建议和解释。最终,在尝试了一段时间后,我做到了以下几点!

首先打开终端并运行 brew install git

然后在终端中会得到以下回复:

Linking /usr/local/Cellar/git/2.34.1... 
Error: Could not symlink bin/git
Target /usr/local/bin/git
already exists. You may want to remove it:
  rm '/usr/local/bin/git'

To force the link and overwrite all conflicting files:
  brew link --overwrite git

To list all files that would be deleted:
  brew link --overwrite --dry-run git 

于是我运行了这个命令

brew link --overwrite git

我收到的回复是:
Linking /usr/local/Cellar/git/2.34.1... 213 symlinks created.

之后运行以下命令。
brew link --overwrite --dry-run git

收到以下回复:

警告:已链接:/usr/local/Cellar/git/2.34.1

要重新链接,请运行:
brew unlink git && brew link git

于是我最终运行了一个检查来查看git的版本是什么。

git --version

我终于得到了我想要的更新版git,而且我已经将路径对齐了!

git version 2.34.1

希望这能帮助需要帮助的人!我没有移除 "/usr/local/bin/git",但希望我不需要或以后不必担心它。

太棒了,即使我已经正确导出了PATH到最新版本,仍然无法获取它,但现在它可以工作了。 - George Tiganila

1

如果你在 macOS Monterey 上使用,需要确保 homebrew/bin 文件夹在 $PATH 环境变量中处于首位:

export PATH=/opt/homebrew/bin:$PATH

然后执行 git --version 命令,应该会返回最新的版本号。
您可以参考这里的不同选项,例如在您的 .zshrc 或者 .bashrc 文件中添加 alias git="/usr/local/bin/git"


当我输入命令时,会收到以下回复:"export: The term 'export' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again." - Jahanzeb Ahmad
1
@JahanzebAhmad 首先,请确保您拥有 macOS Monterey 操作系统。其次,将该行代码添加到您的 ~/.bashrc~/.zshrc 中。然后打开一个新会话并启动 VSCode,以使该 IDE 能够从新的 PATH 中继承。 - VonC

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接