Brew更新失败:未跟踪的工作树文件将被合并覆盖

试图更新自酿brew update我得到了以下错误

 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 

我find了一个安装了Mountain Lion之后遇到类似问题的博客文章(我也是这周做的)。 他解释了他如何删除错误信息中提到的文件

 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. 

假设这些说明是正确的(我可能不应该假设),我试图按照这些说明做

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

但是,当我试图使用cocot.rb时,它说'文件不存在'

我不知道的一件事是cd $(brew --prefix)这些是我input的确切单词,还是我必须用某些东西replace前缀? 光盘是成功的,所以我假设它是正确的 – 它把我移到/ usr / local,但没有文件删除。 / usr / local的内容是

 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 

无论如何,你知道我怎样才能解决“酿造更新”

更新:根据favoretti的指示删除文件并尝试chown -R <your_username> $(brew --prefix)/.git ,我得到以下错误运行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 
 cd $(brew --prefix) git reset --hard HEAD brew update 

您需要执行以下操作:

 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 origingit reset --hard origin/master

这是由于update代码中一个早已被修复的旧bug造成的。 但是,该错误的性质要求您执行以下操作:

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

如果brew doctor仍然抱怨未提交的修改,也运行这个命令:

 cd $(brew --repository) git clean -fd 
 $ cd $(brew --prefix) $ git clean -fd $ git reset --hard $ sudo chown -R `whoami` `brew --prefix` $ brew update 

注意:步骤2和步骤3是为我工作的,因为在我得到错误之前,我在4之前做了5步。 在更改文件夹的所有者之前冲泡更新引起了整个问题。

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

解决办法是:

 sudo chown -R <user> /usr/local/Library 

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

 $ cd `brew --prefix` $ git fetch origin $ git reset --hard origin/master $ brew cleanup --force $ brew update 

我可以通过在这些path添加pipe理员组写(和setgid位)权限来解决这个问题。

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

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

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

另一个select是只使用git stash

brew update命令执行git pull ,所以如果有任何更改的文件(甚至是文件属性,当我更改目录中的权限时发生在我身上),则必须以某种方式修复冲突。 使用git stash是一种方法; 它会进行任何更改并将其放在一边,以便有效地还原到上次更新的回购版本。 Homebrew的“位置”默认是/usr/local ,它会作为一个git仓库安装。 你可以找一个.git文件夹来自己看看。 我正在写一个自制软件的卸载脚本,很快就会在我的GitHub上发布更多信息。

 sudo chown -R USER /usr/local/bin 

注意 – 对于USER使用命令,即你的用户名

 sudo brew doctor 

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

  • 修复一个git问题,所以你可以再次委派pipe理更改。
  • 没有手动移动文件或目录。
  • 没有手动调整文件或目录权限。

步骤(对于那些想要解释的人来说):

 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 

概述:
从我可以告诉,这个问题的实际原因是回购url的变化。 这是现在brew ,并brew.git 。 (完整的最新的url: https : //github.com/Homebrew/brew )

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

注2:这第二个命令将正确的远程URL添加到一个新的别名; 我这样做,以防万一这种方法没有达到我想要的,我又需要以前的地址。 由于新的远程工作,我会邀请其他人发表评论,只是简单地改变原来的别名。 我会愉快地更新答案,以反映什么对你有用。

注意3:这个命令的结果是正确的:它报告了大量的更新,包括“==>迁移HOMEBREW_REPOSITORY到/ usr / local / Homebrew!”的特别好的报告。 (强调他们)。

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

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

我已经尝试了上面几个比较stream行的答案,所以我非常确定,当我粘贴博客文章中的重要命令时, git status已经变得清晰了:

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

这应该工作。

 1. cd `brew --prefix` 2. git fetch origin 3. git reset --hard origin/master 4. sudo brew update 

去sudo总是为我工作:

sudo酿造升级