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

Bra*_*cil 207 homebrew

试图更新Homebrew 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
Run Code Online (Sandbox Code Playgroud)

我在安装了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.
Run Code Online (Sandbox Code Playgroud)

假设这些指令是正确的(我可能不应该假设),我试着按照这些说明进行操作

    $ cd $(brew --prefix)
    $ rm cocot.rb
Run Code Online (Sandbox Code Playgroud)

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

我不确定的一件事cd $(brew --prefix)是那些我输入的确切单词还是我必须用某些东西替换前缀?CD是成功的,所以我假设它是正确的 - 它将我移动到/ 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
Run Code Online (Sandbox Code Playgroud)

无论如何,你知道如何修复'brew update'吗?

更新:根据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
Run Code Online (Sandbox Code Playgroud)

fav*_*tti 360

您需要执行以下操作:

cd $(brew --prefix)
rm Library/Formula/argp-standalone.rb
rm Library/Formula/cocot.rb
Run Code Online (Sandbox Code Playgroud)

然后做

git fetch origin
git reset --hard origin/master
brew update
Run Code Online (Sandbox Code Playgroud)

基本上,要解释一下:

cd $(brew --prefix)
Run Code Online (Sandbox Code Playgroud)

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

brew --prefix
/usr/local
Run Code Online (Sandbox Code Playgroud)

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

请注意,如果您因特定原因(例如固定版本)而自行更改了这些公式,则此操作会将其还原为默认值,并可能产生不需要的效果.

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

  1. chown everything my_username:admin,即sudo chown -R ted:admin $(brew --prefix)
  2. 运行上面的两个git命令,git fetch origingit reset --hard origin/master

  • 这个解决方案为我修复了一些东西,但是我不得不把所有东西都写到我的用户名:admin,即`sudo chown -R ted:admin $(brew --prefix)`然后运行上面的两个git命令,`git fetch origin `和`git reset --hard origin/master` (19认同)
  • 这意味着您的权限被搞砸了.一种方法是运行`sudo git reset --hard`,其他更好的方法是修复权限并执行`chown -R <your_username> $(brew --prefix)/ .git` (3认同)
  • @TedPennings:很酷!我会将您的命令添加到答案作为可能的附加步骤. (2认同)

Str*_*hen 279

cd $(brew --prefix)
git reset --hard HEAD
brew update
Run Code Online (Sandbox Code Playgroud)

  • 而不是`git reset --hard HEAD`(这对我不起作用),我做了`git fetch --all`和`git reset --hard origin/master` (82认同)
  • 你可能也想做``git add .``然后``git stash``:P (17认同)
  • 如果在用`cd $(brew --prefix)`更改到brew目录并使用`git reset --hard HEAD`重置git stage之后你的`git status`没有返回工作目录清理你可能还需要清理通过运行`git clean -df`来启动状态. (13认同)

小智 46

这是由update代码中的旧错误引起的,该错误早已被修复.但是,错误的性质要求您执行以下操作:

cd $(brew --repository)
git reset --hard FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)

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

cd $(brew --repository)    
git clean -fd
Run Code Online (Sandbox Code Playgroud)

  • 当接受的答案没有时,这个解决方案对我有用. (3认同)

Ron*_* D. 31

$ cd $(brew --prefix)
$ git clean -fd
$ git reset --hard
$ sudo chown -R `whoami` `brew --prefix`
$ brew update
Run Code Online (Sandbox Code Playgroud)

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


dem*_*sne 6

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

解决方案是: -

sudo chown -R <user> /usr/local/Library
Run Code Online (Sandbox Code Playgroud)


小智 5

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

$ cd `brew --prefix`
$ git fetch origin
$ git reset --hard origin/master
$ brew cleanup --force
$ brew update
Run Code Online (Sandbox Code Playgroud)