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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10762859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:47:03  来源:igfitidea点击:

brew update: The following untracked working tree files would be overwritten by merge:

githomebrew

提问by Tyler DeWitt

I tried to run brew updateand I get an error about my local changes would be lost if I merged. I tried committing my local changes (don't remember making any, but it's been awhile), and that made things worse.

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

Here's the output:

这是输出:

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

回答by chris Frisina

Don't forget to fetch the origin!!!

别忘了去取原点!!!

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

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

Explanation, for those interested:

解释,对于那些有兴趣的人:

What happens is that you are trying to update brew, but brew itself is either not up to date (likely), there is a permissions change via some OS update (also likely), or brew is slightly corrupt (unlikely). Since brew itself is a git repo, you have to update or reset brew to the master branch version. brew [by default] is located in the /usr/localfolder, so you

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

  1. Go to that folder [first command] which also should update permissions (if not see below)
  2. Fetch the origin [second command] which means to update your LOCAL version of the remote branch of brew
  3. Hard reset [3rd command] based on the REMOTE master branch (which also uses your current permissions).
  1. 转到该文件夹​​ [第一个命令],它也应该更新权限(如果没有见下文)
  2. 获取原点 [第二个命令],这意味着更新 brew 远程分支的本地版本
  3. 基于 REMOTE 主分支(也使用您当前的权限)的硬重置 [第三个命令]。

You can also chownthe first command if you are in a non sudo or admin profile
$ sudo chown -R `whoami` /usr/local
$ cd /usr/local
$ git reset --hard origin/master

chown如果您在非 sudo 或管理员配置文件中,您也可以使用第一个命令
$ sudo chown -R `whoami` /usr/local
$ cd /usr/local
$git reset --hard origin/master

To understand git reset, take a look at this article.

要了解 git reset,请查看这篇文章

回答by Joe Holloway

I had a similar issue a couple weeks ago trying to update an old homebrew install. Doing this:

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

git reset --hard origin/master

in /usr/localfixed it for me.

/usr/local固定对我来说。

It seems like other folks have had this issue too. Have you looked over any of the proposed workarounds here?

好像其他人也有这个问题。您是否查看了此处提出的任何解决方法?

回答by furins

I'm adding my personal experience, since it seems a little safer than what proposed in 2012:

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

  1. Run brew doctor.
  2. If you get the following warning:

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

    run:

    sudo chown -R `whoami` /usr/local
    

    to fix the permissions problems (as suggested also by Chris Frisina). Eventually run brew doctoragain to ensure yourself that the warning is gone.

  3. Now, you should have a

    Warning: You have uncommitted modifications to Homebrew
    

    that may bey solved by

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

    as suggested by Dr.Brew itself. The command stashes the uncommitted modifications so you could go back and recover them if needed. It seemed safer than git reset --hard origin/masterto me.

  4. If you wish, check the official troubleshooting guideif the steps suggested here and by other SO users does not solve your problem.

  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 用户建议的步骤不能解决您的问题,请查看官方故障排除指南

回答by Haris Krajina

Similar answer but if you have files that are no longer tracked you need additional step so from /usr/localrun

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

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

回答by Kay V

This approach may be simpler than some. It involves:

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

  • fixing a git issue so you can delegate management of changes to it again.
  • no manual moves of files or directories.
  • no manual adjustments of file or directory permissions.
  • 修复 git 问题,以便您可以再次将更改的管理委托给它。
  • 无需手动移动文件或目录。
  • 无需手动调整文件或目录权限。

Steps (with notes for those who want explanations):

步骤(附注给需要解释的人):

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 

Overview:
From what I can tell, the actual cause of this issue is a change in the repo url. It's now brewand was brew.git. (Full up-to-date url: https://github.com/Homebrew/brew)

概述:据
我所知,此问题的实际原因是 repo url 的更改。它是现在brew和过去brew.git。(完整的最新网址:https: //github.com/Homebrew/brew

Note 1: This first command takes you from anywhere in your file structure to the correct directory. The directory structure is different for me than what others show above (Mac OS 10.11.16), but with this command, those differences should not matter.

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

Note 2: This second command adds the correct remote url to a new alias; I did so just in case this approach didn't accomplish what I wanted and I needed the previous address again. Since the new remote worked, I'll invite someone else to comment on simply changing the url aliased by origin. I'll happily update the answer to reflect what worked for you.

注意 2:第二个命令将正确的远程 url 添加到新别名;我这样做是为了以防这种方法不能完成我想要的,而我又需要以前的地址。由于新的远程工作,我将邀请其他人评论简单地更改由 origin 别名的 url。我很乐意更新答案以反映对您有用的内容。

Note 3: This forth command has exactly the desired result: it reports a large number of updates, including the particularly nice report of "==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew!" (emphasis theirs).

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