macos 尝试更新 brew 包管理器时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6933959/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:15:56  来源:igfitidea点击:

Error while trying to update brew package manager

macoshomebrewpackage-managers

提问by Chiron

I tried to update brew:

我尝试更新 brew:

sudo brew update

But I got this error:

但我收到了这个错误:

error: Your local changes to the following files would be overwritten by merge:

Listing a lot of files

Error: Failed while executing git pull http://github.com/mxcl/homebrew.gitmaster

错误:您对以下文件的本地更改将被合并覆盖:

列出很多文件

错误:执行 git pull 时失败http://github.com/mxcl/homebrew.gitmaster

Any idea what is going wrong?

知道出了什么问题吗?

回答by Turadg

There was a bug in Homebrewthat was fixed just a few days ago. To fix the bug you can run git reset --hard FETCH_HEADinside your Homebrew installation. Since that won't fix files that are already seen as modified you can also run git checkout Libraryto replace your checkout with the latest files. (That wipes all edits so take appropriate measures with any you made.)

Homebrew有一个错误,几天前才修复。要修复该错误,您可以git reset --hard FETCH_HEAD在 Homebrew 安装中运行。由于这不会修复已被视为已修改的文件,因此您还可以运行git checkout Library以使用最新文件替换您的结帐。(这会擦除所有编辑,因此对您所做的任何编辑都采取适当的措施。)

回答by JGallardo

The accepted answer is correct but incomplete. If you are getting the error of

接受的答案是正确但不完整的。如果您收到以下错误

error: The following untracked working tree files would be overwritten by merge:

错误:以下未跟踪的工作树文件将被合并覆盖:

Then go to your terminal and run these commands

然后转到您的终端并运行这些命令

cd /usr/local

Then

然后

git reset --hard FETCH_HEAD

Then

然后

git checkout Library

That should get everything in order. Then run

这应该让一切井然有序。然后运行

brew update

回答by pixel 67

Let me add: cd /usr/local/gitand then run git reset --hard FETCH_HEAD

让我添加:cd /usr/local/git然后运行git reset --hard FETCH_HEAD

回答by hguzman

go to your terminal and run these commands

转到您的终端并运行这些命令

cd /usr/local

sudo git reset --hard FETCH_HEAD

sudo git checkout Library

回答by Joseph Hansen

For those of you using OS X El Capitan, your problem may be System Integrity Protection.

对于那些使用 OS X El Capitan 的人,您的问题可能是系统完整性保护。

If /usr/localexists already, run the following in Terminal:

如果/usr/local已经存在,请在终端中运行以下命令:

sudo chown -R $(whoami):admin /usr/local

If /usr/localdoes not exist:

如果/usr/local不存在:

First, try to create /usr/localthe normal way:

首先,尝试以/usr/local正常方式创建:

sudo mkdir /usr/local && sudo chflags norestricted /usr/local && sudo chown -R $(whoami):admin /usr/local

If you see permission issues instead try:

如果您看到权限问题,请尝试:

  1. Reboot into Recovery mode (Hold Cmd+R on boot) & access the Terminal.
  2. In that terminal run: csrutil disable
  3. Reboot back into OS X
  4. Open your Terminal application and execute the line from just above
  5. Reboot back into Recovery Mode & access the Terminal again.
  6. In that terminal execute: csrutil enable
  7. Reboot back into OS X & you'll be able to write to /usr/local & install Homebrew.
  1. 重新启动进入恢复模式(启动时按住 Cmd+R)并访问终端。
  2. 在那个终端运行: csrutil disable
  3. 重新启动回到 OS X
  4. 打开您的终端应用程序并从正上方执行该行
  5. 重新启动到恢复模式并再次访问终端。
  6. 在那个终端执行: csrutil enable
  7. 重新启动到 OS X,您将能够写入 /usr/local 并安装 Homebrew。

回答by Achim Sperling

Out of no reason (or at least no one I'd understand) the repository in /usr/local(which is the brew install!) lost its remote repository. So, neither a git resetnor a git pulland for sure no brew updatewould work.

无缘无故(或者至少没有人理解)/usr/local(这是 brew install!)中的存储库丢失了它的远程存储库。所以,agit reset和 a都没有git pull,肯定没有brew update

How do you know that happened? Check /usr/local/.git/configwhether there are some lines like the following:

你怎么知道那件事发生了?检查/usr/local/.git/config是否有如下几行:

[remote "origin"]
url = http://github.com/mxcl/homebrew.git
fetch = +refs/heads/*:refs/remotes/origin/*

If not do as follows:

如果没有,请执行以下操作:

cd /usr/local
git remote add origin http://github.com/mxcl/homebrew.git
git pull origin master