试图用 Homebrew 软件更新我的 git,但我遇到了这个问题:
MBP:GitHub_Tutorial nasdas$ brew install git
Warning: git 2.21.0 is already installed and up-to-date
To reinstall 2.21.0, run `brew reinstall git`
MBP:GitHub_Tutorial nasdas$ git --version
git version 2.17.2 (Apple Git-113)
最佳答案
大概您安装了两个版本,彼此独立。
使用type git
或which git
查看您正在运行的是哪一个。可能是 /usr/bin/git
。 brew 安装的可能是 /usr/local/bin/git
。更改您的 $PATH
(或 $path
或您的 shell 使用的任何内容)以将 /usr/local/bin
放在 /usr/之前bin
以便 git
运行新的而不是旧的,或者使用 /usr/local/bin/git
来运行新的。
(并且,作为 Greg Bacon notes in a comment,请注意,您可能必须在各种 shell 中运行 hash -r
,以便在 /usr/local/bin 中安装某些内容后让它们再次检查
,如果他们已经决定 git
意味着 /usr/bin/git
即使 $PATH
有 /usr/local/bin
较早。在 csh/tcsh 中,这是 rehash
而不是 hash -r
。)
(事实证明这是哈希问题——你的 shell 早些时候决定 git
意味着旧的。再次登录也清除了这种东西,但这很痛苦! )
关于git --version 命令返回与实际安装的不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54871498/