brew update failure while executing git checkout

喜夏-厌秋 提交于 2019-12-20 08:14:07

问题


After an interrupted brew update because of a network issue, Homebrew appears to be broken:

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

Looking at the /usr/local Git repository, there's no remote repository.

$ cd `brew --prefix`
$ git remote -v
$

回答1:


Fixed with the following commands:

$ 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.



回答2:


when i try it, sudo is needed:

$ 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



回答3:


In my case, I had just upgraded to OS X El Capitan and none of the other solutions worked.

I took note of the packages in /usr/local/Cellar and then deleted the Cellar folder and started with a fresh install.

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

Then I brew installed the packages again.




回答4:


I had a similar problem where from /usr/local (== $(brew --prefix)) I tried the answer by @ Julien Carsique but still got the error:

[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.

This was because I the hdf5 routine was in /usr/local/Library/tab/homebrew-science which has it's own git repository. To fix this I entered:

[local]master$ cd Library/Taps/homebrew/homebrew-science/
[homebrew-science]master$ git checkout 3115d85 hdf5.rb

Now I can install a previous version of the desired library (e.g. hdf5)

Hope this helps someone!




回答5:


What solved Homebrew git errors for me was simply to cd ~ and run brew update in my home directory. The command failed when I was in a folder shared on GitHub. Also, clang magically appeared again from brew config after cd ~.



来源:https://stackoverflow.com/questions/9370552/brew-update-failure-while-executing-git-checkout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!