更新brew时执行git checkout失败

39

由于网络问题,brew update 被中断后,Homebrew 似乎出现了故障:

$ brew update
error: pathspec 'master' did not match any file(s) known to git.
Error: Failure while executing: git checkout -q master 

查看 /usr/local Git 仓库,发现没有远程仓库。

$ cd `brew --prefix`
$ git remote -v
$
5个回答

101

使用以下命令进行修复:

$ cd `brew --prefix`
$ git remote add origin https://github.com/Homebrew/homebrew.git
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.

3
我收到了来自GitHub的403错误,使用HTTPS URL访问仓库。这个方法适合我:$ git remote add origin git://github.com/mxcl/homebrew.git - jongala
2
“brew update” 第一次永远不起作用。工作树总是有问题。 - Rob
我目前遇到了以下问题,可能是由于Github的DDOS攻击引起的:/usr/local at owne-pc (master ✔)% brew update error: Failed connect to github.com:443; Operation timed out while accessing https://github.com/mxcl/homebrew.git/info/refs fatal: HTTP request failed Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master - Sarah Vessels
由于某种原因,我的一些文件被root拥有。可能在某个时候使用了sudo。我将这些文件的所有权更改为我的普通用户,并按照以下说明操作,效果很好。 - Tim G
在运行了 git reset --hard origin/master 之后,我不得不运行 git clean -f - Michael Stalker

3

当我尝试这个时,需要使用sudo:

$ git reset --hard origin/master
error: unable to unlink old 'Library/Homebrew/macos/xcode.rb' (Permission denied)
fatal: Could not reset index file to revision 'origin/master'.
$ sudo !!
sudo git reset --hard origin/master
Password:
HEAD is now at 97302bf xrootd 3.2.2

你应该检查你的权限。Homebrew被设计为不需要 sudo即可工作。https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md#why-does-homebrew-say-sudo-is-bad- - Rafael Barbosa

2

在我的情况下,我刚升级到了OS X El Capitan系统,但其他解决方案都没有起作用。

我注意到了/usr/local/Cellar中的软件包,然后删除了Cellar文件夹并进行了全新安装。

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

然后我再次使用 brew 安装了这些包。


1
我曾遇到一个类似的问题,在 /usr/local(等同于 $(brew --prefix))路径下尝试了@Julien Carsique提供的答案,但仍然遇到错误。
[local]master$ git checkout 3115d85 hdf5.rb
error: pathspec '3115d85' did not match any file(s) known to git.
error: pathspec 'hdf5.rb' did not match any file(s) known to git.

这是因为hdf5例程位于/usr/local/Library/tab/homebrew-science中,该目录有自己的git存储库。要解决此问题,我输入了以下内容:
[local]master$ cd Library/Taps/homebrew/homebrew-science/
[homebrew-science]master$ git checkout 3115d85 hdf5.rb

现在我可以安装所需库的以前版本(例如hdf5)

希望这对某人有所帮助!


0
解决Homebrew git错误的方法很简单,只需在我的主目录下运行cd ~brew update。当我在一个在GitHub上共享的文件夹中时,该命令失败了。此外,在运行cd ~后,clang神奇地再次出现在brew config中。

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