如何在 OSX 10.8 上更新我的 git 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15057424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update my version of git on OSX 10.8
提问by emersonthis
I'm on OSX 10.8.2 and I'm running git git v1.7.4.4
我在 OSX 10.8.2 上运行 git git v1.7.4.4
I just installed git on a remote server and it's version 1.11.x. I'm I would like to be running the same version of the software but I cannot figure out how to update git on my laptop.
我刚刚在远程服务器上安装了 git,它的版本是 1.11.x。我想运行相同版本的软件,但我不知道如何在我的笔记本电脑上更新 git。
I attempted to follow the steps listed here, which instruct to download the git-OSX-installer, run the install (which ran smoothly) and then do:
我尝试按照此处列出的步骤操作,该步骤指示下载git-OSX-installer,运行安装(运行顺利),然后执行以下操作:
$ sudo mkdir -p /usr/local/bin
$ sudo ln -s /usr/local/git/bin/git /usr/local/bin/git
But after this I do git --version
and it's still 1.7.4.4. Did I just reinstall the same version? Or did I install a newer version somewhere else?
但在这之后我做了git --version
,它仍然是 1.7.4.4。我刚刚重新安装了相同的版本吗?还是我在其他地方安装了较新的版本?
I've been reading similar questions and I think the issue is that OSX ships with an old version of git installed in a different location then where the git-osx-installer or mac ports will put it. But I'm not sure how to correct this. Thanks in advance for your advice.
我一直在阅读类似的问题,我认为问题在于 OSX 附带的旧版本 git 安装在不同的位置,然后 git-osx-installer 或 mac 端口将放置它。但我不确定如何纠正这一点。预先感谢您的建议。
Update:
更新:
which git
returns:
/usr/bin/git
which git
返回:/usr/bin/git
echo $PATH
returns:
/opt/local/bin:/opt/local/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
echo $PATH
返回:/opt/local/bin:/opt/local/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3- p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin: /usr/local/bin:/usr/local/git/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin
Update2:
更新2:
ESL ~/Downloads$ export PATH=/usr/local/bin:$PATH
ESL ~/Downloads$ which git
/usr/local/bin/git
ESL ~/Downloads$
ESL ~/Downloads$ git --version
git version 1.8.1.3
It appears I installed the newer git version in local. So should I add the export PATH=/usr/local/bin:$PATH
to my .bash_profile? Is it a problem that both versions of git are installed?
看来我在本地安装了较新的 git 版本。那么我应该将它添加export PATH=/usr/local/bin:$PATH
到我的 .bash_profile 中吗?两个版本的git都安装了是不是有问题?
I added export PATH=/usr/local/bin:$PATH
to the bottom of my ~/.bash_profile and now the new version of git runs.
我添加export PATH=/usr/local/bin:$PATH
到我的 ~/.bash_profile 底部,现在新版本的 git 运行。
回答by Marco Massenzio
The best way to update any binary on a Mac OSX machine is to use the package(s) developed specifically for Mac (a .dmg or .pkg download).
在 Mac OSX 机器上更新任何二进制文件的最佳方法是使用专为 Mac 开发的软件包(.dmg 或 .pkg 下载)。
In the case of git this is at: http://git-scm.com/download/mac(clicking on this link should automatically start the download of the latest version of git for Mac).
在 git 的情况下,这是在:http: //git-scm.com/download/mac(单击此链接应该会自动开始下载最新版本的 git for Mac)。
However, in this case (at least for my 10.8.3 MacBook) this was not quite the whole story: the package installs git in /usr/local/git
and then adds that path at the end of $PATH
- which defeats the whole purpose IMO.
但是,在这种情况下(至少对于我的 10.8.3 MacBook),这还不是全部:该包安装了 git /usr/local/git
,然后在末尾添加了该路径$PATH
- 这违背了 IMO 的全部目的。
I have manually modified my .bashrc
so as to have something similar to what suggested above:
我已经手动修改了我的.bashrc
,以便有类似于上面建议的内容:
export PATH=/usr/local/git/bin:$PATH
Once you do that, you should see the correct version of git being picked:
一旦你这样做了,你应该看到正确版本的 git 被选择:
$ git --version
git version 1.8.2.2
Note that this won't work for any app that is launched interactively (eg, via the docking bar) - you'll have to run the additional script provided in the downloaded package; see the README
for instructions.
请注意,这不适用于任何以交互方式启动的应用程序(例如,通过停靠栏) - 您必须运行下载的软件包中提供的附加脚本;请参阅README
有关说明。
回答by Ali-Akber Saifee
Since /usr/bin shows up before /usr/local/bin in your path, the git executable in /usr/bin will be given precedence. try this in your shell:
由于 /usr/bin 在您的路径中出现在 /usr/local/bin 之前,因此 /usr/bin 中的 git 可执行文件将被优先考虑。在你的 shell 中试试这个:
export PATH=/usr/local/bin:$PATH
which git
On a side note, I'd strongly recommend using homebrewfor managing installations such as this on macos
附带说明一下,我强烈建议使用自制软件来管理 macos 上的此类安装
回答by Ehryk
I had a similar issue in Cygwin (linux environment compiled for windows). I would do
我在 Cygwin(为 Windows 编译的 linux 环境)中遇到了类似的问题。我会做
which git
and it would respond with the correct location of the updated git compiled from source, but wouldn't actually use it until I did
它会以从源代码编译的更新 git 的正确位置进行响应,但在我这样做之前不会实际使用它
hash -r git
I don't claim to understand what this did or why it had to be done, but after that git --version
replied with '1.8.2.rc0.22.gb3600c3' which was clearly no longer the old git shipped with Cygwin. This may not apply to OSX, but give it a shot if which git
is locating the updated binary.
我不知道这做了什么或为什么必须这样做,但在那之后git --version
回复了“1.8.2.rc0.22.gb3600c3”,这显然不再是 Cygwin 附带的旧 git。这可能不适用于 OSX,但如果which git
正在查找更新的二进制文件,请试一试。