使用brew升级git出现问题:提示“没有这样的文件或目录 - /usr/local/Cellar/git”。

3
我正在尝试升级git版本。在升级过程中,我遇到了一些路径问题,这似乎是与升级git和Xcode预装的git版本有关的常见问题。我对git和编程都比较陌生,请您谅解。
我的操作系统是OSX 10.9.5,安装了Xcode 6.1.1。
我按照这里的说明进行操作:博客文章
当我运行brew doctor时,会收到许多警告:

Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry and just ignore them. Thanks!

Warning: Python is installed at /Library/Frameworks/Python.framework

Homebrew only supports building against the System-provided Python or a brewed Python. In particular, Pythons installed to /Library can interfere with other software installs.

Warning: Unbrewed dylibs were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected dylibs: /usr/local/lib/libtcl8.6.dylib /usr/local/lib/libtk8.6.dylib

Warning: Unbrewed header files were found in /usr/local/include. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected header files: /usr/local/include/fakemysql.h /usr/local/include/fakepq.h /usr/local/include/fakesql.h /usr/local/include/itcl.h /usr/local/include/itcl2TclOO.h /usr/local/include/itclDecls.h /usr/local/include/itclInt.h /usr/local/include/itclIntDecls.h /usr/local/include/itclMigrate2TclCore.h /usr/local/include/itclTclIntStubsFcn.h /usr/local/include/mysqlStubs.h /usr/local/include/odbcStubs.h /usr/local/include/pqStubs.h /usr/local/include/tcl.h /usr/local/include/tclDecls.h /usr/local/include/tclOO.h /usr/local/include/tclOODecls.h /usr/local/include/tclPlatDecls.h /usr/local/include/tclThread.h /usr/local/include/tclTomMath.h /usr/local/include/tclTomMathDecls.h /usr/local/include/tdbc.h /usr/local/include/tdbcDecls.h /usr/local/include/tdbcInt.h /usr/local/include/tk.h /usr/local/include/tkDecls.h /usr/local/include/tkPlatDecls.h

Warning: Unbrewed .pc files were found in /usr/local/lib/pkgconfig. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected .pc files: /usr/local/lib/pkgconfig/tcl.pc /usr/local/lib/pkgconfig/tk.pc

Warning: Unbrewed static libraries were found in /usr/local/lib. If you didn't put them there on purpose they could cause problems when building Homebrew formulae, and may need to be deleted.

Unexpected static libraries: /usr/local/lib/libtclstub8.6.a /usr/local/lib/libtkstub8.6.a

Warning: /usr/bin occurs before /usr/local/bin This means that system-provided programs will be used instead of those provided by Homebrew. The following tools exist at both paths:

2to3
easy_install
easy_install-2.7
gcc-4.2

Consider setting your PATH so that /usr/local/bin occurs before /usr/bin. Here is a one-liner: echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

起初我忽略了这些错误,因为一开始的brew消息提示,但是当我运行brew upgrade git时,出现了以下内容:
Error: No such file or directory - /usr/local/Cellar/git

在谷歌搜索问题后,我发现有人通过编辑他们的bash.profile解决了类似的问题(错误相同但指定的路径不同),所以我运行了echo命令:

echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

我也尝试过:

echo export PATH='/usr/local/Cellar/git:$PATH' >> ~/.bash_profile

我尝试着手动将这些导出路径的命令添加到我的.bash_profile文件中,但似乎并没有帮助。

如果能得到任何帮助,我将不胜感激。

4个回答

5

我成功解决了这个问题,方法是先卸载两次 git,然后重新安装最新版本的 git。这样可以同时移除预装的 git 和我自己安装的版本,消除路径问题。我运行了以下命令:

which git

然后执行了 sudo rm -rf /absolute/path/to/git

删除了已安装的一个git程序。然后我再次运行了两个命令,但是第二次 which git 返回了不同的路径,我使用这个路径和第二个 sudo rm -rf /absolute/path/to/git。最终,我使用brew安装了git。

并不是很难,但似乎行得通。


rm: /usr/bin/git: 操作不允许 - H.Jacob
你没有包含sudo。 - TMin

2
我假设您已经安装了Git的某个版本?(输入git --versionwhich git进行检查。)如果没有安装,请执行brew install git,然后您就完成了。
不过,假设您已经安装了Git:
选项1:如果brew无法识别当前的git安装
总体来说,这是一个超级快速的修复方法……对我有效。
运行$ brew upgrade git 如果结果告诉您未安装,则brew无法识别当前安装……您最快的选择是让brew从头开始安装:
1. 重命名现有的Apple安装的git(例如此示例) 2. 通过brew install git让brew安装最新版本(例如此示例
步骤1,重命名Apple安装的git,只是避免Apple安装的Git和您通过Homebrew安装的新Git之间冲突的一种方式。有关此问题的第二个示例,请参见您链接到的博客上的另一篇文章: http://rayhightower.com/blog/2014/12/18/git-vulnerability-on-mac-os-x/ 选项2:让brew识别您已经安装的git
如果您认为上述方法太笨拙,会在您的计算机上留下旧的git安装程序……
另一种选择可能是玩弄链接?我对brew link的初始尝试没有成功。我没有尝试通过符号链接或定义任何$PATH来解决。肯定有比简单放弃现有安装更整洁的选项,但对我来说,选项1今天就足够了。

0

0

虽然我不是专家,但我基本上做了以下几步:

  1. 备份原始的git目录
  2. 使用Homebrew安装Git
  3. 重新启动(或source)shell

~ > which git
/usr/bin/git
~ > sudo mv /usr/bin/git /usr/bin/git-original
~ > which git
git not found
~ > brew install git
~ > source /etc/profile
~ > git --version
git version 2.4.3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接