git --version 命令返回与实际安装的不同的结果

标签 git terminal homebrew

试图用 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 gitwhich 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/

相关文章:

go - 使用不带命令的 PTY

linux - 发送信号到后台处理

homebrew - 错误 : homebrew/science was deprecated. 我该怎么办?

git - Git 和 libgit2 的区别

ruby - 交互式 Ruby 子 shell 有什么意义?

Git 仓库坏了? - 尽管 gitignore 仍然跟踪文件

OSX 10.8 上 Homebrew 软件的 MySQL 错误

macos - 如何抽象ant-contrib跨平台?

git - 用Git记录文件复制操作

git pull 不更新带有 merge 分支的分支