以下未被跟踪的工作树文件将被merge覆盖:

我试图运行brew update,我得到一个错误,关于我的局部更改将丢失,如果我合并。我尝试提交我的本地更改(不记得做过任何更改,但已经有一段时间了),这让事情变得更糟。

输出如下:

MBP:Library User$ sudo brew update
error: The following untracked working tree files would be overwritten by merge:
Library/Aliases/fastcgi
Library/Aliases/htop
Library/Aliases/nodejs
Library/Aliases/ocio
Library/Aliases/oiio
Library/Aliases/pgrep
Library/Aliases/pkill
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-man
Library/Contributions/cmds/brew-mirror-check.rb
Library/Contributions/cmds/brew-missing.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.commit.html.erb
Library/Contributions/cmds/brew-test-bot.css
Library/Contributions/cmds/brew-test-bot.index.html.erb
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/install_homebrew.rb
Library/Formula/abcl.rb
Library/Formula/abyss.rb
Library/Formula/akka.rb
Library/Formula/apollo.rb
Library/Formula/appledoc.rb
Library/Formula/arangodb.rb
Library/Formula/autoconf.rb
Library/Formula/automake.rb
Library/Formula/avidemux.rb
Library/Formula/bind.rb
Library/Formula/bsdconv.rb
Library/Formula/bsdmake.rb
Library/Formula/camellia.rb
Library/Formula/cbmbasic.rb
Library/Formula/cdo.rb
Library/Formula/checkstyle.rb
Library/Formula/cifer.rb
Library/Formula/clhep.rb
Library/Formula/collada-dom.rb
Library/Formula/crash.rb
Library/Formula/crossroads.rb
Library/Formula/css-crush.rb
Library/Formula/curlftpfs.rb
Library/Formula/dart.rb
Library/Formula/dasm.rb
Library/Formula/dfc.rb
Library/Formula/di.rb
Library/Formula/dsniff.rb
Library/Formula/dupx.rb
Library/Formula/dwatch.rb
Library/Formula/eprover.rb
Library/Formula/ext2fuse.rb
Library/Formula/ezlupdate.rb
Library/Formula/f3.rb
Library/Formula/fastx_toolkit.rb
Library/Formula/fceux.rb
Library/Formula/findbugs.rb
Library/Formula/freerdp.rb
Library/Formula/funcoeszz.rb
Library/Formula/fwknop.rb
Library/Formula/gabedit.rb
Library/Formula/gbdfed.rb
Library/Formula/gconf.rb
Library/Formula/git-encrypt.rb
Library/Formula/glm.rb
Library/Formula/gmap-gsnap.rb
Library/Formula/gnu-arch.rb
Library/Formula/gnunet.rb
Library/Formula/gobby.rb
Library/Formula/gptfdisk.rb
Library/Formula/griffon.rb
Library/Formula/grok.rb
Library/Formula/gtk-chtheme.rb
Library/Formula/gtkglextmm.rb
Library/Formula/gtmess.rb
Library/Formula/hg-flow.rb
Library/Formula/hqx.rb
Library/Formula/htop-osx.rb
Library/Formula/htpdate.rb
Library/Formula/imap-uw.rb
Library/Formula/iozone.rb
Library/Formula/ipbt.rb
Library/Formula/ipe.rb
Library/Formula/ispc.rb
Library/Formula/ispell.rb
Library/Formula/jigdo.rb
Library/Formula/jing.rb
Library/Formula/jless.rb
Library/Formula/jpeginfo.rb
Library/Formula/konoha.rb
Library/Formula/legit.rb
Library/Formula/libcouchbase.rb
Library/Formula/libcuefile.rb
Library/Formula/libextractor.rb
Library/Formula/libglademm.rb
Library/Formula/libgtextutils.rb
Library/Formula/libinfinity.rb
Library/Formula/libkate.rb
Library/Formula/libqalculate.rb
Library/Formula/libqglviewer.rb
Library/Formula/libreplaygain.rb
Library/Formula/libtool.rb
Library/Formula/libvbucket.rb
Library/Formula/libvo-aacenc.rb
Library/Formula/libxmi.rb
Library/Formula/lifelines.rb
Library/Formula/makeicns.rb
Library/Formula/mathgl.rb
Library/Formula/meld.rb
Library/Formula/mesalib-glw.rb
Library/Formula/minisat.rb
Library/Formula/minuit2.rb
Library/Formula/mobile-shell.rb
Library/Formula/movgrab.rb
Library/Formula/mp3cat.rb
Library/Formula/mpich2.rb
Library/Formula/mrfast.rb
Library/Formula/musepack.rb
Library/Formula/ndiff.rb
Library/Formula/net6.rb
Library/Formula/nrpe.rb
Library/Formula/nuttcp.rb
Library/Formula/oath-toolkit.
Updating aa07533..3f070ef
Aborting
Error: Failed while executing git pull  origin refs/heads/master:refs/remotes/origin/master
70093 次浏览

