如何在 macOS 上将 Git 升级到最新版本? [英] How to upgrade Git to latest version on macOS?

查看:234
本文介绍了如何在 macOS 上将 Git 升级到最新版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚买了一台装有 OS X Lion 的新 Mac,我在终端中检查了默认安装的 git 版本.我得到了答案

I just bought a new Mac with OS X Lion and I checked in the Terminal what version of git is installed by default. I got the answer

git --version
> git version 1.7.5.4

我想将 git 升级到最新版本 1.7.8.3,所以我下载了 dmg 安装程序git-1.7.8.3-intel-universal-snow-leopard.dmg"并启动了它.

I would like to upgrade git to the latest version 1.7.8.3, so I downloaded the dmg installer "git-1.7.8.3-intel-universal-snow-leopard.dmg" and I launched it.

安装后终端还是提示版本是1.7.5.4.我做错了什么?

After the install, the Terminal still says that the version is 1.7.5.4. What am I doing wrong?

推荐答案

如果你已经有 Homebrew 就很简单:假设您安装了自制软件,请输入以下内容:

It's simple if you already have Homebrew: Assuming you have homebrew installed, type the following:

brew install git

这应该会自动安装 git 并将其设置在您的路径中,替换 Apple 的.

This should automatically install git and set it in your path, replacing the Apple one.

现在退出并重新启动您的终端.

Now quit and restart your terminal.

然后检查git版本以确认.

Then check git version to confirm.

git --version

如果上述命令的输出显示最新版本,并且没有提及 Apple 的版本详细信息,那么您就大功告成了.

If the output of the above command shows the latest version and does not mention Apple with the version details, then you are all set.

如果你仍然看到苹果版本,那么输入以下两行,这将手动设置我们的本地git发行版而不是苹果版的路径.

If however you still see apple version, then type the following two lines, which will manually set our path to the local git distro instead of the Apple one.

export PATH=/usr/local/bin:$PATH
git --version

如果您没有自酿啤酒,请按照以下步骤操作

检查版本

$ git --version

备份(或删除)Apple git(可选)

Backup (or remove) Apple git (Optional)

$ sudo mv/usr/bin/git/usr/bin/git-apple

如果你没有安装 Homebrew

Install Homebrew if you didn’t have

$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

或者如果你已经有了更新

Or update if you already have

$ brew update &&酿造升级

使用 Homebrew 安装 Git

Install Git with Homebrew

$ brew install git

符号链接

$ brew link --force git

退出终端并打开一个新终端,然后检查版本.

Quit terminal and open a new terminal, then check version.

$ git --version

你应该看到...

git 版本 <最新版本>

不错!我们现在安全了!下次你可以……

Nice! We’re safe now! And next time you can just…

$ brew update &&酿造升级

这篇关于如何在 macOS 上将 Git 升级到最新版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