ChatGPT解决这个技术问题 Extra ChatGPT

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

我尝试运行 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

d
double-beep

不要忘记获取原点:

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

发生的情况是您正在尝试更新 brew,但 brew 本身不是最新的(可能),通过某些操作系统更新发生了权限更改(也可能),或者 brew 稍微损坏(不太可能)。由于 brew 本身是一个 git repo,因此您必须将 brew 更新或重置为 master 分支版本。 brew [默认] 位于 /usr/local/Homebrew 文件夹中,因此您

转到该文件夹 [第一个命令],它也应该更新权限(如果没有见下文)获取原点 [第二个命令],这意味着根据远程主控更新 brew 远程分支的本地版本硬重置 [第三个命令]分支(也使用您当前的权限)。

如果您在非 sudo 或管理员配置文件中,还可以 chown 第一个命令

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

要了解 git reset,请查看 this article


我必须在重置之前git fetch origin。谢谢。有趣的是,这个答案是如何在过去一天添加的,我很幸运!
/usr/local git fetch origin fatal: 'origin' does not appear to be a git repository fatal: The remote end hung up unexpectedly
看看这个 github.com/mxcl/homebrew/wiki/Common-Issues 描述了错误以及如何更正它。
它有效,但我必须使用 sudo 完成最后一步
这仍然经常发生在我身上,事实上,在过去的几个月里,我需要重复这些步骤 3 次。很烦人,SO有一个最喜欢的功能很方便(说谷歌搜索错误通常会将此帖子作为第一个结果)
J
Joe Holloway

几周前我遇到了类似的问题,试图更新旧的自制软件安装。这样做:

git reset --hard origin/master

/usr/local 中为我修复了它。

似乎其他人也有这个问题。您是否查看过任何建议的解决方法here


像冠军一样工作。也感谢您的链接!
其他人注意:请尝试按照其他答案中的建议运行“git fetch origin”——只为我正确解决此问题(除了 brew 没有看到任何更新之外,没有“git fetch origin”没有明显的问题;) )。
我今天早上刚刚遇到了这个 brew 错误。一个小小的谷歌搜索把我带到了这里。这个答案完全解决了我的问题。谢谢!
首先,您可能必须 cd usr/localgit remote add origin https://github.com/mxcl/homebrew.git 另请参阅 stackoverflow.com/questions/6024671/…
f
furins

我正在添加我的个人经验,因为它似乎比 2012 年提出的更安全:

运行冲泡医生。如果您收到以下警告: 警告:/usr/local 目录不可写。运行: sudo chown -R `whoami` /usr/local 来修复权限问题(正如 Chris Frisina 所建议的那样)。最终再次运行 brew doctor 以确保警告消失。现在,您应该有一个警告:您对 Homebrew 进行了未提交的修改,可以通过 cd /usr/local/Library && git stash && git clean -d -f 解决,正如 Dr.Brew 本身所建议的那样。该命令存储未提交的修改,以便您可以在需要时返回并恢复它们。对我来说,这似乎比 git reset --hard origin/master 更安全。如果您愿意,如果此处和其他 SO 用户建议的步骤不能解决您的问题,请查看官方故障排除指南。


cd /usr/local/Library && git stash && git clean -d -f 然后 brew update 为我修复了它
H
Haris Krajina

类似的答案,但如果您有不再跟踪的文件,则需要额外的步骤,因此从 /usr/local 运行

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

K
Kay V

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

修复 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!” (强调他们的)。