macos - Mac OS X Lion 下 Git 如何升级?
高洛峰
高洛峰 2017-04-21 10:57:29
0
8
927

Mac OS X Lion 下使用which git查看 git 发现位于/usr/bin/git目录下,可能是安装 Xcode 时一起装上来的,版本是 1.7.5.4。

想升级到新版本,下载 git-osx-installer 安装完成后,在命令行里查看却仍是旧版本,查阅资料发现这个安装包是将 git 装在/usr/local/git目录下。

我想使用这个新版本的 git,请问该如何设置呢,或者有别的方法?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(8)
左手右手慢动作
cd /usr/bin
mv git git_legacy_1.7.5.4
ln -s /usr/local/git ./
巴扎黑

Actually, there are two questions.
One is how to install a higher version of git?
You can use git-osx-installer or brew.
It is recommended to install with brew:
brew install git

Another one is how to make the newly installed git overwrite the old git?
It is recommended to modify ~/.bash_profile and add the following content:
export PATH=/usr/local/bin:/usr/local/sbin:${PATH}
This allows bash to search for instructions under /usr/local first, and will not overwrite old files, which is safer.

Peter_Zhu

I also updated my git. It is very convenient to update with homebrew.
If you have homebrew installed:

brew install git

My approach is:
After update

sudo cd /usr/bin
sudo mkdir old-git-1.7.5.4
sudo mv git* old-git-1.7.5.4

The advantage is that other components of git are also up to date. And the old git will not appear during git completion

阿神

I also used git installed with brew. When I first used OSX Lion, I always used git installed with brew. Later, after reinstalling OSX Mountain Lion, I found that the default git is the one that comes with the system and the version is relatively old. I I am another patient with obsessive-compulsive disorder about upgrading. I have also considered changing the path like @Hoho. However, due to some reasons that I am not sure about (some problems I encountered when I first started using Mac), I am worried that putting /usr/local/bin may be in front. It will affect some things that I don't pay attention to. Later, I simply put it in .zshrc (I use zsh)

alias git="/usr/local/bin/git"

Everything is currently running normally and does not affect anything else. No side effects

伊谢尔伦

I used this method http://apple.stackexchange.com/a/3913...

Changed.bash_profile这个文件.然后让/usr/local/bin这个文件夹出现在/usr/bin之前.
虽然我是从git的官方网站上下载的安装dmg文件. 但是却不能安装. 需要改路径才行.
我也知道可以用brew的方式安装. 但是个人感觉那个有些时候不是最新的发行版本. 而且老是从SourceForgeWhen downloading from third-party websites, the speed is not very fast. (Maybe it’s because of GFW)

It seems that this thing is caused by Apple’s own Xcode.
http://apple.stackexchange.com/q/2012...

巴扎黑

I installed xocde first, so it comes with a git version of 1.8.5.

Then I want to install a new version of git instead of 1.8.5. What I do is:
Install brew first, -> brew install git -> brew doctor

Note that brew doctor will automatically detect some settings and prompt you to modify them, such as making the brew download command at the front of PATH.
In this way, it can be replaced with a new version in git and can be updated through brew.

阿神

brew install git
...
➜ meetup git:(master) git --version
git version 1.9.3 (Apple Git-50) //旧版本
➜ meetup git:(master) which git
/usr/bin/git
➜ meetup git:(master) sudo mv /usr/bin/git /usr/bin/git-1.9.3
Password:
➜ meetup git:(master) which git
/usr/local/bin/git
➜ meetup git:(master) git --version
git version 2.2.1
// 搞定

PHPzhong

1 It is recommended to use homebrew to install components under mac system.
2 Install homebrew terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
3 Upgrade homebrew to the latest version

brew update

4 Use the latest version of homebrew to check which software needs to be updated. (Take git as an example)

brew outdated  ##列出过时的软件包

5 If git needs to be updated:

 brew upgrade git  ##若是有跟新洁癖,那就把后面的git 去掉 使用 brew upgrade进行所有包的跟新。
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template