208

Trying to update Homebrew with brew update I got the following error

error: The following untracked working tree files would be overwrittenby merge:     
 Library/Formula/argp-standalone.rb
 Library/Formula/cocot.rb 
Please move or remove them before you can merge. 
Aborting 
Updating e088818..5909e2c 
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master

I found a blog post by someone who experienced a similar problem after having installed Mountain Lion (which I did this week too). He explains how he removed the files referred to in the error message

I removed these files:
$ cd $(brew --prefix)
$ rm cocot.rb
However, removing these files didn't help with the brew update. Instead I had to manually update brew through git:
$ cd $(brew --prefix)
$ git fetch origin
$ git reset --hard origin/master
$ brew update
Already up-to-date.

Assuming those instructions are correct (which I maybe shouldn't assume), I tried to follow these instructions and do

    $ cd $(brew --prefix)
    $ rm cocot.rb

However, it said 'file doesn't exist' when I tried to rm cocot.rb

One thing I'm not sure about is the cd $(brew --prefix) Are those the exact words I type or do I have to replace prefix with something? the cd was successful, so I'm assuming it was correct -- it moved me into /usr/local, but there was no file to remove. Contents of /usr/local are

Cellar              clamXav             git             mysql               var Library             doc             heroku              mysql-5.5.15-osx10.6-x86_64 README.md           etc             include             rvm bin             foreman             lib             share

At any rate, do you know how I can fix the 'brew update'

Update: After removing the files according to favoretti's instructions and trying chown -R <your_username> $(brew --prefix)/.git, I got the following error running brew update

error: The following untracked working tree files would be overwritten by merge:
    Library/Aliases/gperftools
    Library/Aliases/hashdeep
    Library/Aliases/htop
    Library/Aliases/nodejs
    Library/Aliases/ocio
    Library/Aliases/oiio
    Library/Aliases/pgrep
    Library/Aliases/pkill
    Library/Aliases/qt4
    Library/Aliases/twolame
    Library/Aliases/wxwidgets
    Library/Contributions/cmds/brew-aspell-dictionaries
    Library/Contributions/cmds/brew-beer.rb
    Library/Contributions/cmds/brew-dirty.rb
    Library/Contributions/cmds/brew-graph
    Library/Contributions/cmds/brew-grep
    Library/Contributions/cmds/brew-leaves.rb
    Library/Contributions/cmds/brew-linkapps.rb
    Library/Contributions/cmds/brew-ls-taps.rb
    Library/Contributions/cmds/brew-man
    Library/Contributions/cmds/brew-md5-to-sha1
    Library/Contributions/cmds/brew-mirror-check.rb
    Library/Contributions/cmds/brew-pull.rb
    Library/Contributions/cmds/brew-readall.rb
    Library/Contributions/cmds/brew-server
    Library/Contributions/cmds/brew-services.rb
    Library/Contributions/cmds/brew-switch.rb
    Library/Contributions/cmds/brew-test-bot.rb
    Library/Contributions/cmds/brew-tests.rb
    Library/Contributions/cmds/brew-unpack.rb
    Library/Contributions/cmds/brew-which.rb
    Library/Contributions/cmds/git
    Library/Contributions/cmds/svn
    Library/ENV/4.3/apr-1-config
    Library/ENV/4.3/bsdmake
    Library/ENV/4.3/c++
    Library/ENV/4.3/c89
    Library/ENV/4.3/c99
    Library/ENV/4.3/cc
    Library/ENV/4.3/clang
    Library/ENV/4.3/clang++
    Library/ENV/4.3/cpp
    Library/ENV/4.3/g++
    Library/ENV/4.3/gcc
    Library/ENV/4.3/git
    Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
    Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
    Library/ENV/4.3/ld
    Library/ENV/4.3/llvm-g++
    Library/ENV/4.3/llvm-g++-4.2
    Library/ENV/4.3/llvm-gcc
    Library/ENV/4.3/llvm-gcc-4.2
    Library/ENV/4.3/make
    Library/ENV/4.3/mig
    Library/ENV/4.3/sed
    Library/ENV/4.3/svn
    Library/ENV/4.3/xcrun
    Library/ENV/libsuperenv.rb
    Library/ENV/pkgconfig/leopard/libcrypto.pc
    Library/ENV/pkgconfig/leopard/libcurl.pc
    Library/ENV/pkgconfig/mountain_lion/libcurl.pc
    Library/ENV/pkgconfig/mountain_lion/libexslt.pc
    Library/ENV/pkgconfig/mountain_lion/libxml-2.0.pc
    Library/ENV/pkgconfig/mountain_lion/libxslt.pc
    Library/Formula/abcl.rb
    Library/Formula/abcmidi.rb
    Library/Formula/aiccu.rb
    Library/Formula/akka.rb
    Library/Formula/alac.rb
    Library/Formula/alure.rb
    Library/Formula/appledoc.rb
    Library/Formula/arangodb.rb
    Library/Formula/argp-standalone.rb
    Library/Formula/argtable.rb
    Library/Formula/autopano-sift-c.rb
    Library/Formula/avian.rb
    Library/Formula/avidemux.rb
    Library/Formula/avro-cpp.rb
    Library/Formula/aws-cloudsearch.rb
    Library/Formula/aws-sns-cli.rb
    Library/Formula/backupninja.rb
    Library/Formula/bact.rb
    Library/Formula/bam.rb
    Library/Formula/basex.rb
    Library/Formula/berkeley-db4.rb
    Library/Formula/bind.rb
    Library/Formula/blazeblogger.rb
    Library/Formula/bochs.rb
    Library/Formula/boost149.rb
    Library/Formula/bsdconv.rb
    Library/Formula/bsdmake.rb
    Library/Formula/buildapp.rb
    Library/Formula/bup.rb
    Library/Formula/byacc.rb
    Library/Formula/cadubi.rb
    Library/Formula/camellia.rb
    Library/Formula/casperjs.rb
    Library/Formula/ccextractor.rb
    Library/Formula/cconv.rb
    Library/Formula/cdo.rb
    Library/Formula/cdpr.rb
    Library/Formula/cgvg.rb
    Library/Formula/checkstyle.rb
    Library/Formula/chordii.rb
    Library/Formula/chruby.rb
    Library/Formula/cifer.rb
    Library/Formula/clhep.rb
    Library/Formula/cntlm.rb
    Library/Formula/cocot.rb
    Library/Formula/cogl.rb
    Library/Formula/collada-dom.rb
    Library/Formula/crash.rb
    Library/Formula/crossroads.rb
    Library/Formula/crosstool-ng.rb
    Library/Formula/css-crush.rb
    Library/Formula/csync.rb
    Library/Formula/ctemplate.rb
    Library/Formula/curlftpfs.rb
    Library/Formula/cutter.rb
    Library/Formula/cvsutils.rb
    Library/Formula/darkstat.rb
    Library/Formula/darner.rb
    Library/Formula/dart.rb
    Library/Formula/dasm.rb
    Library/Formula/debianutils.rb
    Library/Formula/dfc.rb
    Library/Formula/dgtal.rb
    Library/Formula/dhcping.rb
    Library/Formula/di.rb
    Library/Formula/dmtx-utils.rb
    Library/Formula/drip.rb
    Library/Formula/dsniff.rb
    Library/Fo
Aborting
Updating e088818..c1fbc29
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master
4

12 回答 12

360

您需要执行以下操作:

cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb

然后做

git fetch origin
git reset --hard origin/master
brew update

基本上,解释一下:

cd $(brew --prefix)

告诉cd将目录更改为brew --prefix将输出的任何内容。如果您尝试执行brew --prefix命令,您应该会看到以下内容:

brew --prefix
/usr/local

因此,在这种情况下,该命令相当于cd /usr/local. 较新brew的版本在其安装前缀和 下具有公式Library/Formula/,因此您需要在其中查找那些过时/更改的文件。

请注意,如果您出于特定原因(例如固定版本)自己更改了这些公式,则此操作会将它们恢复为默认值,并且可能会产生不良影响。

@TedPennings 在评论中指出这对他有用,但他的顺序是:

  1. chown 一切my_username:admin,即,sudo chown -R ted:admin $(brew --prefix)
  2. 运行上面的两个 git 命令,git fetch origin然后git reset --hard origin/master
于 2013-01-01T19:23:17.753 回答
280
cd $(brew --prefix)
git reset --hard HEAD
brew update
于 2013-03-13T20:08:40.970 回答
46

这是由update很久以前修复的代码中的旧错误引起的。但是,该错误的性质要求您执行以下操作:

cd $(brew --repository)
git reset --hard FETCH_HEAD

如果brew doctor仍然抱怨未提交的修改,请运行以下命令:

cd $(brew --repository)    
git clean -fd
于 2014-01-14T03:55:43.937 回答
31
$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update

注意:第 2 步和第 3 步对我有用,因为我在收到错误之前在第 4 步之前执行了第 5 步。更改文件夹所有者之前的brew 更新导致了整个问题。

于 2014-05-17T17:01:28.417 回答
6

我有一个类似的问题,我的 brew 包库以 root 用户身份下载,然后我无法运行 brew update 因为 git 会抱怨无法合并文件。

解决方案是: -

sudo chown -R <user> /usr/local/Library
于 2013-05-24T02:42:52.287 回答
5

如果您不介意放弃对您可能已应用的公式的潜在修改,则重置 brew 存储库应该是最有效的方法:

$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update
于 2013-12-22T02:28:43.080 回答
4

通过在这些路径中添加管理员组写入(和 setgid 位)权限,我能够在我的机器上解决此问题:

sudo chmod -R g+ws /usr/local /Library/Caches/Homebrew

s 在执行时设置组 ID,以便下次不同的管理员用户更新或升级 Homebrew 时不会丢失写权限。

这个答案有些不完整,因为当我尝试这样做brew cleanup --force时,Homebrew 尝试删除 /usr/local/Cellar/ 中的内容时会出现权限问题。(不幸的是,我目前无法进一步调查。)

于 2013-12-20T18:33:49.197 回答
1

另一种选择是只使用git stash.

brew update 命令执行 a git pull,所以如果有任何更改的文件(甚至是文件属性,当我递归更改目录中的权限时发生在我身上)你必须以某种方式解决冲突。使用git stash是一种方式;它需要任何更改并将它们放在一边,以便您有效地恢复到上次更新的 repo 版本。Homebrew 的“位置”是默认的/usr/local,它作为 git 存储库安装。你可以.git自己找一个文件夹看看。我正在编写一个自制卸载脚本,很快就会在我的 GitHub 个人资料上发布更多信息。

于 2014-02-24T01:51:27.257 回答
1
sudo chown -R USER /usr/local/bin

注意 - 供用户使用命令,即您的用户名

sudo brew doctor
于 2015-11-10T08:23:28.460 回答
1

这种方法可能比某些方法更简单。它涉及:

  • 修复 git 问题,以便您可以再次将更改的管理委派给它。
  • 无需手动移动文件或目录。
  • 无需手动调整文件或目录权限。

步骤(为需要解释的人提供注释):

cd $(brew --repository)                              // see Note 1 below
git remote add brew https://github.com/Homebrew/brew // see Note 2 below
git pull brew master                                 // promising fast-forward report!
brew update                                          // see Note 3 below 

概述:
据我所知,这个问题的实际原因是 repo url 发生了变化。现在brew和过去brew.git。(完整的最新网址:https ://github.com/Homebrew/brew )

注意 1:第一个命令将您从文件结构中的任何位置带到正确的目录。对我来说,目录结构与上面显示的其他人(Mac OS 10.11.16)不同,但是使用此命令,这些差异应该无关紧要。

注意 2:第二个命令将正确的远程 url 添加到新别名;我这样做是为了以防这种方法没有完成我想要的并且我再次需要以前的地址。由于新的遥控器工作正常,我会邀请其他人评论简单地更改以来源为别名的 url。我很乐意更新答案以反映对您有用的方法。

注意 3:这第四条命令完全符合预期的结果:它报告了大量更新,包括“==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!”的特别好的报告。(强调他们的)。

于 2016-11-15T00:00:14.993 回答
0

这篇文章在更新到 El Capitan 后帮助了我。在我的情况下,chown没有工作(“zsh:找不到命令:chown”),所以第 1 步是将这一行添加到我的 .zshrc 中:

export PATH="$PATH:/usr/sbin"

我已经尝试了上面几个更受欢迎的答案,所以我很确定git status当我粘贴博客文章中的关键命令时,这些答案已经很清楚了:

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

于 2015-10-31T20:08:35.533 回答
0

这应该有效。

1. cd `brew --prefix`
2. git fetch origin
3. git reset --hard origin/master
4. sudo brew update
于 2016-10-31T06:54:09.580 回答