几周前,我在更新旧的自制程序安装时遇到了类似的问题。这样做:

git reset --hard origin/master

/usr/local固定它为我。

似乎其他人也有这个问题。你有没有看过任何提议的变通方法在这里?

别忘了获取原点:

cd /usr/local/Homebrew
git fetch origin
git reset --hard origin/master

发生的情况是,您试图更新brew,但brew本身不是最新的(可能),通过某些操作系统更新有权限更改(也可能),或者brew轻微损坏(不太可能)。由于brew本身是一个git回购,您必须更新或重置brew到主分支版本。brew[默认情况下]位于/usr/local/Homebrew文件夹中,因此您可以

  1. 转到该文件夹[第一个命令],它也应该更新权限(如果没有,请参阅下面)
  2. 获取origin [second命令],这意味着更新brew远程分支的LOCAL版本
  3. 基于REMOTE主分支(也使用您的当前权限)的硬复位[第三个命令]。

如果你在非sudo或admin配置文件中,你也可以chown第一个命令

sudo chown -R `whoami` /usr/local/Homebrew
cd /usr/local/Homebrew
git reset --hard origin/master

要理解git重置,看一下这篇文章

我加上我的个人经验,因为这似乎比2012年提出的建议更安全:

  1. brew doctor运行。
  2. 如果你得到以下警告:

    Warning: The /usr/local directory is not writable.
    

    运行:

    sudo chown -R `whoami` /usr/local
    

    来修复权限问题(Chris Frisina也建议)。最后再次运行brew doctor以确保警告消失

  3. 现在,你应该有一个

    Warning: You have uncommitted modifications to Homebrew
    

    这个问题可以通过

    cd /usr/local/Library && git stash && git clean -d -f
    

    这是Dr.Brew自己建议的。该命令将存储未提交的修改,以便在需要时可以返回并恢复它们。对我来说,它似乎比git reset --hard origin/master更安全

  4. 如果这里和其他SO用户建议的步骤不能解决您的问题,请检查官方故障排除指南

类似的答案,但如果你的文件不再被跟踪,你需要额外的步骤,所以从/usr/local运行

git fetch origin
git clean -f
git reset --hard origin/master

这种方法可能比其他方法更简单。它包括:

  • 修复了一个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
< p >概述:< br > 据我所知,这个问题的实际原因是回购url的变化。它现在是brew,以前是brew.git。(完整的最新url: https://github.com/Homebrew/brew)

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

注意2:第二个命令将正确的远程url添加到新的别名;我这样做只是为了防止这种方法没有达到我想要的效果,我又需要以前的地址。由于新的远程工作,我将邀请其他人对简单地更改url以起源为别名进行评论。我将很高兴地更新答案,以反映对您有效的方法。

注意3:这个第四个命令得到了理想的结果:它报告了大量的更新,包括特别漂亮的报告“==> migrate HOMEBREW_REPOSITORY to /usr/ localhome brew!”(并强调了这一点)。